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

// 定义浮层popup的基础构造
@mixin _popup {
    @include flexbox;
    @include flex-direction(column);
    position: absolute;
    z-index: map-get($z-index, popup);
    @include border-radius(map-get($popup, radius));
    @if map-get($popup, shadow-opacity) != null {
        box-shadow: 0 0 5px rgba(map-get($popup, bordercolor), map-get($popup, shadow-opacity));
    }
    border: 1px solid map-get($popup, bordercolor);
    min-width: 2.8rem;
    min-height: 1rem;
    width: map-get($popup, width);
    height: map-get($popup, height);
    background: #fff;
    // 改用标签的方式,因为JS需要控制位置
    > .arrow::after {
        position: absolute;
        content: "◆";
        color: #fff;
        font-size: map-get($popup, arrow-size) * 2;
        line-height: 1;
    }
    // 控制箭头方向
    .arrow-top,
    .arrow-down {
        &::after {
            @include transform(translate(-50%));
            left: 50%;
        }
    }
    .arrow-top::after {
        top: -#{map-get($popup, arrow-size) - .01rem};
        // 箭头边框色
        text-shadow: 0 -1px map-get($popup, bordercolor);
    }
    .arrow-down::after {
        bottom: -#{map-get($popup, arrow-size) - .01rem};
        // 箭头边框色
        text-shadow: 0 1px map-get($popup, bordercolor);
    }
    .arrow-right,
    .arrow-left {
        &::after {
            @include transform(translate(0, -50%));
            top: 50%;
        }
    }
    .arrow-right::after {
        right: -#{map-get($popup, arrow-size) - .01rem};
        // 箭头边框色
        text-shadow: 1px 0 map-get($popup, bordercolor);
    }
    .arrow-left::after {
        left: -#{map-get($popup, arrow-size) - .01rem};
        // 箭头边框色
        text-shadow: -1px 0 map-get($popup, bordercolor);
    }
    // 有hd或ft时,箭头的颜色应该和hd或ft相同
    .arrow-extra.arrow::after {
        color: map-get($popup, hd-bgcolor);
    }
    > .hd,
    > .bd {
        position: relative;
        z-index: 2;
    }
    > .hd {
        height: map-get($popup, hd-height);
        border-bottom: 1px solid map-get($popup, bordercolor);
        background: map-get($popup, hd-bgcolor);
        line-height: map-get($popup, hd-height);
        text-align: center;
        .title {
            overflow: hidden;
            height: 100%;
            margin: 0 60px;
            @if map-get($popup, title-color) != map-get($base, color) {
                color: map-get($popup, title-color);
            }
            @if map-get($popup, title-font-size) != map-get($base, font-size) {
                font-size: map-get($popup, title-font-size);
            }
        }
        .regret,
        .affirm {
            position: absolute;
            top: 0;
        }
        .regret {left: 10px;}
        .affirm {right: 10px;}
    }
    > .bd {
        @include flex(1, column);
        @include overflow();
        padding: map-get($popup, bd-padding);
    }
    > .ft {
        padding: .1rem 0;
        border-top: 1px solid map-get($popup, bordercolor);
        text-align: center;
    }
}

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

@mixin yo-popup(
    $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,
    $arrow-size: default) {
    // 区别是否新增实例还是修改本身
    @if $name == default {
        $name: "";
    } @else {
        $name: "-#{$name}";
    }
    // 如果值为default,则取config的定义
    @if $width == default {
        $width: map-get($popup, width);
    }
    @if $height == default {
        $height: map-get($popup, height);
    }
    @if $radius == default {
        $radius: map-get($popup, radius);
    }
    @if $bordercolor == default {
        $bordercolor: map-get($popup, bordercolor);
    }
    @if $shadow-opacity == default {
        $shadow-opacity: map-get($popup, shadow-opacity);
    }
    @if $hd-height == default {
        $hd-height: map-get($popup, hd-height);
    }
    @if $hd-bgcolor == default {
        $hd-bgcolor: map-get($popup, hd-bgcolor);
    }
    @if $title-color == default {
        $title-color: map-get($popup, title-color);
    }
    @if $title-font-size == default {
        $title-font-size: map-get($popup, title-font-size);
    }
    @if $bd-padding == default {
        $bd-padding: map-get($popup, bd-padding);
    }
    @if $arrow-size == default {
        $arrow-size: map-get($popup, arrow-size);
    }
    .yo-popup#{$name} {
        > .arrow::after{
            @if $arrow-size != map-get($popup, arrow-size) {
                font-size: $arrow-size * 2;
            }
        }
        .arrow-top::after{
            @if $arrow-size != map-get($popup, arrow-size) {
                top: -$arrow-size + .01rem;
            }
            @if $bordercolor != map-get($popup, bordercolor) {
                text-shadow: 0 -1px $bordercolor;
            }
        }
        .arrow-down::after {
            @if $arrow-size != map-get($popup, arrow-size) {
                bottom: -$arrow-size + .01rem;
            }
            @if $bordercolor != map-get($popup, bordercolor) {
                text-shadow: 0 1px $bordercolor;
            }
        }
        .arrow-right::after {
            @if $arrow-size != map-get($popup, arrow-size) {
                right: -$arrow-size + .01rem;
            }
            @if $bordercolor != map-get($popup, bordercolor) {
                text-shadow: 1px 0 $bordercolor;
            }
        }
        .arrow-left::after {
            @if $arrow-size != map-get($popup, arrow-size) {
                left: -$arrow-size + .01rem;
            }
            @if $bordercolor != map-get($popup, bordercolor) {
                text-shadow: -1px 0 $bordercolor;
            }
        }
        .arrow-extra.arrow::after {
            @if $hd-bgcolor != map-get($popup, hd-bgcolor) {
                color: $hd-bgcolor;
            }
        }
        @if $radius != map-get($popup, radius) {
            border-radius: $radius;
        }
        @if $bordercolor != map-get($popup, bordercolor) {
            border-color: $bordercolor;
            box-shadow: 0 0 5px rgba($bordercolor, $shadow-opacity);
        } @else {
            @if $shadow-opacity != map-get($popup, shadow-opacity) {
                box-shadow: 0 0 5px rgba($bordercolor, $shadow-opacity);
            }
        }
        @if $width != map-get($popup, width) {
            width: $width;
        }
        @if $height != map-get($popup, height) {
            height: $height;
        }
        > .hd {
            @if $radius != map-get($popup, radius) {
                border-radius: $radius $radius 0 0;
            }
            @if $hd-height != map-get($popup, hd-height) {
                height: $hd-height;
                line-height: $hd-height;
            }
            @if $bordercolor != map-get($popup, bordercolor) {
                border-bottom-color: $bordercolor;
            }
            @if $hd-bgcolor != map-get($popup, hd-bgcolor) {
                background: $hd-bgcolor;
            }
            .title {
                @if $title-color != map-get($popup, title-color) and $title-color != map-get($base, color) {
                    color: $title-color;
                }
                @if $title-font-size != map-get($popup, title-font-size) and $title-font-size != map-get($base, font-size) {
                    font-size: $title-font-size;
                }
            }
        }
        > .bd {
            @if $bd-padding != map-get($popup, bd-padding) {
                padding: $bd-padding;
            }
        }
        > .ft {
            @if $bordercolor != map-get($popup, bordercolor) {
                border-color: $bordercolor;
            }
        }
        // 增量扩展
        @content;
    }
}

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