// #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.value = e.detail.file);
        this.host.on('fileRemoved', (e) => this.value = e.detail.file);
        this.host.on('filesChanged', (e) => this.value = e.detail.files);
        this.host.on('blur', () => this.onTouched());
        // Sync the initial host value without triggering onChange, because
        // the host element may already have a value before the accessor is connected.
        void this.host.updateComplete.then(() => {
            this.writeValue(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