@import "../../css/variables.scss";

// *************** FORMS & LABELS **************
label {
    display: inline-block;
    margin-bottom: 0.7rem;
    font-size: 1.4rem;
    font-weight: 400;
    line-height: normal;
    color: #999;
}

textarea {
    padding: 10px 10px;
    border-radius: 3px;
    font-size: 1.4rem !important;
    height: 80px;
}

input {
    padding: 0px 10px;
    height: 40px;
    border-radius: 3px;
    font-size: 1.4rem !important;

    &[disabled] {
        border-color: hsla(0, 0%, 80%, 0.5);
        color: #999;
    }
}

input,
textarea {
    width: 100%;
    border: 1px solid #ccc;
    background-color: $white;
    transition: all 0.3s;
    -webkit-appearance: none;

    &:focus {
        outline: 0;
        box-shadow: 0;
    }
}

input.invalid {
    border: 1px solid #cc2f40;
}

input.invalid ~ span:before,
textarea.invalid ~ span:before {
    position: absolute;
    top: calc(100% + 0px);
    padding: 0;
    padding-top: 3px;
    border-radius: 4px;
    content: attr(error);
    color: #cc2f40;
    display: block;
    font-size: 1rem;
    animation-name: ErrorShow;
    animation-duration: 1s;
    z-index: 1;

    @include md {
        font-size: 1.2rem;
    }
}

label.invalid + input,
span.invalid + input,
label.invalid + textarea,
span.invalid + textarea {
    border: 1px solid #cc2f40;
    background-color: #ffecec;
}

label.invalid:before,
span.invalid:before {
    position: absolute;
    top: calc(100% + 2px);
    padding: 6px;
    border-radius: 4px;
    background-color: #cc2f40;
    content: attr(data-error);
    color: #fff;
    display: block;
    font-size: 12px;
    animation-name: ErrorShow;
    animation-duration: 1s;
    z-index: 1;
}

@keyframes ErrorShow {
    0% {
        opacity: 0;
        transform: translateY(-20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0px);
    }
}

textarea {
    &.no-resize {
        resize: none;
    }
}

//Animated input + label
/* Hide the browser-specific focus styles */
.form-item-container {
    display: flex;
    align-items: center;
    flex-direction: column;
    transition: all 0.6s;

    @include sm {
        flex-direction: row;
        .form-item-floating {
            width: calc(100% - 20px);

            &:first-of-type {
                margin-right: 20px;
            }

            &.phone-type {
                width: calc(50% - 10px);
                margin-right: 0;
            }
        }
    }

    &.single {
        .form-item-floating {
            width: 100%;
            margin-right: 0;
        }
    }

    &.promo {
        flex-direction: row;

        .form-item-floating {
            width: calc(100% - 20px);
            &:first-of-type {
                margin-right: 20px;
            }

            @include lg {
                width: calc(50% - 20px);
            }
        }
    }

    &.small {
        .form-item-floating:first-of-type {
            width: 30%;
        }
    }

    &.disabled {
        pointer-events: none;
        opacity: 0.5;

        input {
            border-color: hsla(0, 0%, 80%, 0.5);
            color: #999;
            pointer-events: none;
        }
    }

    &.hidden {
        display: none;
    }
}

.form-item-floating {
    border-width: 0;
    margin-bottom: 20px;
    width: 100%;

    svg.password {
        fill: $darker-blue;
        position: absolute;
        right: 10px;
        top: calc(50% + 16px);
        transform: translateY(calc(-50% - 5px));
        width: 18px;
        height: 18px;
        cursor: pointer;

        &:hover {
            #lid,
            #eye {
                animation-play-state: running;
            }
        }

        #lid {
            animation: blink 0.8s infinite;
            animation-play-state: paused;
        }

        #eye {
            animation: squeeze 0.8s infinite;
            animation-play-state: paused;
        }

        @keyframes blink {
            90% {
                transform: none;
                animation-timing-function: ease-in;
            }
            93% {
                transform: translateY(15px) scaleY(0);
            }
            100% {
                animation-timing-function: ease-out;
            }
        }

        @keyframes squeeze {
            90% {
                transform: none;
                animation-timing-function: ease-in;
            }
            93% {
                transform: translateY(8px) scaleY(0.4);
            }
            100% {
                animation-timing-function: ease-out;
            }
        }
    }

    &:focus {
    }

    &::placeholder {
        color: transparent;
    }
}

