//
// Copyright (c) 2021 GrowStocks
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

@use '../../Core/Theme';
@use '../../Core/Tools';
@use '../../Core/Typography';
@use '../../Core/Feature';

@mixin base() {
    .sc-text-field {
        position: relative;
        margin: 0;
        cursor: text;
        width: 100%;

        .sc-text-field__label {
            width: 100%;
            font-size: 14px;
            padding: 0 0.7rem;

            position: absolute;
            top: 0.975rem;
            left: 0;

            color: var(--sc-theme--on-input, #232323);
            cursor: text;

            @include Tools.prefix(transition, all 70ms ease);
        }

        .sc-text-field__input {
            width: 100%;

            @include Tools.prefix(transition, all 0.1s ease);

            border-width: 2px !important;
            padding: 1.4rem 0.5rem 0.3rem 0.5rem;
            font-size: Typography.px-to-rem(15px);
            resize: none;
            border-bottom: 2px solid var(--sc-theme--primary-light) !important;

            &:hover {
                cursor: text;
            }

            &::placeholder {
                color: rgba(0 0 0 / 0) !important;
            }

            &:focus {
                outline: none;
                border-color: var(--sc-theme--primary-light) !important;
            }

            &:focus-within,
            &:not(:placeholder-shown) {
                padding: 1.4rem 0.6rem 0.3rem 0.6rem;

                & + .sc-text-field__label {
                    width: auto;
                    margin: 0 0 0 0.3rem;
                    padding: 0 0.4rem;

                    top: 0.4rem;

                    font-size: Typography.px-to-rem(11px);

                    pointer-events: none;
                }
            }

            @content;
        }

        .sc-text-field__helper {
            color: var(--sc-theme--on-surface);
            font-size: Typography.px-to-rem(12px);
            margin-top: 7px;
        }

        &.sc-text-field--error {
            @include Tools.prefix(transition, all 0.1s ease);

            > * {
                border-bottom: 2px solid var(--sc-theme--error) !important;
                color: var(--sc-theme--error);

                &:focus {
                    border-color: var(--sc-theme--error) !important;
                }
            }

            > .sc-text-field__label {
                --sc-theme--placeholder: #e2e2e2 !important;
                border-bottom: none!important;
            }

            > .sc-text-field__helper {
                color: var(--sc-theme--error);
                border-bottom: none !important;
            }
        }
    }
}
