$input-height: #{size('large')};
$checkbox-size: 32px;

@mixin input-container() {
    @include flex();
    @include flex-wrap();
    @include align-items-center();
    @include height-modifiers();
    margin-bottom: 20px;
    overflow: hidden;
    white-space: nowrap;
    will-change: border;

    @include breakpoint(small) {
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin-bottom: 5px;
    }

    &--bordered {
        @include breakpoint(small) {
            padding: 20px;
            border: 2px solid color('borders');
            border-radius: 4px;
        }
    }

    &--focused {
        @include breakpoint(small) {
            background-color: color('input', 'focus');
        }
    }

    &--full-width {
        width: 100%;
    }
}

//basic-input is meant to be used were we don't want to produce any modifiers
@mixin basic-input() {
    @include font("IntervalNextBook");
    font-size: em(18px);
    color: color('text', 'input');
    padding: 0 20px;
    border-radius: 4px;

    will-change: border;
    -webkit-appearance: none;
    -moz-appearance: none;

    &[type='number'] {
        -moz-appearance:textfield;
    }

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }

    @include input-placeholder {
        @include font("IntervalNextBook");
        color: color('input', 'placeholder');
    }

    &:focus {
        border: 2px solid color('input', 'border-focus');
        outline: none;
    }
}

@mixin input() {
    @include basic-input();
    // height-modifiers must be above height so modifiers override the default height
    height: $input-height;
    @include height-modifiers();
    border: 0;

    &--range {
        position: relative;
        width: calc(100% - 134px);
        border-bottom-right-radius: 0;
        border-top-right-radius: 0;
        border: 2px solid color('borders');
        border-right: 0;
        -webkit-appearance: none;
    }

    &--transparent {
        background-color: transparent;
        border: 0;
    }

    &--full-width {
        width: 100%;
    }

    &--bordered {
        border: 2px solid color('input', 'border');
    }
    &--warning {
        border: 2px solid color('feedback', 'warning');
    }
    &--error {
        border: 2px solid color('feedback', 'error');
    }
    &--success {
        border: 2px solid color('feedback', 'success');
    }
}

@mixin input-button(){
    @include flex();
    @include align-items-center();
    @include justify-content-center();

    // height-modifiers must be below height so modifiers override the default height
    height: $input-height;
    @include height-modifiers();

    width: 67px;
    border: 2px solid color('borders');
    border-left: 1px solid color('borders');
    font-size: em(24px);
    font-weight: bold;
    color: color('primary');
    will-change: background-color;

    &:first-of-type {
        border-right: 0;
    }

    &:last-of-type {
        border-top-right-radius: 4px;
        border-bottom-right-radius: 4px;
    }

    svg {
        fill: color('primary');
    }

    &:hover {
        background-color: color('buttons', 'hover');
        cursor: pointer;
    }

    &:active {
        background-color: color('background', 'light');
    }

    &[disabled],
    &--disabled {
        svg {
            fill: color('input', 'disabled');
        }
    }
}

@mixin textarea() {
    @include input();
    max-width: 410px;
    height: auto;
    padding: 12px;
    border: 2px solid color('input', 'border');
    border-radius: 4px;
    font-size: em(18px);

    @include input-placeholder {
        @include font("IntervalNextBook");
        color: color('input', 'placeholder');
    }

    & + &-counter {
        @include body();
        max-width: 410px;
        text-align: right;
    }

    &--naked {
        max-width: 100%;
        padding: 0;
        border: 0;
        border-radius: 0;
        outline: none;
        background-color: transparent;
    }
}

