// #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 { Slottable } from '../../../Behaviors/Slottable';
import { Themeable } from '../../../Behaviors/Themeable';
import { addInheritanceConsumerController } from '../../../Controllers/InheritanceConsumerController';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { CustomElement } from '../../Abstracts/CustomElement';
import { FLOW_BOARD_COLUMN_INHERITANCE_CONTEXT } from './FlowBoardColumnInheritanceContext';
import { flowBoardColumnItemComposerElementTemplate } from './FlowBoardColumnItemComposerElementTemplate';
import { addFlowBoardComposerController } from './FlowBoardComposerController';
import { flowBoardColumnItemComposerElementCosmopolitanStyle } from './Themes/FlowBoardColumnItemComposerElement.Cosmopolitan';
import { flowBoardColumnItemComposerElementJoyStyle } from './Themes/FlowBoardColumnItemComposerElement.Joy';
import { flowBoardColumnItemComposerElementMemphisStyle } from './Themes/FlowBoardColumnItemComposerElement.Memphis';
// #endregion
/**
 * FlowBoardColumnItemComposer - A composer for creating new items in a FlowBoard column.
 *
 * @description
 * Provides a trigger+form pattern for adding new items to a column.
 * This component is completely data-agnostic - it accepts any data structure.
 * The user provides their own form fields via the `form` slot.
 *
 * @remarks
 * The composer emits generic `create` events with user-defined data:
 * - Element properties (title, description, labels, etc.)
 * - Metadata (userId, tags, priority, appointments, custom fields, etc.)
 * - Any other data the application needs
 *
 * @name FlowBoardColumnItemComposerElement
 * @element mosaik-flow-board-column-item-composer
 * @category Layouts
 *
 * @slot trigger - The trigger element that opens the form (e.g., "Add another item" button)
 * @slot form - The form content for creating new items (completely user-defined)
 *
 * @csspart container - The main container element
 * @csspart trigger - The trigger section wrapper
 * @csspart form - The form section wrapper
 *
 * @cssprop {String} --flow-board-composer-padding - Padding for the composer
 * @cssprop {String} --flow-board-composer-gap - Gap between form elements
 *
 * @fires flowBoardBeforeItemCreate {FlowBoardBeforeItemCreateEvent} - Fired before item creation (cancelable)
 * @fires flowBoardItemCreate {FlowBoardItemCreateEvent} - Fired when item is created with user-defined data
 *
 * @example
 * Basic usage with simple form:
 * ```html
 * <mosaik-flow-board-column-item-composer id="composer" slot="footer">
 *   <mosaik-button slot="trigger" variant="ghost" icon="plus">Add item</mosaik-button>
 *   <div slot="form">
 *     <mosaik-input id="title" placeholder="Enter title…"></mosaik-input>
 *     <mosaik-button @click="${submit}">Add</mosaik-button>
 *   </div>
 * </mosaik-flow-board-column-item-composer>
 *
 * <script>
 * function submit() {
 *     const composer = document.getElementById('composer');
 *     const title = document.getElementById('title').value;
 *     composer.create({ title });
 * }
 * </script>
 * ```
 *
 * @example
 * Advanced usage with metadata and custom fields:
 * ```html
 * <mosaik-flow-board-column-item-composer id="composer" slot="footer">
 *   <mosaik-button slot="trigger">Add Task</mosaik-button>
 *   <div slot="form">
 *     <mosaik-input id="title" placeholder="Title"></mosaik-input>
 *     <mosaik-textarea id="description"></mosaik-textarea>
 *     <mosaik-select id="priority">
 *       <option value="low">Low</option>
 *       <option value="high">High</option>
 *     </mosaik-select>
 *     <mosaik-user-picker id="assignee"></mosaik-user-picker>
 *     <mosaik-tag-picker id="tags"></mosaik-tag-picker>
 *     <mosaik-date-picker id="dueDate"></mosaik-date-picker>
 *     <mosaik-button @click="${submit}">Create</mosaik-button>
 *   </div>
 * </mosaik-flow-board-column-item-composer>
 *
 * <script>
 * function submit() {
 *     const composer = document.getElementById('composer');
 *     composer.create({
 *         // Element properties
 *         title: document.getElementById('title').value,
 *         description: document.getElementById('description').value,
 *
 *         // Metadata - saved to backend
 *         metadata: {
 *             priority: document.getElementById('priority').value,
 *             assigneeId: document.getElementById('assignee').selectedUserId,
 *             tags: document.getElementById('tags').selectedTags,
 *             dueDate: document.getElementById('dueDate').value,
 *
 *             // Custom fields - anything your app needs
 *             customFields: {
 *                 estimatedHours: 8,
 *                 category: 'backend',
 *                 linkedIssues: ['ISSUE-123', 'ISSUE-456']
 *             }
 *         }
 *     });
 * }
 *
 * // Listen for create events
 * composer.addEventListener('create', (e) => {
 *     const { data } = e.detail;
 *     // Save to backend API with all metadata
 *     await api.createItem({
 *         columnId: currentColumn.id,
 *         ...data
 *     });
 * });
 * </script>
 * ```
 *
 * @public
 */
