@import (once) "../../include/vars";
@import (once) "../../include/mixins";

:root {
    --select-focus-color: rgba(red(@light-gray), green(@light-gray), blue(@light-gray), 0.45);
    --select-disabled-color: #ccc;
    --select-options-background: #ffffff;
    --select-options-color: #191919;
    --select-option-background: transparent;
    --select-option-color: inherit;
    --select-option-background-hover: rgba(29,29,29,0.1);
    --select-option-color-hover: inherit;
    --select-option-background-selected: #e8e8e8;
    --select-option-color-selected: #191919;
    --select-button-background: transparent;
    --select-button-color: #191919;
    --select-button-background-hover: transparent;
    --select-button-color-hover: #191919;
    --select-dropdown-toggle-color: #191919;
    --select-group-title-background: #f6f7f8;
    --select-group-title-color: #646464;
    --select-item-group-title-background: transparent;
    --select-item-group-title-color: #ccc;
    --select-tag-background: #f6f7f8;
    --select-tag-color: #191919;
    --select-tag-button-background: #f6f7f8;
    --select-tag-button-color: #191919;
    --select-border-radius: 4px;
}

.dark-side {
    --select-focus-color: rgba(red(@light-gray), green(@light-gray), blue(@light-gray), 0.2);
    --select-disabled-color: #ccc;
    --select-options-background: #2b2d30;
    --select-options-color: #dbdfe7;
    --select-option-background: transparent;
    --select-option-color: inherit;
    --select-option-background-hover: #43454a;
    --select-option-color-hover: #ffffff;
    --select-option-background-selected: #43454a;
    --select-option-color-selected: #ffffff;
    --select-button-background: transparent;
    --select-button-color: #dbdfe7;
    --select-button-background-hover: transparent;
    --select-button-color-hover: #ffffff;
    --select-dropdown-toggle-color: #ffffff;
    --select-group-title-background: #1e1f22;
    --select-group-title-color: #646464;
    --select-item-group-title-background: transparent;
    --select-item-group-title-color: #646464;
    --select-tag-background: #2b2d30;
    --select-tag-color: #dbdfe7;
    --select-tag-button-background: #2b2d30;
    --select-tag-button-color: #dbdfe7;
}

.select {
    --select-height: var(--control-height-normal);
    --select-font-size: 16px;

    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    width: 100%;
    padding: 0;
    cursor: pointer;
    position: relative;
    margin: 0;
    user-select: none;
    border-radius: var(--select-border-radius);
    
    &:hover, &.focused {
        .button {
            border:none!important;
            box-shadow: none!important;
        }
    }

    &.small {
        --select-height: var(--control-height-small);
        --select-font-size: 12px;
    }
    &.medium {
        --select-height: var(--control-height-medium);
        --select-font-size: 14px;
    }
    &.large {
        --select-height: var(--control-height-large);
        --select-font-size: 16px;
    }
    &.largest {
        --select-height: var(--control-height-largest);
        --select-font-size: 20px;
    }
}

