@charset "utf-8";
@import "../core/variables";
@import "../core/classes";
@import "../element/yo-btn";

// 定义dialog的基础构造
@mixin _dialog {
    @include flexbox;
    @include flex-direction(column);
    position: fixed;
    z-index: map-get($z-index, dialog);
    overflow: hidden;
    @include border-radius(map-get($dialog, radius));
    @if map-get($dialog, shadow-opacity) != null {
        box-shadow: 0 0 5px rgba(map-get($dialog, bordercolor), map-get($dialog, shadow-opacity));
    }
    border: 1px solid map-get($dialog, bordercolor);
    min-width: 2.8rem;
    max-width: 90%;
    width: map-get($dialog, width);
    height: map-get($dialog, height);
    background: #fff;
    text-align: center;
    > .hd {
        position: relative;
        height: map-get($dialog, hd-height);
        background: map-get($dialog, hd-bgcolor);
        line-height: map-get($dialog, hd-height);
        .title {
            overflow: hidden;
            height: 100%;
            margin: 0 60px;
            @if map-get($dialog, title-color) != map-get($base, color) {
                color: map-get($dialog, title-color);
            }
            @if map-get($dialog, title-font-size) != map-get($base, font-size) {
                font-size: map-get($dialog, title-font-size);
            }
        }
        .regret,
        .affirm {
            position: absolute;
            top: 0;
        }
        .regret {
            left: .1rem;
        }
        .affirm {
            right: .1rem;
        }
    }
    > .bd {
        @include flex(1, column);
        @include overflow;
        min-height: .45rem;
        padding: map-get($dialog, bd-padding);
        @if map-get($dialog, bd-font-size) != map-get($base, font-size) {
            font-size: map-get($dialog, bd-font-size);
        }
    }
    > .ft {
        @include flexbox;
        text-align: center;
        @include yo-btn(
            $border-width: 1px 0 0,
            $bordercolor: map-get($base, bordercolor),
            $bgcolor: #fff,
            $color: map-get($base, link-color),
            $radius: 0,
            $active-bgcolor: #f9f9f9
        ){
            display: block;
            @include flex;
            &:last-child:not(:only-child),
            &:only-child {
                font-weight: bold;
            }
            &:last-child:not(:only-child) {
                border-left-width: 1px;
            }
        }
    }
}

/**
 * @module widget
 * @method yo-dialog
 * @description 构造yo-dialog的自定义使用方法
 * @demo http://doyoe.github.io/Yo/demo/widget/yo-dialog.html
 * @param {String} $name 定义dialog名称
 * @param {Length | null} $width 定义dialog宽度
 * @param {Length} $height 定义dialog高度
 * @param {Length} $radius 定义dialog圆角
 * @param {Number} $shadow-opacity 定义dialog阴影透明度
 * @param {Color} $bordercolor 定义dialog边框色
 * @param {Length} $hd-height 定义dialog头部高度
 * @param {Color} $hd-bgcolor 定义dialog头部背景色
 * @param {Color} $title-color 定义dialog标题文本色
 * @param {Length} $title-font-size 定义dialog标题字号
 * @param {Length} $bd-padding 定义dialog主体补白
 * @param {Length} $bd-font-size 定义dialog主体字号
 */

@mixin yo-dialog(
    $name: default,
    $width: default,
    $height: default,
    $radius: default,
    $shadow-opacity: default,
    $bordercolor: default,
    $hd-height: default,
    $hd-bgcolor: default,
    $title-color: default,
    $title-font-size: default,
    $bd-padding: default,
    $bd-font-size: default) {
    // 区别是否新增实例还是修改本身
    @if $name == default {
        $name: "";
    } @else {
        $name: "-#{$name}";
    }
    // 如果值为default,则取config的定义
    @if $width == default {
        $width: map-get($dialog, width);
    }
    @if $height == default {
        $height: map-get($dialog, height);
    }
    @if $radius == default {
        $radius: map-get($dialog, radius);
    }
    @if $shadow-opacity == default {
        $shadow-opacity: map-get($dialog, shadow-opacity);
    }
    @if $bordercolor == default {
        $bordercolor: map-get($dialog, bordercolor);
    }
    @if $hd-height == default {
        $hd-height: map-get($dialog, hd-height);
    }
    @if $hd-bgcolor == default {
        $hd-bgcolor: map-get($dialog, hd-bgcolor);
    }
    @if $title-color == default {
        $title-color: map-get($dialog, title-color);
    }
    @if $title-font-size == default {
        $title-font-size: map-get($dialog, title-font-size);
    }
    @if $bd-padding == default {
        $bd-padding: map-get($dialog, bd-padding);
    }
    @if $bd-font-size == default {
        $bd-font-size: map-get($dialog, bd-font-size);
    }
    .yo-dialog#{$name} {
        @if $radius != map-get($dialog, radius) {
            border-radius: $radius;
        }
        @if $bordercolor != map-get($dialog, bordercolor) {
            border-color: $bordercolor;
            box-shadow: 0 0 5px rgba($bordercolor, $shadow-opacity);
        } @else {
            @if $shadow-opacity != map-get($dialog, shadow-opacity) {
                box-shadow: 0 0 5px rgba($bordercolor, $shadow-opacity);
            }
        }
        @if $width != map-get($dialog, width) {
            width: $width;
        }
        @if $height != map-get($dialog, height) {
            height: $height;
        }
        > .hd {
            @if $hd-height != map-get($dialog, hd-height) {
                height: $hd-height;
                line-height: $hd-height;
            }
            @if $hd-bgcolor != map-get($dialog, hd-bgcolor) {
                background: $hd-bgcolor;
            }
            .title {
                @if $title-color != map-get($dialog, title-color) and $title-color != map-get($base, color) {
                    color: $title-color;
                }
                @if $title-font-size != map-get($dialog, title-font-size) and $title-font-size != map-get($base, font-size) {
                    font-size: $title-font-size;
                }
            }
        }
        > .bd {
            @if $bd-padding != map-get($dialog, bd-padding) {
                padding: $bd-padding;
            }
            @if $bd-font-size != map-get($dialog, bd-font-size) and $bd-font-size != map-get($base, font-size) {
                font-size: $bd-font-size;
            }
        }
        // 增量扩展
        @content;
    }
}

// 调用本文件时载入dialog基础构造
.yo-dialog {
    @include _dialog;
}