'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-7a477838.js');
const randomIdGenerator_util = require('./randomIdGenerator.util-e7f4b6de.js');
const formTextareaVariation_enum = require('./form-textarea-variation.enum-9c90d40f.js');

const formTextareaCss = ".sc-digi-form-textarea-h{--digi--form-textarea--height--small:4.6875rem;--digi--form-textarea--height--medium:8.4375rem;--digi--form-textarea--height--large:10.3125rem;--digi--form-textarea--height--auto:auto;--digi--form-textarea--border-radius:var(--digi--border-radius--input);--digi--form-textarea--padding:calc(var(--digi--gutter--medium) / 2) var(--digi--gutter--medium);--digi--form-textarea--background--empty:var(--digi--color--background--interactive--default--input-elements);--digi--form-textarea--background--neutral:var(--digi--color--background--interactive--default--input-elements);--digi--form-textarea--background--success:var(--digi--color--background--interactive--validation--success);--digi--form-textarea--background--warning:var(--digi--color--background--interactive--validation--warning);--digi--form-textarea--background--error:var(--digi--color--background--interactive--validation--error);--digi--form-textarea--border--neutral:var(--digi--border-width--input-regular) solid;--digi--form-textarea--border--error:var(--digi--border-width--input-validation) solid;--digi--form-textarea--border--success:var(--digi--border-width--input-validation) solid;--digi--form-textarea--border--warning:var(--digi--border-width--input-validation) solid;--digi--form-textarea--border-color--neutral:var(--digi--color--border--interactive--default--on-input);--digi--form-textarea--border-color--success:var(--digi--color--border--interactive--validation--success);--digi--form-textarea--border-color--warning:var(--digi--color--border--interactive--validation--warning);--digi--form-textarea--border-color--error:var(--digi--color--border--interactive--validation--error)}.sc-digi-form-textarea-h .digi-form-textarea.sc-digi-form-textarea{display:flex;flex-direction:column;gap:0.4em}.sc-digi-form-textarea-h .digi-form-textarea--small.sc-digi-form-textarea{--HEIGHT:var(--digi--form-textarea--height--small)}.sc-digi-form-textarea-h .digi-form-textarea--medium.sc-digi-form-textarea{--HEIGHT:var(--digi--form-textarea--height--medium)}.sc-digi-form-textarea-h .digi-form-textarea--large.sc-digi-form-textarea{--HEIGHT:var(--digi--form-textarea--height--large)}.sc-digi-form-textarea-h .digi-form-textarea--neutral.sc-digi-form-textarea{--BORDER:var(--digi--form-textarea--border--neutral);--BORDER-COLOR:var(--digi--form-textarea--border-color--neutral);--BACKGROUND:var(--digi--form-textarea--background--neutral)}.sc-digi-form-textarea-h .digi-form-textarea--empty.sc-digi-form-textarea:not(:focus-within){--BACKGROUND:var(--digi--form-textarea--background--empty)}.sc-digi-form-textarea-h .digi-form-textarea--success.sc-digi-form-textarea{--BORDER:var(--digi--form-textarea--border--success);--BORDER-COLOR:var(--digi--form-textarea--border-color--success);--BACKGROUND:var(--digi--form-textarea--background--success)}.sc-digi-form-textarea-h .digi-form-textarea--warning.sc-digi-form-textarea{--BORDER:var(--digi--form-textarea--border--warning);--BORDER-COLOR:var(--digi--form-textarea--border-color--warning);--BACKGROUND:var(--digi--form-textarea--background--warning)}.sc-digi-form-textarea-h .digi-form-textarea--error.sc-digi-form-textarea{--BORDER:var(--digi--form-textarea--border--error);--BORDER-COLOR:var(--digi--form-textarea--border-color--error);--BACKGROUND:var(--digi--form-textarea--background--error)}.sc-digi-form-textarea-h .digi-form-textarea__content.sc-digi-form-textarea{width:100%}.sc-digi-form-textarea-h .digi-form-textarea__textarea.sc-digi-form-textarea{height:var(--HEIGHT);width:inherit;font-family:var(--digi--global--typography--font-family--default);font-size:var(--digi--typography--body--font-size--desktop);padding:var(--digi--form-textarea--padding);color:var(--digi--color--text--primary);background:var(--BACKGROUND);border:var(--BORDER);border-color:var(--BORDER-COLOR);border-radius:var(--digi--form-textarea--border-radius);box-sizing:border-box}.sc-digi-form-textarea-h .digi-form-textarea__textarea.sc-digi-form-textarea:focus-visible{outline:2px solid black;outline-offset:2px;box-shadow:0px 0px 0px 5px white}";
const DigiFormTextareaStyle0 = formTextareaCss;

