@import './variables/definition.scss';
@import './functions/func.scss';
@import './functions/checkbox.scss';

$headerHeight: 26px;
$caretWidth: 26px;
$dropItemHeight: 30px;
$borderRadius: 2px;
$scrollBarSize: 4px;

$searchBarHeight: 36px;
$searchInputHeight: 26px;
$searchIconSize: 13px;
$listMaxHeight: 210px;

.dropdown-wrapper {
    display: inline-block;
    border: none;
    border-radius: unset;
    user-select: none;
    position: relative;

    >.dropdown-header {
        border: 1px solid $borderColor;
        border-radius: $borderRadius;
        background-color: $bgColor;
        display: flex;
        height: $headerHeight;
        transition: all .3s;

        &:focus {
            border-color: $focusColor;
            // box-shadow: 0 0 3px 1px rgba(0, 0, 0, .2);
        }

        &:focus,
        &:focus-visible {
            outline: none;
        }

        /*>.dropdown-select-container {
            flex: 1 1 auto;
            overflow-x: auto;
            white-space: nowrap;
            display: flex;
            flex-direction: row;
            @include scrollbar();

            &::-webkit-scrollbar {
                height: $scrollBarSize;
            }

            &::-webkit-scrollbar-thumb {
                border-radius: $borderRadius;
            }

            >span {
                display: inline-block;
                margin: 2px;
                padding: 0 2px;
                border: 1px solid lightgray;
                height: 20px;
                line-height: 20px;
                background-color: white;
                font-size: .75rem;
                border-radius: $borderRadius;
                cursor: pointer;
                position: relative;

                >svg {
                    display: none;
                    width: 8px;
                    height: 20px;
                    fill: white;
                    vertical-align: top;
                }

                &:hover {
                    border-color: #1890ff;
                    border-top-right-radius: 0;
                    border-bottom-right-radius: 0;
                    background-color: #1890ff;
                    color: white;

                    >svg {
                        display: inline-block;
                        margin-left: 3px;
                        padding: 0 2px;
                    }
                }
            }

            >label {
                flex: 1 1 auto;
                min-width: 40px;
                cursor: pointer;
                outline: none;
                line-height: $headerHeight;
                padding: 0 4px;
                font-weight: 400;
                font-size: .8125rem;
                color: $foreColor;
            }
        }*/

        >.dropdown-text {
            flex: 1 1 auto;
            cursor: pointer;
            font-size: .875rem;
            line-height: $headerHeight;
            padding: 0 6px;
            overflow: hidden;
            text-overflow: ellipsis;
            border: none;
            outline: none;
            white-space: nowrap;
        }

        >.dropdown-caret {
            flex: 0 0 auto;
            width: $caretWidth;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;

            &::after {
                display: block;
                content: '';
                border-top: 4px solid;
                border-left: 4px solid transparent;
                border-right: 4px solid transparent;
                height: 0;
                width: 0;
            }
        }

        &.disabled {
            border-color: $disabledBgColor;
            color: $disabledForeColor;

            &:focus {
                border-color: $disabledBgColor;
                // box-shadow: none;
            }

            >.dropdown-text,
            >.dropdown-caret {
                cursor: default;
            }
        }
    }

    >.dropdown-panel {
        position: absolute;
        visibility: hidden;
        opacity: 0;
        transform: scaleY(0);
        transform-origin: top;
        background-color: $bgColor;
        top: calc($headerHeight + 2px);
        z-index: 2;
        transition: transform 120ms ease, opacity 120ms ease, visibility 120ms ease;
        width: calc(100% + 2px);
        box-sizing: border-box;
        /*border: 1px solid $borderColor;
        border-top-width: 0;*/
        box-shadow: 0 3px 6px -4px rgba(0, 0, 0, .12), 0 6px 16px 0 rgba(0, 0, 0, .08), 0 9px 28px 8px rgba(0, 0, 0, .05);
        left: -1px;

        &.slide-up {
            top: auto;
            /*border-top-width: 1px;
            border-bottom-width: 0;*/
            transform-origin: bottom;
        }

        &.active {
            visibility: visible;
            opacity: 1;
            transform: scaleY(1);
        }

        >.dropdown-search {
            box-sizing: border-box;
            height: $searchBarHeight;
            line-height: $searchBarHeight;
            padding: 0 8px;
            position: relative;
            display: flex;
            align-items: center;

            >input[type="text"] {
                box-sizing: border-box;
                width: 100%;
                height: $searchInputHeight;
                outline: none;
                border: 1px solid $borderColor;
                border-radius: $borderRadius;
                padding: 0 6px 0 22px;
                color: $foreColor;
                transition: all .3s;

                &:hover,
                &:focus {
                    border-color: $focusColor;
                }

                // &:focus {
                //     box-shadow: 0 0 3px 1px rgba(0, 0, 0, .2);
                // }
            }

            >svg {
                position: absolute;
                left: 14px;
                width: $searchIconSize;
                height: 100%;
                cursor: text;
            }
        }

        >.dropdown-list {
            margin: 0;
            padding: 0;
            list-style: none;
            max-height: $listMaxHeight;
            overflow-y: auto;
            font-size: .875rem;
            @include scrollbar();

            &.filtered>li:first-child {
                background-color: $hoverColor;
            }

            >li {
                // display: flex;
                // align-items: center;
                line-height: $dropItemHeight;
                height: $dropItemHeight;
                padding: 0 10px;
                cursor: pointer;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;

                &:hover,
                &.selected {
                    background-color: $hoverColor;
                }

                >.checkbox-wrapper {
                    height: $dropItemHeight;
                    display: flex;
                }
            }
        }
    }
}