@mixin checkbox() {
    display: none;

    & + label {
        @include flex();
        height: $checkbox-size;
        line-height: $checkbox-size;
        @include font("IntervalNextReg");
        font-size: em(16px);
        color: color('text', 'body');
        cursor: pointer;
        position: relative;

        &:before {
            content: "";
            width: $checkbox-size;
            height: $checkbox-size;
            border: 2px solid color('input', 'border');
            background: color('primary', 'highlight');
            border-radius: 4px;
            margin-right: 20px;
        }

        svg {
            display: none;
            position: absolute;
            left: 8px;
            top: calc(50% - 6px);
            fill: color('primary', 'highlight');
            width: 17px;
        }
    }

    &:focus,
    &:checked {
        & + label {
            color: color('primary');

            svg {
                display: block;
            }

            &:before {
                background: color('primary');
                border: 2px solid color('primary');
                border-radius: 4px;
            }
        }
    }

    &--use-background {
        &:focus,
        &:checked {
            & + label:before {
                background: color('primary') url("../images/checkbox-icon.svg") center/65% no-repeat;
            }
        }
    }

    &--disabled {
        + label {
            pointer-events: none;
            cursor: default;
            opacity: 0.3;
        }
    }

    &--error {
        + label {
            &:before {
                border: 2px solid color('feedback','error');
            }
        }
    }

    &--small {
        + label {
            padding-left: $checkbox-size !important;
            color: #667485;
            font-size: em(14px);

            &::before {
                width: 20px;
                height: 20px;
            }

            & > svg {
                width: 12px;
                height: 9px;
                top: calc(50% - 4px);
                left: 5px !important;
            }
        }

        &:checked {
            + label {
                color: color("primary");
            }
        }
    }
}

@mixin radio-button() {
    @include flex();
    @include flex-wrap();
    @include align-items-center();

    input[type="radio"] {
        visibility: hidden;
        width: 0;
        height: 0;
    }

    label {
        position: relative;
        padding-left: #{$checkbox-size + 20px};
        height: $checkbox-size;
        line-height: $checkbox-size;
        @include font("IntervalNextReg");
        font-size: em(18px);
        color: color('input', 'label');
        will-change: color;

        &:before,
        &:after {
            content: " ";
            position: absolute;
            display: block;
            border-radius: 50%;
            top: 0;
            left: 0;
        }

        &:before {
            width: $checkbox-size;
            height: $checkbox-size;
            border: 2px solid color('input', 'border');
            will-change: border;
        }

        &:after {
            width: 20px;
            height: 20px;
            will-change: background-color;
            top: 6px;
            left: 6px;
        }
    }

    input[type="radio"]:checked + label {
        color: color('primary');

        &:before {
            background-color: color('buttons');
            border: 2px solid color('primary');
        }
        &:after {
            background-color: color('primary');
        }
    }

    &--disabled {
        label {
            cursor: default;
            color: color('radio-button', 'disabled-text');

            &:before {
                border-color: color('radio-button', 'disabled-border');
            }
        }
    }
}

@mixin mobile-number() {
    @include inline-flex();
    @include align-items-center();
    position: relative;
    width: 100%;
    max-width: 380px;
    height: $input-height;
    @include height-modifiers();

    &__select-wrapper {
        @include select-wrapper();
        height: 100%;
        width: auto;

        &:before,
        &:after {
            z-index: 10;
        }

        select,
        & > div {
            @include basic-select();
            position: relative;
            width: 100%;
            height: 100%;
            padding: 0 38px 0 14px;
            border-top-right-radius: 0;
            border-bottom-right-radius: 0;
            white-space: nowrap;
            -webkit-appearance: none;
            -moz-appearance: none;
        }
    }

    input {
        @include basic-input();
        width: 100%;
        height: 100%;
        border: 2px solid color('input', 'border');
        border-bottom-left-radius: 0;
        border-top-left-radius: 0;
        border-left: 0;

        &:focus {
            margin-left: -2px;
            border: 2px solid color("input", "border-focus");
            z-index: 1;
            width: calc(100% + 2px);
        }
    }

    &--error {
        input {
            border: 2px solid color('feedback', 'error');

            &:focus {
                border: 2px solid color('feedback', 'error');
            }
        }

        & + label {
            margin-top: 16px;
        }
    }
}

@mixin input-price() {
    @include input();
    @include row();
    @include justify-content-center();
    @include align-items-center();
    border: 2px solid color('input', 'border');
    border-radius: 4px;
    flex-wrap: nowrap;

    input,
    &__value {
        font-size: em(20px);
        margin: 0;
    }

    input {
        @include input();
        color: color('input', 'label');
        max-width: 30%;
        padding-left: 0;
        border: inherit;
        border-right: 0;
        border-left: 0;
        text-align: right;
        padding-right: 10px;

        &:focus {
            border: inherit;
            border-right: 0;
            border-left: 0;
        }
    }

    &__value {
        max-width: 70%;
        padding: 0;
        padding-right: 36px;
        border-left: 0;
        line-height: $input-height;
    }

    &__currency {
        color: color('text');
    }

    &__interval {
        color: color('text', 'input');
    }

    @include breakpoint(small) {
        margin: 0;
        padding: 0;

        input,
        &__value {
            width: 50%;
        }
    }

    &--focused {
        border: 2px solid color('input', 'border-focus');
        outline: none;
    }
}

