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

.select {
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    width: 100%;
    padding: 0;
    cursor: pointer;
    position: relative;
    margin: 0;

    .dropdown-toggle {
        width: 36px;
        height: 36px;
        display: block;
        position: relative;

        &::before {
            margin-left: -1.1rem;
        }
    }

    .option-list {
        margin: 0;
        padding: 0;
        list-style: none inside;
        overflow-y: auto;
        position: relative;
        display: block;
        background-color: @white;
        font-size: 0.875rem;

        li, a {
            display: block;
        }

        a {
            min-width: auto;
            height: 32px;
            line-height: 32px;
            overflow: hidden;
            text-overflow: ellipsis;
            padding: 0 2rem 0 2.5rem;
        }

        .icon {
            font-size: 20px;
            width: 20px;
            height: 20px;
            left: 8px;
            position: absolute;
            vertical-align: middle;
            text-align: center;
        }

        li:hover {
            background-color: rgba(29, 29, 29, 0.1);
        }

        li.active {
            background-color: #5ebdec;
            color: #ffffff;
            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;
    }

    .button {
        background-color: transparent;
        color: @dark;
        height: 34px;
        min-width: 34px;
        &:focus, &:active {
            box-shadow: none!important;
        }
        &:hover {
            background-color: @light;
            text-shadow: rgba(0,0,0,.25) 0.1em 0.1em 0.2em;
        }
    }

    .input-clear-button {
        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: 34px;
        padding-left: 10px;
        .text-ellipsis();

        .icon {
            margin: 0 4px
        }

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

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

    &:hover {
        input {
            border-color: transparent;
        }
    }

    .drop-container {
        position: absolute;
        top: 100%;
        left: 0;
        width: ~"calc(100% + 2px)";
        height: auto;
        border: 1px solid @borderColor;
        padding: 2px;
        margin-left: -1px;
        z-index: @zindex-dropdown;
        background-color: @white;
        box-shadow: 3px 3px 5px 0 rgba(0,0,0,0.3);

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

    &.focused {
        box-shadow: 0 0 0 3px rgba(red(@lightGray), green(@lightGray), blue(@lightGray), 0.45);
    }

    &.dropdown-toggle {
        &::before {
            margin-left: -1.1rem;
            left: 100%;
            top: 14px;
            margin-top: 0;
            width: .4rem;
            height: .4rem;
        }
    }

    &.disabled {
        &.dropdown-toggle {
            &:before {
                border-color: @white;
            }
        }
    }

    .group-title {
        background-color: #f6f7f8;
        font-size: .75rem;
        line-height: .875rem;
        padding: .25rem .5rem .25rem 1rem;
        border: 0;
        color: #646464;
        font-weight: bold;
        &:hover {
            background-color: #f6f7f8;
            cursor: default;
            border: 0;
        }
    }

    ul {
        right: 0;
        left: 0;
    }

    @selected-item-size: 26px;

    &.multiple {
        flex-wrap: wrap;
        height: auto;
        min-height: 36px;

        .dropdown-toggle {
            position: absolute;
            top: 0;
            right: 0;
        }

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

        .select-input {
            height: auto;
            min-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;}
    .dropdown-toggle {order: 4;}

}

.select {
    &.input-large {
        height: @input-lx;

        .dropdown-toggle, & > .button-group .button {
            height: @input-lx;
            width: @input-lx;
        }

        .dropdown-toggle {
            &::before {
                margin-left: -1.5rem;
            }
        }

        .select-input, .prepend, .append {
            height: @input-lx - 2;
            font-size: 1.3rem;
            padding: 2px 10px;
            line-height: @input-lx - 2;
        }

        &.multiple {
            min-height: @input-lx;
            height: auto;
            .select-input {
                height: auto;
                min-height: @input-lx - 2;
            }
            & > .button-group {
                right: @input-lx;
            }
            & > .button-group:not(.d-none) ~ .select-input {
                margin-right: @input-lx * 2;
            }
        }

        &.dropdown-toggle::before {
            top: 18px;
            width: .6rem;
            height: .6rem;
            margin-left: -1.3rem;
        }
    }

    &.input-small {
        height: @input-sx;

        .dropdown-toggle, & > .button-group .button {
            height: @input-sx;
            width: @input-sx;
        }

        .dropdown-toggle {
            &::before {
                margin-left: -1rem;
            }
        }

        .select-input, .prepend, .append {
            height: @input-sx - 2;
            font-size: .9rem;
            padding: 0 4px;
            line-height: @input-sx - 2;
        }

        &.multiple {
            min-height: @input-sx;
            height: auto;
            .select-input {
                height: auto;
                min-height: @input-sx - 2;
            }
            & > .button-group {
                right: @input-sx;
            }
            & > .button-group:not(.d-none) ~ .select-input {
                margin-right: @input-sx * 2;
            }
        }

        &.dropdown-toggle::before {
            top: 10px;
            width: .325rem;
            height: .325rem;
            margin-left: -.9rem;
        }

        .button-group {
            .button {
                padding: 0;
            }
        }
    }
}

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

        &.dropdown-toggle {
            padding-right: 0!important;
            padding-left: .9rem;
            &::before {
                margin-left: .9rem;
                left: 0;
            }
        }
    }
}

.select {
    .selected-item__group-name {
        font-size: .75rem;
        color: gray;
    }
}