'use strict';

var index = require('./index-p7cvUYAE.js');
var parts = require('./parts-BXshb_S-.js');
var formControlErrorText = require('./form-control-error-text-BO58Y6zF.js');
require('./event-types-YOY5TKUN.js');

const FormControlFile = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.formControlInput = index.createEvent(this, "formControlInput", 7);
        this.formControlBlur = index.createEvent(this, "formControlBlur", 7);
        this.fileSelected = index.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 = parts.input;
        if (this.errorText) {
            part = parts.inputInvalid;
        }
        if (this.disabled) {
            part = parts.inputDisabled;
        }
        if (this.isFocused) {
            part = parts.inputFocused;
        }
        return part;
    }
    render() {
        return (index.h(index.Host, { key: '9463f54c8850245de8d3ae92a45447fe8d2ce329' }, index.h("div", { key: 'fec5946a226ef5c270514e6b1f8a95de60d6bcb0', class: "form-group d-flex flex-column" }, index.h("div", { key: '95783cbeab704b1b970af6619191667991814e73', class: "d-flex align-items-start gap-2" }, index.h("label", { key: 'c258720ecba808fcf18d3408569b4e391ca0e31f', part: parts.label, class: "form-label", htmlFor: this.name }, this.label), index.h("form-control-tooltip", { key: '280b23806bc9616506eb56025318b5c6fe395762', helpText: this.helpText })), index.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();
            } }), index.h(formControlErrorText.FormControlErrorText, { key: 'df64bb1a0ac921da01fa8a4c3b63a8f5880781d2', errorText: this.errorText, name: this.name }))));
    }
    get el() { return index.getElement(this); }
};

exports.form_control_file = FormControlFile;