const FormTextarea = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.afOnChange = index.createEvent(this, "afOnChange", 7);
        this.afOnBlur = index.createEvent(this, "afOnBlur", 7);
        this.afOnKeyup = index.createEvent(this, "afOnKeyup", 7);
        this.afOnFocus = index.createEvent(this, "afOnFocus", 7);
        this.afOnFocusout = index.createEvent(this, "afOnFocusout", 7);
        this.afOnInput = index.createEvent(this, "afOnInput", 7);
        this.afOnDirty = index.createEvent(this, "afOnDirty", 7);
        this.afOnTouched = index.createEvent(this, "afOnTouched", 7);
        this.afOnReady = index.createEvent(this, "afOnReady", 3);
        this.hasActiveValidationMessage = false;
        this.dirty = false;
        this.touched = false;
        this.afLabel = undefined;
        this.afLabelDescription = undefined;
        this.afVariation = formTextareaVariation_enum.FormTextareaVariation.MEDIUM;
        this.afName = undefined;
        this.afId = randomIdGenerator_util.randomIdGenerator('digi-form-textarea');
        this.afMaxlength = undefined;
        this.afMinlength = undefined;
        this.afRequired = undefined;
        this.afRequiredText = undefined;
        this.afAnnounceIfOptional = false;
        this.afAnnounceIfOptionalText = undefined;
        this.value = undefined;
        this.afValue = undefined;
        this.afValidation = formTextareaVariation_enum.FormTextareaValidation.NEUTRAL;
        this.afValidationText = undefined;
        this.afRole = undefined;
        this.afAriaActivedescendant = undefined;
        this.afAriaLabelledby = undefined;
        this.afAriaDescribedby = undefined;
        this.afAutofocus = undefined;
    }
    onValueChanged(value) {
        this.afValue = value;
    }
    onAfValueChanged(value) {
        this.value = value;
    }
    afValidationTextWatch() {
        this.setActiveValidationMessage();
    }
    /**
     * Hämtar en referens till textareaelementet. Bra för att t.ex. sätta fokus programmatiskt.
     * @en Returns a reference to the textarea element. Handy for setting focus programmatically.
     */
    async afMGetFormControlElement() {
        return this._textarea;
    }
    componentWillLoad() {
        this.afValue ? (this.value = this.afValue) : (this.afValue = this.value);
        this.setActiveValidationMessage();
    }
    componentDidLoad() {
        this.afOnReady.emit();
    }
    setActiveValidationMessage() {
        this.hasActiveValidationMessage = !!this.afValidationText;
    }
    get cssModifiers() {
        return {
            'digi-form-textarea--small': this.afVariation === formTextareaVariation_enum.FormTextareaVariation.SMALL,
            'digi-form-textarea--medium': this.afVariation === formTextareaVariation_enum.FormTextareaVariation.MEDIUM,
            'digi-form-textarea--large': this.afVariation === formTextareaVariation_enum.FormTextareaVariation.LARGE,
            'digi-form-textarea--auto': this.afVariation === formTextareaVariation_enum.FormTextareaVariation.AUTO,
            'digi-form-textarea--neutral': this.afValidation === formTextareaVariation_enum.FormTextareaValidation.NEUTRAL,
            'digi-form-textarea--success': this.afValidation === formTextareaVariation_enum.FormTextareaValidation.SUCCESS,
            'digi-form-textarea--error': this.afValidation === formTextareaVariation_enum.FormTextareaValidation.ERROR,
            'digi-form-textarea--warning': this.afValidation === formTextareaVariation_enum.FormTextareaValidation.WARNING,
            'digi-form-textarea--empty': !this.afValue &&
                (!this.afValidation ||
                    this.afValidation === formTextareaVariation_enum.FormTextareaValidation.NEUTRAL)
        };
    }
    blurHandler(e) {
        if (!this.touched) {
            this.afOnTouched.emit(e);
            this.touched = true;
        }
        this.setActiveValidationMessage();
        this.afOnBlur.emit(e);
    }
    changeHandler(e) {
        this.afOnChange.emit(e);
    }
    focusHandler(e) {
        this.afOnFocus.emit(e);
    }
    focusoutHandler(e) {
        this.afOnFocusout.emit(e);
    }
    keyupHandler(e) {
        this.afOnKeyup.emit(e);
    }
    inputHandler(e) {
        this.afValue = this.value = e.target.value;
        if (!this.dirty) {
            this.afOnDirty.emit(e);
            this.dirty = true;
        }
        this.setActiveValidationMessage();
        this.afOnInput.emit(e);
    }
    render() {
        return (index.h("div", { key: '7db0a51f5df800c0b168ffe8b73a8ab7facff47d', class: Object.assign({ 'digi-form-textarea': true }, this.cssModifiers) }, index.h("div", { key: 'fcc3dda067cc458bd42bc3782f9319a41b43a158', class: "digi-form-textarea__label" }, index.h("digi-form-label", { key: 'e38c247bcb49fc7a25c36b43b4a2cd9e54f71fbb', afFor: this.afId, afLabel: this.afLabel, afDescription: this.afLabelDescription, afRequired: this.afRequired, afAnnounceIfOptional: this.afAnnounceIfOptional, afRequiredText: this.afRequiredText, afAnnounceIfOptionalText: this.afAnnounceIfOptionalText })), index.h("div", { key: '05fe0e8e1436cc08a9899526fb914c107e354798', class: "digi-form-textarea__content" }, index.h("textarea", { key: '1a5cd259c241e0855a1a58175d16ee8dd68a60f5', class: "digi-form-textarea__textarea", ref: (el) => (this._textarea = el), onBlur: (e) => this.blurHandler(e), onChange: (e) => this.changeHandler(e), onFocus: (e) => this.focusHandler(e), onFocusout: (e) => this.focusoutHandler(e), onKeyUp: (e) => this.keyupHandler(e), onInput: (e) => this.inputHandler(e), "aria-activedescendant": this.afAriaActivedescendant, "aria-describedby": this.afAriaDescribedby, "aria-labelledby": this.afAriaLabelledby, "aria-invalid": this.afValidation === formTextareaVariation_enum.FormTextareaValidation.ERROR
                ? 'true'
                : 'false', maxLength: this.afMaxlength, minLength: this.afMinlength, role: this.afRole, required: this.afRequired, id: this.afId, name: this.afName, value: this.afValue, autofocus: this.afAutofocus ? this.afAutofocus : null })), index.h("div", { key: 'da195f032a227bfe9ae3e116684b1bfdb55e255e', class: "digi-form-textarea__footer" }, index.h("div", { key: '7af0abecbb36e94f613fd8d338de34a9960cc5d7', class: "digi-form-textarea__validation", "aria-atomic": "true", role: "alert", id: `${this.afId}--validation-message` }, this.hasActiveValidationMessage &&
            this.afValidation != formTextareaVariation_enum.FormTextareaValidation.NEUTRAL && (index.h("digi-form-validation-message", { key: '0d6cf7d983feadf617efd18d2afe9b4a73e83f6e', class: "digi-form-textarea__validation-message", "af-variation": this.afValidation }, this.afValidationText))))));
    }
    get hostElement() { return index.getElement(this); }
    static get watchers() { return {
        "value": ["onValueChanged"],
        "afValue": ["onAfValueChanged"],
        "afValidationText": ["afValidationTextWatch"]
    }; }
};
FormTextarea.style = DigiFormTextareaStyle0;

exports.digi_form_textarea = FormTextarea;
