@import "./functions/func.scss";

$headerLineHeight: 24px;
$buttonHeight: 28px;

.ui-popup-mask {
    position: fixed;
    @include inset(0, 0, 0, 0);
    background-color: rgba(0 0 0 /20%);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    z-index: 200;
    transition: opacity .12s ease;

    & {
        --corner-radius: 6px;
        --loading-size: 20px;
        --loading-border-radius: 10px;
    }

    &.ui-popup-active .ui-popup-container {
        transform: scale(1.1);
    }

    &.ui-popup-transparent {
        right: unset;
        bottom: unset;
    }

    .ui-popup-container {
        min-width: 400px;
        max-width: 800px;
        max-height: 90vh;
        background-color: var(--bg-color);
        border-radius: var(--corner-radius);
        box-shadow: 0 2px 8px var(--shadow-color);
        transition: opacity .12s ease, transform .12s ease;
        position: absolute;
        display: flex;
        flex-direction: column;

        @include outline();

        .ui-popup-header {
            flex: 0 0 auto;
            border-radius: var(--corner-radius) var(--corner-radius) 0 0;
            line-height: $headerLineHeight;
            user-select: none;
            background-color: var(--title-ctrlbg-color);
            color: var(--title-color);
            display: flex;
            align-items: center;

            >div {
                flex: 1 1 auto;
                font-size: 1rem;
            }

            .ui-popup-header-title {
                flex-grow: 1;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                padding: 5px 0 3px 12px;
            }

            .ui-popup-header-title,
            .ui-popup-move {
                cursor: move;
            }

            .ui-popup-header-title.no-move {
                cursor: default;
            }

            >.ui-popup-header-icons {
                flex: 0 0 auto;
                padding: 5px 12px 3px 0;
                display: flex;

                >svg {
                    flex: 0 0 auto;
                    width: $headerLineHeight;
                    height: $headerLineHeight;
                    fill: var(--title-color);
                    padding: 4px;
                    cursor: pointer;
                    box-sizing: border-box;
                    transition: opacity .12s ease;

                    &:hover {
                        opacity: .8;
                    }

                    &:focus,
                    &:focus-visible {
                        outline: none;
                        opacity: .8;
                        background-color: rgb(0 0 0/10%);
                        border-radius: var(--corner-radius);
                    }
                }
            }
        }

        .ui-popup-body {
            margin: 6px 10px;
            flex: 1 1 auto;
            line-height: $headerLineHeight;
            position: relative;
            min-height: 80px;

            >.ui-popup-loading {
                position: absolute;
                @include inset(0, 0, -46px, 0);
                visibility: hidden;
                opacity: 0;
                transition: visibility 0s linear .12s, opacity .12s ease;
                background-color: var(--loading-bg-color);
                display: flex;
                justify-content: center;
                align-items: center;
                z-index: 1;

                >div {
                    background-color: var(--loading-fore-color);
                    border-radius: var(--loading-border-radius);

                    >svg {
                        width: var(--loading-size);
                        height: var(--loading-size);
                        padding: 20px;
                        animation: loading-spinner 1.2s infinite linear;
                    }
                }

                &.ui-popup-loading-content {
                    bottom: 0;
                }
            }

            >.message-wrapper {
                display: flex;
                margin: 10px;

                &.message-wrapper-input {
                    flex-direction: column;
                    gap: 6px;

                    >.ui-text {
                        min-height: 50px;
                        resize: vertical;
                    }
                }

                >svg {
                    width: 30px;
                    height: 30px;
                    fill: unset;

                    +span {
                        padding-left: 16px;
                    }
                }
            }

            .setting-wrapper {
                --line-height: 28px;

                >.setting-item {
                    display: flex;
                    align-items: center;
                    line-height: var(--line-height);
                    margin: 4px 0;

                    >.setting-label {
                        flex: 0 0 auto;
                        width: 120px;
                        text-align: right;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        padding-right: 10px;

                        &.setting-required::after {
                            content: '*';
                            color: var(--red-color);
                            font-weight: bold;
                        }

                        +* {
                            flex: 1 1 auto;
                            margin-right: 10px;
                            box-sizing: border-box;
                            height: var(--line-height);
                            line-height: var(--line-height);
                        }

                        +textarea {
                            text-indent: var(--text-indent);
                        }

                        +.ui-check-wrapper {
                            padding: 0;
                        }
                    }
                }
            }
        }

        .ui-popup-footer {
            flex: 0 0 auto;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding: 4px 26px 26px 20px;
        }

        .ui-popup-body,
        .ui-popup-footer {

            .ui-popup-button {
                margin-left: 12px;
                border: none;
                // height: $buttonHeight;
                line-height: $buttonHeight;
                color: var(--title-color);
                border-radius: var(--corner-radius);
                padding: 1px 16px;
                box-sizing: border-box;
                min-width: 70px;
                text-align: center;
                cursor: pointer;
                user-select: none;
                background-color: var(--title-ctrlbg-color);
                transition: opacity .12s ease;

                &:focus,
                &:hover {
                    opacity: .8;
                }

                @include outline();

                &:disabled {
                    opacity: .4;
                    cursor: default;
                }
            }
        }

        .ui-popup-border {
            position: absolute;

            &.ui-popup-border-left,
            &.ui-popup-border-right {
                width: 6px;
                height: 100%;
                top: 0;
                cursor: ew-resize;
            }

            &.ui-popup-border-top,
            &.ui-popup-border-bottom {
                width: 100%;
                height: 6px;
                left: 0;
                cursor: ns-resize;
            }

            &.ui-popup-border-top-left,
            &.ui-popup-border-top-right,
            &.ui-popup-border-bottom-right,
            &.ui-popup-border-bottom-left {
                width: 8px;
                height: 8px;
            }

            &.ui-popup-border-top-left,
            &.ui-popup-border-bottom-right {
                cursor: nwse-resize;
            }

            &.ui-popup-border-top-right,
            &.ui-popup-border-bottom-left {
                cursor: nesw-resize;
            }

            &.ui-popup-border-left,
            &.ui-popup-border-top-left,
            &.ui-popup-border-bottom-left {
                left: -4px;
            }

            &.ui-popup-border-right,
            &.ui-popup-border-top-right,
            &.ui-popup-border-bottom-right {
                right: -4px;
            }

            &.ui-popup-border-top,
            &.ui-popup-border-top-left,
            &.ui-popup-border-top-right {
                top: -4px;
            }

            &.ui-popup-border-bottom,
            &.ui-popup-border-bottom-right,
            &.ui-popup-border-bottom-left {
                bottom: -4px;
            }
        }

        &.ui-popup-collapse {
            min-height: 40px;
            min-width: 160px;

            .ui-popup-body,
            .ui-popup-footer,
            .ui-popup-border {
                display: none;
            }
        }
    }
}