let FlowBoardColumnItemComposerElement = class FlowBoardColumnItemComposerElement extends Themeable(Slottable(CustomElement)) {
    // #region Fields
    _composerController;
    _flowBoardBeforeItemCreate;
    _flowBoardItemCreate;
    _inheritance;
    // #endregion
    // #region Ctor
    /**
     * Constructs a new instance of the `FlowBoardColumnItemComposerElement` class.
     *
     * @public
     */
    constructor() {
        super();
        this._composerController = addFlowBoardComposerController(this);
        this._flowBoardBeforeItemCreate = new HTMLElementEventEmitter(this, 'flowBoardBeforeItemCreate');
        this._flowBoardItemCreate = new HTMLElementEventEmitter(this, 'flowBoardItemCreate');
        this._inheritance = addInheritanceConsumerController(this, {
            context: FLOW_BOARD_COLUMN_INHERITANCE_CONTEXT
        });
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `is` property.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-flow-board-column-item-composer';
    }
    /**
     * Gets or sets whether the composer form is open.
     *
     * @public
     * @attr
     */
    get open() {
        return this._composerController.open;
    }
    set open(value) {
        this._composerController.open = value;
    }
    /**
     * Gets the column key from the parent column (via inheritance).
     * Useful for identifying which column the item is being added to.
     *
     * @public
     * @readonly
     */
    get columnKey() {
        return this._inheritance.get('columnKey', '');
    }
    // #endregion
    // #region Methods
    /**
     * Creates a new item with the provided data.
     * Emits flowBoardBeforeItemCreate (cancelable) and flowBoardItemCreate events.
     *
     * @param data The data for the new item (completely user-defined)
     * @returns True if created, false if canceled
     *
     * @public
     */
    create(data) {
        const beforeDetail = {
            columnKey: this.columnKey,
            data,
            cancel: false
        };
        this._flowBoardBeforeItemCreate.emit(beforeDetail);
        if (beforeDetail.cancel) {
            return false;
        }
        const detail = {
            columnKey: this.columnKey,
            data
        };
        this._flowBoardItemCreate.emit(detail);
        // Close the composer
        this._composerController.close();
        return true;
    }
    /**
     * Toggles the composer between open and closed state.
     *
     * @public
     */
    toggle() {
        this._composerController.toggle();
    }
    /**
     * Closes the composer form.
     *
     * @public
     */
    close() {
        this._composerController.close();
    }
    /**
     * Handles keyboard events in the form.
     * Pressing Escape closes the form.
     *
     * @param evt - The keyboard event.
     *
     * @internal
     */
    handleFormKeydown(evt) {
        this._composerController.handleFormKeydown(evt);
    }
};
__decorate([
    Attribute({ type: Boolean }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], FlowBoardColumnItemComposerElement.prototype, "open", null);
FlowBoardColumnItemComposerElement = __decorate([
    Component({
        selector: 'mosaik-flow-board-column-item-composer',
        template: flowBoardColumnItemComposerElementTemplate,
        themes: {
            joy: flowBoardColumnItemComposerElementJoyStyle,
            cosmopolitan: flowBoardColumnItemComposerElementCosmopolitanStyle,
            memphis: flowBoardColumnItemComposerElementMemphisStyle
        },
        host: {
            slot: 'footer'
        },
        options: {
            mode: 'open',
            delegatesFocus: true
        }
    }),
    __metadata("design:paramtypes", [])
], FlowBoardColumnItemComposerElement);
export { FlowBoardColumnItemComposerElement };
//# sourceMappingURL=FlowBoardColumnItemComposerElement.js.map