@import "bootstrap/scss/functions";
@import "bootstrap/scss/mixins/breakpoints";
@import "../styles/bootstrap-variables";

input {
    padding-top: $form-select-padding-y-lg;
    padding-bottom: $form-select-padding-y-lg;
    padding-left: $form-select-padding-x-lg;
    padding-right: 2.25rem;
    width: 100%;
}
input, 
label,
.autocomplete {
    font-weight: $input-font-weight;
    line-height: $line-height-base;
    border-width: $input-border-width;
    border-color: $input-border-color;
    border-radius: 1.2rem;

    @include media-breakpoint-up(md) {
        font-size: calc(1.325rem + 0.9vw);
    }
}

.autocomplete {
    position: relative;

    @include media-breakpoint-up(xl) {
        /*
        This covers longest commune :
        51290 - Saint-Remy-en-Bouzemont-Saint-Genest-et-Isson
         */
        max-width: 50vw;
    }

    .autocomplete-results {
        display: none;
    }

    &._open {
        &:not(._withButton) {
            .autocomplete-input {
                border-radius: 1.2rem 1.2rem 0 0;
            }
        }

        &._withButton {
            .autocomplete-input {
                border-radius: 1.2rem 0 0 0;
            }

            .autocomplete-button {
                border-radius: 0 1.2rem 0 0;
            }

            &._focus {
                border-radius: 1.2rem 1.2rem 0 0;
            }
        }

        .autocomplete-results {
            display: block;
        }
    }

    &._withButton {
        display: flex;
        flex-direction: row;
        justify-content: stretch;
        box-shadow: rgb(0 0 0 / 8%) 0 1px 2px inset;

        &._focus {
            box-shadow: 0 0 0 $form-select-focus-width $input-btn-focus-color;
            border-radius: 1.2rem 1.2rem 1.2rem 1.2rem;
        }


        .autocomplete-button,
        .autocomplete-input {
            box-shadow: none;
        }

        .autocomplete-input {
            border-radius: 1.2rem 0 0 1.2rem;
        }
    }

    &-input {
        -webkit-appearance: none;
        appearance: none;
        outline: none;
        background-color: -webkit-control-background;

        &:focus {
            box-shadow: 0 0 0 $form-select-focus-width $input-btn-focus-color;
        }

        &::-webkit-search-decoration,
        &::-webkit-search-cancel-button,
        &::-webkit-search-results-button,
        &::-webkit-search-results-decoration {
            -webkit-appearance:none;
        }
    }

    &-button {
        appearance: none;
        background-color: white;
        border-radius: 0 1.2rem 1.2rem 0;
        border: none;
        box-shadow: rgb(0 0 0 / 8%) 0px 1px 2px inset;
        span {
            white-space: nowrap;
            padding: 6px 10px;
            border-radius: 5px;
            background-color: transparent;
            animation: fade-in 200ms ease-in;
            color: white;
            font-weight: bold;
        }
    }
    .spinner-border {
      position: absolute;
      left: calc(100% + .25em);
      top: .75em;
      width: 1.5em;
      height: 1.5em;
    }

    @keyframes fade-in {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }

    &-results {
        position: absolute;
        top: calc(100% + 2px);
        width: 100%;
        overflow-y: auto;
        max-height: 20rem;
        background: white;
        z-index: 1000;
        box-sizing: border-box;
        padding-left: 0;
        border-radius: 0 0 1.2rem 1.2rem;
        box-shadow: 0 0 0 $form-select-focus-width $input-btn-focus-color;

        @media screen and (min-width: 1024px){
            max-height: 40rem;
        }
    }

    &-result {
        &:hover, &[aria-selected="true"] {
            background-color: $input-btn-focus-color;
        } 
        &[aria-selected="true"] {
            box-shadow: $primary 6px 0 0 inset;
        }
        
        padding-top: $form-select-padding-y-lg;
        padding-bottom: $form-select-padding-y-lg;
        padding-left: $form-select-padding-x-lg;
        font-size: calc(1.325rem + 0.9vw);
        list-style-type: none;
        cursor: pointer;
    }
}

.autocomplete .group {
    background: $light;
}

.zipcode, .codeDepartement {
    font-weight: bold;
}

.label-for-search {
    cursor: pointer;
}
