// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { HTMLElementEventEmitter, on } from '@breadstone/mosaik-elements';
import { Emit } from '../../../../events/Decorators/EmitDecorator';
import { Disableable } from '../../../Behaviors/Disableable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { filePickerElementTemplate } from './FilePickerElementTemplate';
import { filePickerElementCosmopolitanStyle } from './Themes/FilePickerElement.Cosmopolitan';
import { filePickerElementJoyStyle } from './Themes/FilePickerElement.Joy';
import { filePickerElementMemphisStyle } from './Themes/FilePickerElement.Memphis';
// #endregion
/**
 * File Picker - A user interface component that allows users to select files from their device.
 *
 * @description
 * The FilePicker component provides a simple and accessible way for users to browse and select files,
 * either through a native file dialog or via drag-and-drop integration. It is commonly used in forms,
 * upload flows, and content management systems where files such as images, documents, or media need
 * to be added by the user.
 *
 * FilePicker ensures accessibility and consistency across browsers while offering customization options
 * for styling and behavior. Developers can listen to emitted events to handle picked files and integrate
 * them seamlessly into application logic.
 *
 * @name FilePicker
 * @element mosaik-file-picker
 * @category Input
 *
 * @slot - The default slot for custom trigger content (e.g., a button or icon).
 *
 * @csspart file - The file part.
 *
 * @cssprop {String} --file-picker-background-color - The picker background color CSS custom property.
 * @cssprop {String} --file-picker-border-color - The picker border color CSS custom property.
 * @cssprop {String} --file-picker-border-radius - The picker border radius CSS custom property.
 * @cssprop {String} --file-picker-border-style - The picker border style CSS custom property.
 * @cssprop {String} --file-picker-border-width - The picker border width CSS custom property.
 * @cssprop {String} --file-picker-font-family - The picker font family CSS custom property.
 * @cssprop {String} --file-picker-font-letter-spacing - The picker font letter spacing CSS custom property.
 * @cssprop {String} --file-picker-font-line-height - The picker font line height CSS custom property.
 * @cssprop {String} --file-picker-font-size - The picker font size CSS custom property.
 * @cssprop {String} --file-picker-font-text-decoration - The picker font text decoration CSS custom property.
 * @cssprop {String} --file-picker-font-text-transform - The picker font text transform CSS custom property.
 * @cssprop {String} --file-picker-font-weight - The picker font weight CSS custom property.
 * @cssprop {String} --file-picker-foreground-color - The picker foreground color CSS custom property.
 * @cssprop {String} --file-picker-gap - The picker gap CSS custom property.
 * @cssprop {String} --file-picker-padding-bottom - The picker padding bottom CSS custom property.
 * @cssprop {String} --file-picker-padding-left - The picker padding left CSS custom property.
 * @cssprop {String} --file-picker-padding-right - The picker padding right CSS custom property.
 * @cssprop {String} --file-picker-padding-top - The picker padding top CSS custom property.
 * @cssprop {String} --file-picker-shadow - The picker shadow CSS custom property.
 * @cssprop {String} --file-picker-shadow-blur - The picker shadow blur CSS custom property.
 * @cssprop {String} --file-picker-shadow-color - The picker shadow color CSS custom property.
 * @cssprop {String} --file-picker-shadow-offset-x - The picker shadow offset x CSS custom property.
 * @cssprop {String} --file-picker-shadow-offset-y - The picker shadow offset y CSS custom property.
 * @cssprop {String} --file-picker-shadow-spread - The picker shadow spread CSS custom property.
 * @cssprop {String} --file-picker-transition-duration - The picker transition duration CSS custom property.
 * @cssprop {String} --file-picker-transition-mode - The picker transition mode CSS custom property.
 * @cssprop {String} --file-picker-transition-property - The picker transition property CSS custom property.
 * @cssprop {String} --file-picker-translate - The picker translate CSS custom property.
 *
 * @fires filesPicked {FilesPickedEvent} - Fired when one or multiple files are selected by the user.
 *
 * @example
 * ```html
 * <mosaik-file-picker>
 *   <button>Select File</button>
 * </mosaik-file-picker>
 * ```
 *
 * @public
 */
let FilePickerElement = class FilePickerElement extends Themeable(Disableable(CustomElement)) {
    // #region Fields
    _filesPicked;
    _fileElement;
    _multiple;
    _accept;
    _directory;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._multiple = false;
        this._accept = [];
        this._directory = false;
        this._filesPicked = new HTMLElementEventEmitter(this, 'filesPicked');
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     * The `is` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-file-picker';
    }
    /**
     * Gets or sets the `multiple` property.
     *
     * @public
     * @attr
     */
    get multiple() {
        return this._multiple;
    }
    set multiple(value) {
        if (this._multiple !== value) {
            this._multiple = value;
            this.requestUpdate('multiple');
        }
    }
    /**
     * Gets or sets the `accept` property.
     *
     * @public
     */
    get accept() {
        return this._accept;
    }
    set accept(value) {
        if (this._accept !== value) {
            this._accept = value;
            this.requestUpdate('accept');
        }
    }
    /**
     * Gets or sets the `directory` property.
     *
     * @public
     * @attr
     */
    get directory() {
        return this._directory;
    }
    set directory(value) {
        if (this._directory !== value) {
            this._directory = value;
            this.requestUpdate('directory');
        }
    }
    /**
     * Called when files are picked.
     * Provides reference to `IEventDetail` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get filesPicked() {
        return this._filesPicked;
    }
    // #endregion
    // #region Methods
    /**
     * @public
     */
    pick() {
        if (this.disabled) {
            return;
        }
        this._fileElement.click();
    }
    /**
     * @private
     * @template
     */
    onFileChange(e) {
        const files = e.target.files;
        if (files) {
            this.onFilesPicked({ files: files });
            // reset input value, so the same file can be uploaded multiple times.
            e.target.value = '';
        }
    }
    /**
     * @private
     * @template
     */
    onSlotChange(e) {
        const slot = e.target;
        const assignedElements = slot.assignedElements();
        if (assignedElements.length > 0) {
            const firstElement = assignedElements[0];
            on(firstElement, 'click', () => this.pick());
        }
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this._fileElement = this.getTemplatePart('file');
    }
    /**
     * Emits the `filesPicked` event.
     *
     * @protected
     */
    onFilesPicked(args) {
        this._filesPicked.emit(args);
    }
};
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], FilePickerElement.prototype, "multiple", null);
__decorate([
    Property({ type: (Array) }),
    __metadata("design:type", Array),
    __metadata("design:paramtypes", [Array])
], FilePickerElement.prototype, "accept", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], FilePickerElement.prototype, "directory", null);
__decorate([
    Emit({ eventName: 'filesPicked' }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], FilePickerElement.prototype, "filesPicked", null);
FilePickerElement = __decorate([
    Component({
        selector: 'mosaik-file-picker',
        template: filePickerElementTemplate,
        themes: {
            joy: filePickerElementJoyStyle,
            memphis: filePickerElementMemphisStyle,
            cosmopolitan: filePickerElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], FilePickerElement);
export { FilePickerElement };
//# sourceMappingURL=FilePickerElement.js.map