import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-CV0Pyo1O.js';
import { w as input, x as label, q as inputInvalid, u as inputDisabled, v as inputFocused } from './parts-CPKMvyV_.js';
import { F as FormControlErrorText } from './form-control-error-text-Di9QePY5.js';
import './event-types-CZfYo5-1.js';

const FormControlFile = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.formControlInput = createEvent(this, "formControlInput", 7);
        this.formControlBlur = createEvent(this, "formControlBlur", 7);
        this.fileSelected = createEvent(this, "fileSelected", 7);
        this.isFocused = false;
        this.errorText = '';
        this.inputHandler = () => { };
        this.disabled = false;
        this.handleFormControlInput = (event) => {
            const target = event.target;
            const name = target.getAttribute('name');
            this.inputHandler(name, target.value);
            this.formControlInput.emit({ name, value: target.value });
        };
        this.changeHandler = () => {
            const inputFileList = this.fileInput.files;
            if (inputFileList) {
                this.fileSelected.emit({
                    fileList: inputFileList,
                    document_type: this.documentType
                });
            }
        };
    }
    componentDidLoad() {
        this.fileInput = this.el.querySelector('input');
    }
    get part() {
        let part = input;
        if (this.errorText) {
            part = inputInvalid;
        }
        if (this.disabled) {
            part = inputDisabled;
        }
        if (this.isFocused) {
            part = inputFocused;
        }
        return part;
    }
    render() {
        return (h(Host, { key: '9463f54c8850245de8d3ae92a45447fe8d2ce329' }, h("div", { key: 'fec5946a226ef5c270514e6b1f8a95de60d6bcb0', class: "form-group d-flex flex-column" }, h("div", { key: '95783cbeab704b1b970af6619191667991814e73', class: "d-flex align-items-start gap-2" }, h("label", { key: 'c258720ecba808fcf18d3408569b4e391ca0e31f', part: label, class: "form-label", htmlFor: this.name }, this.label), h("form-control-tooltip", { key: '280b23806bc9616506eb56025318b5c6fe395762', helpText: this.helpText })), h("input", { key: '2fcdd1ad6c923de9b28587ee3d1349d0fdf021eb', ref: (el) => this.fileInput = el, type: "file", name: this.name, part: this.part, class: this.errorText ? "form-control is-invalid" : "form-control", multiple: this.multiple, disabled: this.disabled, onChange: this.changeHandler, onInput: this.handleFormControlInput, onFocus: () => this.isFocused = true, onBlur: () => {
                this.isFocused = false;
                this.formControlBlur.emit();
            } }), h(FormControlErrorText, { key: 'df64bb1a0ac921da01fa8a4c3b63a8f5880781d2', errorText: this.errorText, name: this.name }))));
    }
    get el() { return getElement(this); }
};

export { FormControlFile as form_control_file };
