// #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 } from '@breadstone/mosaik-elements';
import { Emit } from '../../../../events/Decorators/EmitDecorator';
import { Appearanceable } from '../../../Behaviors/Appearanceable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Themeable } from '../../../Behaviors/Themeable';
import { Variantable } from '../../../Behaviors/Variantable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { DropZoneState } from '../../../Types/DropZoneState';
import { CustomElement } from '../../Abstracts/CustomElement';
import { dropZoneElementTemplate } from './DropZoneElementTemplate';
import { dropZoneElementCosmopolitanStyle } from './Themes/DropZoneElement.Cosmopolitan';
import { dropZoneElementJoyStyle } from './Themes/DropZoneElement.Joy';
import { dropZoneElementMemphisStyle } from './Themes/DropZoneElement.Memphis';
// #endregion
/**
 * DropZoneElement - An interactive component that defines a target area for drag-and-drop operations.
 *
 * @description
 * The DropZoneElement provides a designated area within the interface where users can drop draggable items.
 * It is commonly used in applications that require file uploads, reordering of elements, or custom drag-and-drop
 * interactions. By offering a clear and accessible drop target, this component helps improve usability and
 * guides users through intuitive drag-and-drop workflows.
 *
 * DropZoneElement can be styled and configured to visually indicate when a draggable item is hovering over it,
 * and it can emit events to notify the application when an item has been dropped. This makes it a flexible
 * building block for implementing custom drag-and-drop experiences across web and application interfaces.
 *
 * @element mosaik-drop-zone
 * @category Interaction
 *
 * @fires dropZoneData {DropZoneDataEvent} - Fired when data is transferred to the drop zone.
 *
 * @slot - The default slot for content displayed inside the drop zone.
 *
 * @example
 * ```html
 * <mosaik-drop-zone>
 *   <p>Drag files here to upload</p>
 * </mosaik-drop-zone>
 * ```
 *
 * @public
 */
let DropZoneElement = class DropZoneElement extends Themeable(Disableable(Appearanceable(Variantable(CustomElement)))) {
    // #region Fields
    _dropZoneData;
    _dragSubscription;
    _dragOverSubscription;
    _dragStartSubscription;
    _dragEndSubscription;
    _dragEnterSubscription;
    _dragLeaveSubscription;
    _dropSubscription;
    _state;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._dragSubscription = null;
        this._dragOverSubscription = null;
        this._dragStartSubscription = null;
        this._dragEndSubscription = null;
        this._dragEnterSubscription = null;
        this._dragLeaveSubscription = null;
        this._dropSubscription = null;
        this._state = 'none';
        this._dropZoneData = new HTMLElementEventEmitter(this, 'dropZoneData');
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-drop-zone';
    }
    /**
     * Gets or sets the `state` property.
     *
     * @readonly
     * @attr
     */
    get state() { return this._state; }
    set state(value) {
        if (this._state !== value) {
            this._state = value;
            this.requestUpdate('state');
        }
    }
    /**
     * Called when the data is transferred to the drop zone.
     * Provides reference to `{@link IDropZoneDataEventDetail}` as event detail.
     *
     * @public
     * @readonly
     * @eventProperty
     */
    get dropZoneData() {
        return this._dropZoneData;
    }
    // #endregion
    // #region Methods
    /**
     * @public
     * @override
     */
    connectedCallback() {
        super.connectedCallback();
        this._dragSubscription = this.on('drag', (e) => this.onDrag(e));
        this._dragOverSubscription = this.on('dragover', (e) => this.onDragOver(e));
        this._dragStartSubscription = this.on('dragstart', (e) => this.onDragStart(e));
        this._dragEndSubscription = this.on('dragend', (e) => this.onDragEnd(e));
        this._dragEnterSubscription = this.on('dragenter', (e) => this.onDragEnter(e));
        this._dragLeaveSubscription = this.on('dragleave', (e) => this.onDragLeave(e));
        this._dropSubscription = this.on('drop', (e) => this.onDrop(e));
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this._dragSubscription?.dispose();
        this._dragOverSubscription?.dispose();
        this._dragStartSubscription?.dispose();
        this._dragEndSubscription?.dispose();
        this._dragEnterSubscription?.dispose();
        this._dragLeaveSubscription?.dispose();
        this._dropSubscription?.dispose();
    }
    /**
     * Emits the {@link dropZoneData} event.
     *
     * @protected
     */
    onDropZoneData(args) {
        this._dropZoneData.emit(args);
    }
    /**
     * @protected
     */
    onDrag(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        this.state = event.type;
    }
    /**
     * @protected
     */
    onDragOver(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        if (event.dataTransfer) {
            event.dataTransfer.dropEffect = event.dataTransfer.effectAllowed === 'move' ? 'move' : 'copy';
        }
        this.state = event.type;
    }
    /**
     * @protected
     */
    onDragStart(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        this.state = event.type;
    }
    /**
     * @protected
     */
    onDragEnd(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        this.state = event.type;
    }
    /**
     * @protected
     */
    onDragEnter(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        // IMPORTANT: Drag events fire not only when entering or leaving the host as a whole,
        // but also when moving between child elements inside the same host. Without this guard,
        // every small movement inside the drop zone would incorrectly trigger a "leave"/"enter"
        // state change, causing flickering and broken visual feedback. By explicitly checking
        // whether the event path still includes the host element, we can differentiate between
        // internal transitions (safe to ignore) and real exits/entries from the drop zone.
        if (event.composedPath().includes(this)) {
            this.state = 'dragenter';
        }
        this.state = event.type;
    }
    /**
     * @protected
     */
    onDragLeave(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        // IMPORTANT: Not all browsers provide reliable `relatedTarget` information for drag
        // operations, especially when dragging external data (e.g. files from the OS). Using
        // `composedPath()` ensures that we inspect the actual event propagation path through
        // the DOM and Shadow DOM. This makes the drop zone detection more robust and avoids
        // false positives when the user is still inside the component boundaries.
        if (event.composedPath().includes(this)) {
            this.state = event.type;
        }
    }
    /**
     * @protected
     */
    onDrop(event) {
        if (this.disabled) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        this.state = event.type;
        this.onDropZoneData({ data: event.dataTransfer });
        setTimeout(() => {
            this.state = 'none';
        }, 250);
    }
};
__decorate([
    Attribute({ type: DropZoneState }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], DropZoneElement.prototype, "state", null);
__decorate([
    Emit({ eventName: 'dropZoneData' }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [])
], DropZoneElement.prototype, "dropZoneData", null);
DropZoneElement = __decorate([
    Component({
        selector: 'mosaik-drop-zone',
        template: dropZoneElementTemplate,
        themes: {
            joy: dropZoneElementJoyStyle,
            memphis: dropZoneElementMemphisStyle,
            cosmopolitan: dropZoneElementCosmopolitanStyle
        },
        imports: []
    }),
    __metadata("design:paramtypes", [])
], DropZoneElement);
export { DropZoneElement };
//# sourceMappingURL=DropZoneElement.js.map