// #region Imports
import { ElementValueAccessorBase } from '../../../../../Forms/Accessors/Abstracts/ElementValueAccessorBase';
// #endregion
/**
 * The `FileUploadElementValueAccessor` class.
 *
 * @public
 */
export class FileUploadElementValueAccessor extends ElementValueAccessorBase {
    // #region Methods
    /**
     * @public
     */
    hostConnected() {
        this.host.on('fileAdded', (e) => this.writeValue(e.detail.file));
        this.host.on('fileRemoved', (e) => this.writeValue(e.detail.file));
        this.host.on('filesChanged', (e) => this.writeValue(e.detail.files));
        this.host.on('blur', () => this.onTouched());
        // we need to set the value here because the host element may have a value before the accessor is connected
        void this.host.updateComplete.then(() => {
            this.value = this.host.value;
        });
    }
    /**
     * @public
     * @override
     */
    writeValue(value) {
        if (value) {
            super.writeValue(value);
            this.host.value = Array.isArray(value)
                ? value
                : [value];
        }
    }
    /**
     * @public
     * @override
     */
    resetValue() {
        super.resetValue();
        this.host.reset();
    }
}
/**
 * @public
 */
export const fileUploadElementValueAccessor = (host) => new FileUploadElementValueAccessor(host);
//# sourceMappingURL=FileUploadElementValueAccessor.js.map