@import "../var.scss";

$j-prefix-modal: "#{$j-prefix}-modal" !default;
$j-prefix-modal-overlay: "#{$j-prefix}-modal-overlay" !default;
$j-prefix-modal-content: "#{$j-prefix}-modal-content" !default;
$j-prefix-modal-close: "#{$j-prefix}-modal-close" !default;

.#{$j-prefix-modal-overlay} {
    position: fixed;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    transition: all 0.3s ease-in-out;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    overflow-y: auto;
    padding-top: 20px;
    padding-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;

    &[data-active] {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    &[data-closing] {
        opacity: 0;
    }

    &[data-mobile] {
        z-index: 0;
        background: transparent;
    }

    &[data-mobile][data-active] {
        position: static;
    }
}

.#{$j-prefix-modal} {
    background: #fff;
    transition: all 0.3s ease-in-out;
    border-radius: 3px;
    margin: auto;
    z-index: 1000;
    position: fixed;
    left: 50%;
    top: 50%;
    opacity: 0;
    max-height: 100%;
    display: flex;
    max-width: 600px;
    width: calc(100% - 36px);
    max-height: calc(100% - 36px);
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.95);
    border-radius: 10px;
    padding: 24px;
    min-height: 100px;

    &[data-active] {
        // margin-top: 0;
        pointer-events: auto;

        &:not([data-closing]) {
            opacity: 1;
        }

        @media (min-width: $j-sm + 1) {
            &:not([data-closing]) {
                transform: translate(-50%, -50%) scale(1);
            }
        }

        // @media (max-width: $j-sm) {
        //     &:not([data-adaptive]):not([data-closing]) {
        //         top: calc(50% + 0px);
        //     }
        // }
    }

    // @media (min-width: $j-sm + 1) {
    //     & {
    //         // top: calc(50% + 10px);
    //     }
    // }

    // @media (max-width: $j-sm) {
    //     &:not([data-adaptive]) {
    //         // top: calc(50% + 10px);
    //     }
    // }

    .#{$j-prefix-modal-content} {
        overflow-y: auto;
        width: 100%;
    }

    @media (max-width: $j-sm) {
        &[data-adaptive] {
            width: 100%;
            max-width: 100%;
            border-radius: 0;
            overflow: hidden;
            top: auto;
            bottom: 0;
            transform: translate(-50%, 0);
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
        }
    }

    &:not([mobile])[adaptive] {
        @media (max-width: $j-sm) {
            .#{$j-prefix-modal-close} {
                top: 5px;
                right: 5px;
                width: 30px;
                height: 30px;
            }
        }
    }

    &:not([data-mobile]) {
        @media (max-width: $j-sm) {
            padding: 0;

            .#{$j-prefix-modal-close} {
                width: 24px;
                height: 24px;
                top: 18px;
                right: 18px;
            }
        }
    }

    &[data-mobile] {
        position: static;
        z-index: 0;
        animation: none;
        transform: none;
        max-width: 100%;
        border-radius: 0;
        padding-right: 0;
        padding-left: 0;
        padding-top: 0;
    }

    &[data-mobile] .#{$j-prefix-modal-close} {
        display: inline-block;
        cursor: pointer;
    }

    &:not([data-mobile]) .#{$j-prefix-modal-close} {
        display: block;
        top: 24px;
        right: 24px;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        position: absolute;
        background: #fff;
        cursor: pointer;

        &::after,
        &::before {
            display: inline-block;
            content: "";
            border: 1px solid #808d9a;
            width: 14px;
            position: absolute;
            top: 50%;
            left: 50%;
            transition: all 0.3s ease-in-out;
        }

        &::after {
            transform: translate(-50%, -50%) rotate(45deg);
        }

        &::before {
            transform: translate(-50%, -50%) rotate(-45deg);
        }

        &:hover::after,
        &:hover::before {
            border-color: #4c4d4f;
        }
    }

    &-header {
        padding-right: 48px;
        font-size: 24px;
        line-height: 32px;
        font-weight: 700;
        margin-bottom: 24px;

        @media (max-width: $j-sm) {
            padding: 18px;
            border-bottom: 1px solid #f7f7f7;
            text-align: center;
            font-size: 16px;
            line-height: 24px;
            margin-bottom: 8px;
        }
    }

    &-body {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        flex-grow: 1;
        font-size: 16px;
        line-height: 24px;

        @media (max-width: $j-sm) {
            padding: 12px 18px;
        }
    }

    &-content {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        width: 100%;
    }

    &-footer {
        margin-top: 8px;

        @media (max-width: $j-sm) {
            padding: 0 18px 12px;
        }
    }
}