@mixin toggle() {
    position: relative;
    width: 60px;
    height: 32px;
    overflow: hidden;
    z-index: 2;

    background: color('input', 'disabled');
    cursor: pointer;
    border-radius: 6px;

    &__button {
        width: 22px;
        height: 22px;

        border-radius: 4px;
        background: color('buttons', 'primary');
    }

    &__icon {
        @include flex();
        @include align-items-center();
        position: relative;
        width: 150%;
        height: 100%;

        padding: 5px;
        border-radius: 6px;
        transform: translate3d(-26px, 0, 0);
        will-change: transform;

        svg {
            margin: 6px;
            &:first-child {
                width: 15px;
                height: 11px;
            }
            &:last-child {
                margin-left: 8px;
                width: 11px;
                height: 11px;
            }
        }
    }


    &__input:checked + &__icon {
        background: color('primary');
        transform: translate3d(0, 0, 0);
    }


    &__input {
        position: absolute;
        left: -99999px;
    }

    &__label {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 2;
    }
}

//basic-select is meant to be used were we don't want to produce any modifiers
@mixin basic-select() {
  font-size: em(18px);
  background: color("dropdown", "background");
  color: color("dropdown");
  padding: 0 46px 0 14px;
  border: 2px solid color("dropdown", "border");
  border-radius: 4px;

  will-change: border;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  &:-moz-focusring {
      color: transparent;
      text-shadow: 0 0 0 color("text", "input");
  }

  &:focus {
      border: 2px solid color("dropdown", "active");
      outline: none;
  }
}

@mixin select-wrapper {
    display: inline-block;
    position: relative;

    &:before,
    &:after {
        content: "";
        position: absolute;
        display: block;
        width: 8px;
        height: 2px;
        top: 51%;
        background-color: color("dropdown");
    }

    &:before {
        right: 20px;
        transform: rotate(45deg);
    }

    &:after {
        right: 16px;
        transform: rotate(135deg);
    }
}

@mixin select() {
    @include basic-select();
    height: $input-height;
    @include height-modifiers();
    
    &,
    select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    &-wrapper {
        @include select-wrapper();
    }
}

@mixin dropdown() {
    width: 100%;
    height: 56px;
    background-color: color('dropdown', 'background');
    position: relative;
    display: inline-block;

    @include font("IntervalNextBook");
    font-size: em(20px);
    color: color('dropdown');
    line-height: 54px;

    &__button {
        width: 100%;
        padding-left: 18px;
        border-radius: 4px;
        border: solid 2px color('dropdown', 'border');
        will-change: border-color;

        &:before,
        &:after {
            content: " ";
            position: absolute;
            display: block;
            width: 8px;
            height: 2px;
            top: 50%;
            background-color: color('dropdown');
            will-change: background-color;
        }

        &:before {
            right: 20px;
            transform: rotate(45deg);
        }

        &:after {
            right: 15px;
            transform: rotate(-45deg);
        }
    }

    &__wrapper {
        position: relative;
        display: block;
        width: 100%;
        max-height: 170px;
        border: solid 2px color('dropdown', 'border');
        border-radius: 4px;
        margin-top: 4px;
    }

    &__item {
        width: 100%;
        height: 54px;
        background-color: color('dropdown', 'background');
        will-change: background-color;
        padding-left: 18px;

        &:hover {
            background-color: color('dropdown', 'item-hover');
        }
    }

    &--active {
        .uni-dropdown__button {
            border-color: color('dropdown', 'active');

            &:before,
            &:after {
                background-color: color('dropdown', 'active');
                transform: rotate(-45deg);
            }

            &:after {
                transform: rotate(45deg);
            }
        }
    }
}