.select {
    .dropdown-caret {
        --caret-size: calc(var(--select-font-size) * 1.5); 
        position: absolute;
        top: calc((var(--select-height, 36px) - var(--caret-size)) / 2);
        right: 8px;
        height: var(--caret-size);
        width: var(--caret-size);
        aspect-ratio: 1 / 1;
        transform: rotate(90deg);
        transition: transform 0.2s ease-in-out;
        fill: var(--select-dropdown-toggle-color);
    }
    
    &.active-toggle {
        .dropdown-caret {
            transform: rotate(270deg);
        }
    }
    
    .option-list {
        margin: 0;
        list-style: none inside;
        overflow-y: auto;
        position: relative;
        display: block;
        background-color: var(--select-options-background);
        color: var(--select-options-color);
        border-radius: var(--select-border-radius);
        padding: 4px 0;
        
        li {
            display: block;
            margin: 0 4px;
            border-radius: var(--select-border-radius);
            overflow: hidden;
        }
        
        a {
            min-width: auto;
            height: 32px;
            line-height: 32px;
            text-overflow: ellipsis;
            padding: 0 10px;
            font-size: var(--select-font-size);
            display: flex;
            align-items: center;
            justify-content: flex-start;
            white-space: nowrap;
        }

        .icon {
            position: absolute;
            left: 8px;
            top: 8px;
            width: 16px;
            height: 16px;
            font-size: var(--select-font-size);
            display: flex;
            object-fit: cover;
            color: var(--select-option-color);
            
            * {
                object-fit: cover;
                font-size: 16px;
                width: 100%;
                height: 100%;
            }
        }

        a:has(.icon) {
            padding-left: 32px;
        }
        
        li:hover {
            background-color: var(--select-option-background-hover);
            color: var(--select-option-color-hover);
        }

        li.active {
            background-color: var(--select-option-background-selected);
            color: var(--select-option-color-selected);
            font-weight: bold;
        }
    }

    input[type=checkbox]{
        width: 1px;
        height: 1px;
        position: absolute;
        top: 0;
        left: 0;
        opacity: 0;
    }
    select {display: none;}

    & > .button-group {
        display: flex;
        flex-wrap: nowrap;
        margin-right: calc(var(--select-height, 36px) - 2px);
    }

    select[multiple] ~ .button-group {
        margin-right: 0;        
    }
    
    .button {
        background-color: var(--select-button-background);
        color: var(--select-button-color);
        height: calc(var(--select-height, 36px) - 2px);
        min-width: calc(var(--select-height, 36px) - 2px);
        &:hover {
            background-color: var(--select-button-background-hover);
            color: var(--select-button-color-hover);
            text-shadow: rgba(0,0,0,.25) 0.1em 0.1em 0.2em;
        }
    }

    .input-clear-button {
        //font-family: "Segoe UI Symbol", serif;
        height: calc(var(--select-height, 36px) - 2px);
        width: calc(var(--select-height, 36px) - 2px);
        
        background-color: transparent;
        &:hover {
            background-color: transparent;
        }
    }

    .select-input {
        display: flex;
        flex-flow: row wrap;
        align-items: center;
        cursor: pointer;
        width: calc(100% - .1rem);
        height: calc(var(--select-height, 36px) - 2px);
        font-size: var(--select-font-size);
        padding: 0 10px;
        white-space: nowrap;
        .text-ellipsis();

        .icon {
            margin: 0 8px 0 4px;
            width: var(--select-font-size);
            height: var(--select-font-size);
            font-size: var(--select-font-size);
            display: flex;
            object-fit: cover;
            
            * {
                object-fit: cover;
                font-size: inherit;
            }
        }

        &:focus {
            box-shadow: none;
        }
    }

    select[multiple] ~ .select-input {
        padding-left: 0;
    }

    &:hover {
        input {
            border-color: transparent;
        }
        .button {
            &:focus, &:active, &:hover {
                border: none!important;
                box-shadow: none!important;
            }
        }
    }

    .drop-container {
        position: absolute;
        top: 100%;
        left: 0;
        width: calc(100% + 2px);
        height: auto;
        border: 1px solid var(--border-color);
        padding: 2px;
        margin-left: -1px;
        z-index: @z-index-dropdown;
        background-color: var(--select-options-background);
        color: var(--select-options-color);
        box-shadow: 0 10px 15px -3px var(--shadow-color-medium), 0 4px 6px -4px var(--shadow-color-medium);

        .input {
            margin: 4px 2px 6px;
            width: calc(100% - 4px);
        }
    }

    &.drop-full-size {
        .drop-container {
            width: max-content;
        }
    }

    &.focused {
        box-shadow: 0 0 0 3px var(--select-focus-color);
    }

    .group-title {
        background-color: var(--select-group-title-background);
        color: var(--select-group-title-color);
        font-size: .75rem;
        line-height: .875rem;
        padding: .25rem .5rem .25rem 1rem;
        border: 0;
        font-weight: bold;
        &:hover {
            background-color: var(--select-group-title-background)!important;
            color: var(--select-group-title-color)!important;
            cursor: default;
        }
    }

    ul {
        right: 0;
        left: 0;
    }

    @selected-item-size: 26px;

    &.multiple {
        flex-wrap: wrap;
        height: auto;
        min-height: var(--select-height, 36px);

        & > .button-group {
            position: absolute;
            top: 0;
            right: 34px;
        }

        .select-input {
            height: auto;
            min-height: var(--select-height, 36px);
            //margin-right: 34px;
        }
        .button-group:not(.d-none) ~ .select-input {
            margin-right: 68px;
        }
    }

    .prepend {order: 1}
    .append {order: 3}
    .select-input {order: 2;}
    .button-group {order: 3;}
    
    .prepend {
        border-top-left-radius: var(--select-border-radius);
        border-bottom-left-radius: var(--select-border-radius);
    }
}

.select {
    &[dir=rtl], &.rtl {
        flex-direction: row-reverse;
        .select-input {order: 3;}
        .prepend {order: 4;}
        .append {order: 1;}
        .button-group {order: 2}

        .dropdown-caret {
            right: auto;
            left: 8px;
        }
    }
}

.select {
    .selected-item__group-name {
        font-size: .75rem;
        background-color: var(--select-item-group-title-background);
        color: var(--select-item-group-title-color);
    }

    .tag {
        --tag-height: calc(var(--select-height, 36px) - 4px);
        background-color: var(--select-tag-background);
        color: var(--select-tag-color);
        border: 1px solid var(--border-color);
        height: var(--tag-height);
        .title {
            height: 100%;
            font-size: var(--select-font-size);
        }
    }
}

.select {
    &.no-icons {
        .option-list {
            a {
                padding: 0 1rem;
            }
            .icon {
                display: none;
            }
        }
    }
}

.select {
    .unselect-option {
        margin-left: 6px;
    }
}

.select {
    &.pill-input {
        --select-border-radius: calc(var(--select-height, 36px) * 0.44);

        .button {
            border-radius: 50%;
        }

        .tag {
            border-radius: var(--select-border-radius);
            .action {
                border-top-right-radius: 50%;
                border-bottom-right-radius: 50%;
            }
        }
    }
}

.select {
    .d-none {
        display: none;
    }
}