// config stylesheet allows us to use #{$prefix}
@use '@carbon/styles/scss/config' as *;
@use '@mskcc/fundamentals/src/_variables.scss' as v;
@use '@mskcc/fundamentals/src/_mixins.scss' as m;
@use '@mskcc/colors' as c;

@mixin msk-multi-select {
    .msk-select {
        fieldset[disabled] .multiselect {
            pointer-events: none;
        }

        .multiselect {
            border: 1px solid c.$msk--cool-gray-70;
            border-radius: m.msk-rem(4px);
            box-sizing: content-box;
            color: c.$msk--cool-gray-70;
            display: block;
            min-height: 40px;
            position: relative;
            text-align: left;
            width: 100%;

            &,
            .multiselect__input,
            .multiselect__single {
                font-family: inherit;
                font-size: v.$msk--size-2;
                touch-action: manipulation;
            }

            &:focus-within {
                outline: none;
            }

            &.multiselect--disabled {
                background: #ededed;
                opacity: 0.6;
                pointer-events: none;

                input {
                    background: #ededed;
                    color: #ededed;
                }
            }

            &.multiselect--active {
                z-index: 50;

                .multiselect__select {
                    transform: rotateZ(180deg);
                }

                &:not(.multiselect--above) {
                    .multiselect__current,
                    .multiselect__input,
                    .multiselect__tags {
                        border-bottom-left-radius: 0;
                        border-bottom-right-radius: 0;
                    }
                }

                .multiselect__placeholder {
                    display: none;
                }
            }

            &.multiselect--above {
                &.multiselect--active {
                    .multiselect__current,
                    .multiselect__input,
                    .multiselect__tags {
                        border-top-left-radius: 0;
                        border-top-right-radius: 0;
                    }
                }

                .multiselect__content-wrapper {
                    border-bottom: none;
                    border-radius: 5px 5px 0 0;
                    border-top: 1px solid #e8e8e8;
                    bottom: 100%;
                }
            }

            &.multiselect--disabled {
                .multiselect__current,
                .multiselect__select {
                    background: #ededed;
                    color: #a6a6a6;
                }
            }

            .multiselect__content-wrapper {
                background: #fff;
                border: 1px solid #e8e8e8;
                border-bottom-left-radius: 5px;
                border-bottom-right-radius: 5px;
                border-top: none;
                display: block;
                max-height: 240px;
                overflow: auto;
                -webkit-overflow-scrolling: touch;
                position: absolute;
                width: 100%;
                z-index: 50;

                .multiselect__content {
                    display: inline-block;
                    list-style: none;
                    margin: 0;
                    min-width: 100%;
                    padding: 0;
                    vertical-align: top;

                    &::webkit-scrollbar {
                        display: none;
                    }

                    .multiselect__element {
                        display: block;
                    }

                    .multiselect__option {
                        cursor: pointer;
                        display: block;
                        line-height: 16px;
                        min-height: 40px;
                        padding: 12px;
                        position: relative;
                        text-decoration: none;
                        text-transform: none;
                        vertical-align: middle;
                        white-space: nowrap;

                        &::after {
                            font-size: 13px;
                            line-height: 40px;
                            padding-left: 20px;
                            padding-right: 12px;
                            position: absolute;
                            right: 0;
                            top: 0;
                        }

                        &.multiselect__option--checkbox {
                            align-items: center;
                            display: flex;
                            justify-content: space-between;

                            .#{$prefix}--checkbox-wrapper {
                                .#{$prefix}--checkbox-label-text {
                                    display: none;
                                }
                            }

                            .#{$prefix}--form-item {
                                flex: 0;
                            }
                        }
                    }

                    .multiselect__option--highlight {
                        background: c.$msk--cool-gray-10;
                        color: inherit;
                        outline: none;

                        &::after {
                            background: c.$msk--cool-gray-10;
                            color: inherit;
                            content: attr(data-select);
                        }
                    }

                    .multiselect__option--selected {
                        align-items: center;
                        background: c.$msk--cool-gray-10;
                        color: inherit;
                        display: flex;
                        justify-content: space-between;

                        &::after {
                            background: inherit;
                            color: silver;
                            content: attr(data-selected);
                        }

                        .msk-icon {
                            color: c.$msk--blue-70;
                        }
                    }
                }
            }

            .multiselect__spinner {
                background: #fff;
                display: block;
                height: 30px;
                position: absolute;
                right: 35px;
                width: 40px;
                z-index: 49;

                &::before,
                &::after {
                    border-color: c.$msk--cool-gray-70 transparent transparent;
                    border-radius: 100%;
                    border-style: solid;
                    border-width: 2px;
                    box-shadow: 0 0 0 1px transparent;
                    content: '';
                    height: 16px;
                    left: 50%;
                    margin: -8px 0 0 -8px;
                    position: absolute;
                    top: 50%;
                    width: 16px;
                }

                &::before {
                    animation: spinning 2.4s cubic-bezier(0.41, 0.26, 0.2, 0.62);
                    animation-iteration-count: infinite;
                }

                &::after {
                    animation: spinning 2.4s cubic-bezier(0.51, 0.09, 0.21, 0.8);
                    animation-iteration-count: infinite;
                }
            }

            .multiselect__loading-enter-active,
            .multiselect__loading-leave-active {
                opacity: 1;
                transition: opacity 0.4s ease-in-out;
            }

            .multiselect__loading-enter,
            .multiselect__loading-leave-active {
                opacity: 0;
            }

            .multiselect__input,
            .multiselect__single {
                background: #fff;
                border: none;
                border-radius: 5px;
                box-sizing: border-box;
                display: inline-block;
                line-height: 40px;
                margin-bottom: 8px;
                min-height: 28;
                padding: 0 0 0 5px;
                position: relative;
                transition: border 0.1s ease;
                vertical-align: top;
                width: calc(100%);

                &:hover {
                    border-color: #cfcfcf;
                }

                &:focus {
                    border-color: #a8a8a8;
                    outline: none;
                }
            }

            .multiselect__input {
                &::placeholder {
                    color: #35495e;
                }
            }

            .multiselect__single {
                margin-bottom: 8px;
                padding-left: 5px;
            }

            .multiselect_actions {
                align-items: center;
                display: block;
                display: flex;
                height: 100%;
                position: absolute;
                right: 1px;
                z-index: 49;

                .multiselect_separator {
                    align-self: stretch;
                    background-color: c.$msk--cool-gray-70;
                    box-sizing: border-box;
                    margin-bottom: 8px;
                    margin-top: 8px;
                    width: 1px;
                }

                .multiselect__select {
                    align-items: center;
                    box-sizing: border-box;
                    color: c.$msk--cool-gray-100;
                    cursor: pointer;
                    display: inline-flex;
                    height: 38px;
                    justify-content: center;
                    line-height: 16px;
                    margin: 0;
                    padding: 4px 8px;
                    text-align: center;
                    text-decoration: none;
                    top: 1px;
                    transition: transform 0.2s ease;
                    width: 38px;

                    svg {
                        path {
                            fill: c.$msk--cool-gray-100;
                        }
                    }
                }
            }

            .multiselect__placeholder {
                color: #adadad;
                display: inline-block;
                margin-bottom: 10px;
                padding-top: 2px;
            }

            .multiselect__tag ~ .multiselect__input,
            .multiselect__tag ~ .multiselect__single {
                width: auto;
            }

            &.multiselect--has-reset-icon {
                .multiselect__tags {
                    padding: 8px 60px 0 8px;
                }
            }

            &.multiselect--has-reset-text {
                .multiselect__tags {
                    padding: 8px 130px 0 8px;
                }
            }

            &.multiselect--overflow {
                height: 60px;

                .multiselect_actions {
                    .multiselect_overflow_rectangle {
                        background: linear-gradient(
                            270deg,
                            #fff 0%,
                            rgb(255 255 255 / 0%) 100%
                        );
                        height: 48px;
                        width: 24px;
                    }

                    .multiselect__remove_container {
                        background-color: #fff;
                        height: 48px;
                    }
                }

                .multiselect__tags {
                    &:not(.multiselect__tags__outside) {
                        overflow: hidden;
                        white-space: nowrap;
                        width: 90%;
                    }
                }
            }
        }

        .multiselect__tags {
            border-radius: 5px;
            display: block;
            font-size: 14px;
            min-height: 40px;
            padding: 8px 30px 0 8px;

            .multiselect__tags-wrap {
                display: inline-block;
            }

            &.multiselect__tags__outside {
                padding: 8px 0;

                .multiselect__tags-wrap {
                    display: inline-block;
                }

                .multiselect__tag_reset {
                    background-color: transparent;
                    border: none;
                    color: inherit;
                }
            }

            .multiselect__tag_plain {
                color: c.$msk--cool-gray-100;
                font-size: 16px;
                font-weight: 400;
                line-height: 40px;
            }

            .multiselect__tag {
                background: c.$msk--cool-gray-10;
                border: 2px solid c.$msk--cool-gray-20;
                border-radius: 4px;
                color: c.$msk--cool-gray-70;
                display: inline-block;
                font-size: 16px;
                font-weight: 400;
                line-height: 40px;
                margin-bottom: 1px;
                margin-right: 10px;
                max-width: 100%;
                overflow: hidden;

                // padding: 0px 0px 0px 8px;
                padding: 0 30px 0 8px;
                position: relative;
                text-overflow: ellipsis;
                white-space: nowrap;

                .multiselect__tag-icon {
                    height: auto;
                    line-height: 40px;
                    position: absolute;
                    right: 5px;
                    width: 20px;

                    &::after,
                    &::before {
                        color: c.$msk--cool-gray-70;
                        font-size: 20px;
                        font-weight: normal;
                    }

                    &:focus,
                    &:hover {
                        background: c.$msk--cool-gray-10;
                        color: c.$msk--cool-gray-70;

                        &::after {
                            color: c.$msk--cool-gray-70;
                        }
                    }
                }
            }
        }

        .multiselect * {
            box-sizing: border-box;
        }

        .multiselect__remove_container {
            align-items: center;
            color: c.$msk--blue-70;
            cursor: pointer;
            display: flex;

            &.multiselect__tag {
                background: none;
                border: none;

                .multiselect__remove {
                    line-height: 40px;
                    position: absolute;
                }
            }
        }

        .multiselect__reset_text {
            color: c.$msk--blue-70;
        }

        .multiselect__remove {
            border-radius: 5px;
            bottom: 0;
            cursor: pointer;
            font-style: initial;
            font-weight: 700;
            height: 38px;
            line-height: 38px;
            right: 0;
            text-align: center;
            top: 0;
            transition: all 0.2s ease;
            width: 30px;

            &::before {
                color: c.$msk--blue-70;
                content: '×';
                font-size: 20px;
                font-weight: normal;
            }
        }

        .multiselect__current {
            border: 1px solid #e8e8e8;
            border-radius: 5px;
            box-sizing: border-box;
            cursor: pointer;
            display: block;
            line-height: 16px;
            margin: 0;
            min-height: 40px;
            overflow: hidden;
            padding: 8px 12px 0;
            padding-right: 30px;
            text-decoration: none;
            white-space: nowrap;
        }

        .multiselect__option--disabled {
            background: #ededed !important;
            color: #a6a6a6 !important;
            cursor: text;
            pointer-events: none;
        }

        .multiselect__option--group {
            background: #ededed;
            color: #35495e;
        }

        .multiselect-enter-active,
        .multiselect-leave-active {
            transition: all 0.15s ease;
        }

        .multiselect-enter,
        .multiselect-leave-active {
            opacity: 0;
        }

        .multiselect__strong {
            display: inline-block;
            line-height: 20px;
            margin-bottom: 8px;
            vertical-align: top;
        }

        *[dir='rtl'] .multiselect {
            text-align: right;
        }

        *[dir='rtl'] .multiselect__select {
            left: 1px;
            right: auto;
        }

        *[dir='rtl'] .multiselect__tags {
            padding: 8px 8px 0 40px;
        }

        *[dir='rtl'] .multiselect__content {
            text-align: right;
        }

        *[dir='rtl'] .multiselect__option::after {
            left: 0;
            right: auto;
        }

        *[dir='rtl'] .multiselect__clear {
            left: 12px;
            right: auto;
        }

        *[dir='rtl'] .multiselect__spinner {
            left: 1px;
            right: auto;
        }

        @keyframes spinning {
            from {
                transform: rotate(0);
            }

            to {
                transform: rotate(2turn);
            }
        }
    }
}