.form-item-floating {
    position: relative;

    input,
    textarea {
        &,
        & + label {
            line-height: 1;
            font: inherit;
            position: relative;
        }
    }
}

fieldset {
    margin: 10px 0 30px 0;
    padding: 0px;
    border: none;

    .form-item {
        display: flex;
        align-items: center;
        position: relative;

        input {
            flex-basis: 35px;
        }
    }
}

fieldset {
    .form-item {
        position: relative;

        input[type="radio"] {
            visibility: hidden;
            opacity: 0;
            position: absolute;
        }

        input[type="radio"] + label {
            position: relative;
            padding-left: 25px;
            margin: 8px 0;
            line-height: 16px;
            cursor: pointer;
            transition: all 0.4s;

            &::before {
                content: "";
                position: absolute;
                top: 0;
                left: 0;
                height: 16px;
                width: 16px;
                border-radius: 100%;
                border: 2px solid rgba($pink, 0.5);
                transition: all 0.4s;
            }
        }

        input[type="radio"]:checked + label {
            color: $pink;

            &::before {
                border: 2px solid rgba($pink, 1);
                background-color: $pink;
            }
        }
    }
}

fieldset {
    .form-item {
        margin-bottom: 1rem;
        position: relative;

        a {
            transition: all 0.4s;
            color: $darker-blue;

            &:hover {
                color: $dark-blue;
            }
        }

        label {
            color: #333;
        }

        span::before {
            left: 35px;
            top: calc(100% - 10px);
        }

        input[type="checkbox"] {
            visibility: hidden;
            opacity: 0;
            position: absolute;
        }

        input[type="checkbox"] + label {
            position: relative;
            padding-left: 35px;
            margin: 8px 0;
            line-height: 20px;
            cursor: pointer;
            transition: all 0.4s;

            &::before {
                content: "";
                position: absolute;
                top: 50%;
                left: 0;
                transform: translateY(-50%);
                height: 25px;
                width: 25px;
                border-radius: 5px;
                border: 1px solid rgba(#ccc, 0.5);
                transition: all 0.4s;
            }

            &::after {
                content: url("data:image/svg+xml; utf8,<svg  fill='%234a1bff' version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 512 512' style='enable-background:new 0 0 512 512;' xml:space='preserve'><g><path d='M504.502,75.496c-9.997-9.998-26.205-9.998-36.204,0L161.594,382.203L43.702,264.311c-9.997-9.998-26.205-9.997-36.204,0c-9.998,9.997-9.998,26.205,0,36.203l135.994,135.992c9.994,9.997,26.214,9.99,36.204,0L504.502,111.7C514.5,101.703,514.499,85.494,504.502,75.496z'/></g></svg>");
                display: block;
                width: 15px;
                height: 15px;
                position: absolute;
                left: 5px;
                top: 50%;
                transform: translateY(-50%);
                opacity: 0;
                visibility: hidden;
                transition: all 0.4s;
            }
        }

        input[type="checkbox"].invalid + label {
            &::before {
                border: 1px solid rgba($warning-red, 1);
            }

            &::after {
                opacity: 0;
                visibility: hidden;
            }
        }

        input[type="checkbox"]:checked + label {
            &::before {
                border: 1px solid rgba($darker-blue, 1);
            }

            &::after {
                opacity: 1;
                visibility: visible;
            }
        }
    }
}

.floating-label {
    display: flex;
    align-items: center;
    justify-content: flex-start;

    .custom-tooltip {
        margin-left: 6px;
        cursor: pointer;
        height: 15px;
        width: 15px;
        color: $darker-blue !important;
        border-radius: 100%;

        &:after {
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
        }

        &:hover:after {
            font-size: 1.4rem;
            background-color: #fafafa;
            color: #212121;
            border: 1px solid #ccc;
            box-shadow: 0 5px 30px rgba(0, 0, 0, 0.1) !important;
            padding: 20px;
            border-radius: 2px;
            margin-bottom: 5px;
            padding: 15px;

            @include md {
                width: 26rem;
            }
        }

        &:hover:before {
            left: 0;
            border-color: #fff transparent;
            border-width: 8px 8px 0 8px;
            bottom: 17px;
        }

        .icon {
            font-size: 1.2rem;
            font-weight: 700;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    }
}
