@import '../dynamic.scss';

// Set form control height
.form-control {
    &:not(textarea):not([type='checkbox']):not([type='radio']):not(.form-control-sm):not(.form-control-lg):not([size]):not([multiple]) {
        height: $input-height;
        line-height: $input-height;
    }
}

// Reset checkbox width
input[type='checkbox'] {
    width: auto;
}
// Set IOS-friendly input size to avoid zoom
@include media-breakpoint-down(sm) {
    input[type='text'],
    input[type='password'],
    input[type='tel'],
    input[type='number'],
    input[type='email'],
    textarea {
        font-size: 1.6rem !important;
    }
}

.form-control {
    border-radius: $border-radius;
    background-color: $gray-200;
    border: 1px solid $gray-200;
    transition-property: background-color, border-color, box-shadow, color;

    &::placeholder {
        color: $gray-500;
    }

    &:hover {
        border-color: $gray-400;
    }
    &:hover::placeholder {
        color: $gray-800;
    }

    &:focus {
        box-shadow: inset 0 3px 3px 0 rgba(0, 0, 0, 0.13);
        color: $gray-800;
        outline: none;
    }

    &:disabled {
        border-color: transparent;
        &:hover {
            background-color: $gray-200;
            &::placeholder {
                color: $gray-500;
            }
        }
    }

    &.form-control-border-dark {
        border-color: $dark;
        &:focus {
            border-color: $input-btn-focus-color;
        }
    }

    &.form-control-rounded {
        padding-left: $input-padding-x-lg;
        border-radius: $input-height / 2;
    }

    &.is-invalid,
    &:invalid {
        color: $danger;
        background-color: mix($danger, $white, 10%);
        border-color: $danger;
        box-shadow: none;
        &::placeholder {
            color: transparentize($danger, 0.5);
        }
    }
}

select.form-control {
    background-color: $white;
    line-height: calc(#{$input-height} - #{$border-width * 2}) !important;
    font-weight: 500;
    &.single-select {
        background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 6'><path d='M.6.1c.2-.1.6-.1.8 0L6 4.8 10.6.2c.2-.2.5-.2.7 0s.2.5 0 .7l-5 5S6.1 6 6 6c-.1 0-.3-.1-.4-.1l-5-5C.5.7.5.3.6.1z'/></svg>");
        background-position: right 1.5rem center;
        background-repeat: no-repeat;
        margin: 0;
        appearance: none;
        &:not(.form-control-lg) {
            height: $input-height;
        }
    }
}

// Checkboxes & radio buttons

$form-check-size-md: 3.2rem;
$form-check-size-sm: 2.4rem;

.form-check {
    line-height: $form-check-size-md;
    padding-left: 0;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: row;
    align-items: flex-start;

    // Common
    .form-check-input {
        margin: 0;
        appearance: none;
        height: $form-check-size-md;
        width: $form-check-size-md;
        flex: 0 0 $form-check-size-md;
        &::before {
            content: ' ';
            background-color: $gray-200;
            border: 1px solid $gray-400;
            border-radius: 50%;
            height: $form-check-size-md;
            width: $form-check-size-md;
            display: inline-block;
            cursor: pointer;
        }
        &:checked::before {
            background-color: $branded;
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 10'><path d='M13.4.6c.2.2.2.5 0 .7L5.2 9.7c-.1.1-.3.1-.4.1-.1 0-.3-.1-.4-.1L.6 5.8c-.2-.2-.2-.5 0-.7.2-.2.5-.2.7 0l3.4 3.5 7.9-8c.2-.1.6-.1.8 0z' clip-rule='evenodd'/></svg>");
            background-size: 1.2rem 1.2rem;
            background-position: center center;
            background-repeat: no-repeat;
            border-color: $branded;
        }
        &:focus,
        &:active {
            outline: none;
            &::before {
                border-color: map-get($active-colors, branded);
                border-width: 2px;
            }
            &:checked::before {
                background-color: map-get($highlighted-colors, branded);
                border-color: map-get($active-colors, branded);
            }
        }
        &:disabled,
        &.disabled {
            &::before {
                opacity: $btn-disabled-opacity;
                cursor: default;
            }
            & + .form-check-label {
                opacity: $btn-disabled-opacity;
                cursor: default;
            }
        }
    }
    .form-check-label {
        padding-left: $form-check-size-md + 0.5rem;
        cursor: pointer;
    }

    &.form-check-sm {
        line-height: $form-check-size-sm;
        .form-check-input {
            appearance: none;
            height: $form-check-size-sm;
            width: $form-check-size-sm;
            flex-basis: $form-check-size-sm;
            &::before {
                content: ' ';
                height: $form-check-size-sm;
                width: $form-check-size-sm;
            }
        }
        .form-check-label {
            padding-left: $form-check-size-sm + 0.5rem;
        }
    }

    // Radio button
    .form-check-input[type='radio'] {
        &:checked::before {
            background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'><path d='M8 12c2.2 0 4-1.8 4-4s-1.8-4-4-4-4 1.8-4 4 1.8 4 4 4zm0-2c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z'/></svg>");
            background-size: 2.1rem 2.1rem;
        }
    }
}
