import { r as registerInstance, c as createEvent, h } from './index-Co4V4Zk-.js';

const spwTextareaCss = () => `html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:block}.spw-textarea{position:relative}.spw-textarea__input{flex:1;width:100%;min-height:40px;padding:12px;resize:vertical;border-radius:4px;border:1px solid var(--spw-color-themes-grey-grey-800)}.spw-textarea__input:hover{outline:4px solid var(--spw-color-themes-grey-grey-300)}.spw-textarea__input:focus,.spw-textarea__input:focus-visible{outline:3px solid white;outline-offset:0;box-shadow:0 0 0 6px black}.spw-textarea--disabled .spw-textarea__input{border-color:var(--spw-color-themes-grey-grey-400);background:var(--spw-color-themes-grey-grey-100);color:var(--spw-color-themes-grey-grey-500);cursor:not-allowed}.spw-textarea--disabled .spw-textarea__input::placeholder{color:var(--spw-color-themes-grey-grey-500)}.spw-textarea--disabled .spw-textarea__input:hover,.spw-textarea--disabled .spw-textarea__input:focus,.spw-textarea--disabled .spw-textarea__input:focus-visible{outline:none}.spw-textarea--is-error .spw-textarea__input{border-color:var(--spw-colors-states-error-error-300)}.spw-textarea--large .spw-textarea__input{height:60px;padding:0 24px;line-height:60px}.spw-textarea--is-search .spw-textarea__input{padding-right:80px}.spw-textarea__container{display:flex;align-items:center}.spw-textarea__indicator{padding-left:12px}.spw-textarea__field-message{margin-bottom:8px;margin-top:-4px}.spw-textarea__icon{pointer-events:none;position:absolute;top:50%;right:30px;transform:translateY(-50%);color:var(--spw-ds-primary);font-size:24px}`;

const SpwTextarea = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.valueChanged = createEvent(this, "valueChanged", 7);
        if (hostRef.$hostElement$["s-ei"]) {
            this.internals = hostRef.$hostElement$["s-ei"];
        }
        else {
            this.internals = hostRef.$hostElement$.attachInternals();
            hostRef.$hostElement$["s-ei"] = this.internals;
        }
        this.internalValue = '';
        /** Texte à afficher au-dessus du champ textarea */
        this.label = '';
        /** Nombre de lignes à afficher dans le champ textarea */
        this.rows = 5;
        /** Indique si l'input est un champ de recherche */
        this.isSearch = false;
        /** Indique si le champ textarea est requis */
        this.required = false;
        /** Spécifie la taille du champ textarea : 'large' ou 'medium' */
        this.size = 'medium';
        /** Message d'erreur à afficher sous le champ textarea */
        this.error = '';
        /** Message d'indication (hint) à afficher sous le champ textarea */
        this.hint = '';
        /** Message de succès à afficher sous le champ textarea */
        this.success = '';
        /** Message de warning à afficher sous le champ */
        this.warning = '';
        /** Affiche une icône d'erreur si vrai */
        this.showErrorIcon = true;
        /** Affiche une icône d'indication si vrai */
        this.showHintIcon = true;
        /** Affiche une icône de succès si vrai */
        this.showSuccessIcon = true;
        /** Affiche une icône de warning si vrai */
        this.showWarningIcon = true;
        /** Positionnement du tooltip */
        this.tooltipDirection = 'top';
        /** Curseur du tooltip */
        this.tooltipCursor = 'help';
    }
    /** Méthode publique pour mettre le focus sur le champ textarea. */
    async setFocus() {
        var _a;
        (_a = this.textareaElement) === null || _a === void 0 ? void 0 : _a.focus();
    }
    valueChangedHandler(newVal) {
        this.setValue(newVal);
    }
    setValue(val) {
        this.internalValue = val !== null && val !== void 0 ? val : '';
        this.value = this.internalValue;
        if (this.textareaElement) {
            this.textareaElement.value = this.internalValue;
        }
        this.internals.setFormValue(this.internalValue || null);
        this.valueChanged.emit(this.internalValue);
    }
    componentWillLoad() {
        var _a;
        this.internalValue = (_a = this.value) !== null && _a !== void 0 ? _a : '';
        this.defaultValue = this.internalValue;
    }
    componentDidLoad() {
        this.internals.setFormValue(this.internalValue ? this.internalValue : null);
    }
    formResetCallback() {
        var _a;
        this.setValue((_a = this.defaultValue) !== null && _a !== void 0 ? _a : '');
    }
    handleChange(event) {
        this.internalValue = event.target.value;
        this.value = this.internalValue;
        this.internals.setFormValue(this.internalValue ? this.internalValue : null);
        this.valueChanged.emit(this.internalValue);
    }
    renderErrorMessage() {
        if (this.error) {
            return (h("spw-field-message", { variant: "error", showIcon: this.showErrorIcon }, this.error));
        }
    }
    renderHintMessage() {
        if (this.hint) {
            return (h("spw-field-message", { variant: "hint", showIcon: this.showHintIcon }, this.hint));
        }
    }
    renderSuccessMessage() {
        if (this.success) {
            return (h("spw-field-message", { variant: "success", showIcon: this.showSuccessIcon }, this.success));
        }
    }
    renderWarningMessage() {
        if (this.warning) {
            return (h("spw-field-message", { variant: "warning", showIcon: this.showWarningIcon }, this.warning));
        }
    }
    get elementClass() {
        return {
            'spw-textarea': true,
            [`spw-textarea--${this.size}`]: true,
            'spw-textarea--is-search': this.isSearch,
            'spw-textarea--is-error': !!this.error,
            'spw-textarea--disabled': this.disabled,
        };
    }
    render() {
        return (h("div", { key: 'cbbd0e16dd66f5ae5a1bb6537f77a8984f19a3a6', class: this.elementClass }, this.label && (h("spw-field-label", { key: '95d4f02eddb340fb319a4b56a0b138f378b2afa1', label: this.label, name: this.name, required: this.required, tooltipTitle: this.tooltipTitle, tooltipText: this.tooltipText, tooltipMaxWidth: this.tooltipMaxWidth, tooltipDirection: this.tooltipDirection, tooltipCursor: this.tooltipCursor })), this.assistiveText && (h("spw-field-message", { key: 'b121d8f71bb51677fbca266e76175c5a1011ed1c', class: "spw-textarea__field-message", variant: "hint", showIcon: false }, this.assistiveText)), h("div", { key: '283ad25136bf66441c3c44e38a676cbf6dddd6ba', class: "spw-textarea__container" }, h("textarea", { key: 'ea73e4376ae4ada3ea15565324b3d98ec6e51c5e', class: "spw-textarea__input", ref: el => (this.textareaElement = el), value: this.internalValue, placeholder: this.placeholder, disabled: this.disabled, name: this.name, id: this.name, rows: this.rows, minLength: this.minLength, maxLength: this.maxLength, required: this.required, onInput: event => this.handleChange(event) })), this.renderErrorMessage(), this.renderHintMessage(), this.renderSuccessMessage(), this.renderWarningMessage()));
    }
    static get formAssociated() { return true; }
    static get watchers() { return {
        "value": [{
                "valueChangedHandler": 0
            }]
    }; }
};
SpwTextarea.style = spwTextareaCss();

export { SpwTextarea as spw_textarea };
