import { __esDecorate, __runInitializers } from "tslib";
import { html } from 'lit';
import { state } from 'lit/decorators.js';
import { LitElement } from 'lit';
import { classMap } from 'lit/directives/class-map.js';
let DomainAutoFieldsDialog = (() => {
    let _classSuper = LitElement;
    let _selectedFields_decorators;
    let _selectedFields_initializers = [];
    let _selectedFields_extraInitializers = [];
    return class DomainAutoFieldsDialog extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _selectedFields_decorators = [state()];
            __esDecorate(this, null, _selectedFields_decorators, { kind: "accessor", name: "selectedFields", static: false, private: false, access: { has: obj => "selectedFields" in obj, get: obj => obj.selectedFields, set: (obj, value) => { obj.selectedFields = value; } }, metadata: _metadata }, _selectedFields_initializers, _selectedFields_extraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #selectedFields_accessor_storage = __runInitializers(this, _selectedFields_initializers, new Set()
        /**
         * The auto field categories and definitions
         */
        );
        /**
         * The currently selected field IDs
         */
        get selectedFields() { return this.#selectedFields_accessor_storage; }
        set selectedFields(value) { this.#selectedFields_accessor_storage = value; }
        /**
         * The auto field categories and definitions
         */
        categories = (__runInitializers(this, _selectedFields_extraInitializers), [
            {
                name: 'Core Fields',
                fields: [
                    {
                        id: 'id',
                        name: 'Identifier',
                        description: 'The unique ID for each record.',
                    },
                    {
                        id: 'name',
                        name: 'Name',
                        description: 'A human-readable name for the record.',
                    },
                    {
                        id: 'description',
                        name: 'Description',
                        description: 'A detailed description of the record.',
                    },
                    {
                        id: 'public-unique-name',
                        name: 'Public Unique Name (Slug)',
                        description: 'A URL-friendly unique identifier (e.g., "my-product").',
                    },
                ],
            },
            {
                name: 'User Information',
                fields: [
                    {
                        id: 'email',
                        name: 'Email Address',
                        description: 'Email address with verification support.',
                    },
                    {
                        id: 'first-name',
                        name: 'First Name',
                        description: 'The first name of a person.',
                    },
                    {
                        id: 'last-name',
                        name: 'Last Name',
                        description: 'The last name of a person.',
                    },
                    {
                        id: 'phone',
                        name: 'Phone Number',
                        description: 'Phone number with international format support.',
                    },
                    {
                        id: 'avatar-url',
                        name: 'Avatar URL',
                        description: 'URL to a profile picture or avatar image.',
                    },
                ],
            },
            {
                name: 'Lifecycle & Status',
                fields: [
                    {
                        id: 'status',
                        name: 'Status',
                        description: 'The current state of the record (e.g., Active, Draft, Archived).',
                    },
                    {
                        id: 'version',
                        name: 'Version Number',
                        description: 'Tracks changes to prevent editing conflicts.',
                    },
                    {
                        id: 'owner',
                        name: 'Owner',
                        description: 'Reference to the user or team that owns this record.',
                    },
                ],
            },
            {
                name: 'E-commerce',
                fields: [
                    {
                        id: 'price',
                        name: 'Price',
                        description: 'Product price with currency support.',
                    },
                    {
                        id: 'unit-price',
                        name: 'Unit Price',
                        description: 'Price per unit with currency support.',
                    },
                    {
                        id: 'sku',
                        name: 'SKU',
                        description: 'Stock Keeping Unit - unique product identifier.',
                    },
                    {
                        id: 'quantity',
                        name: 'Quantity',
                        description: 'Available quantity or stock amount.',
                    },
                    {
                        id: 'weight',
                        name: 'Weight',
                        description: 'Physical weight of the item.',
                    },
                    {
                        id: 'images',
                        name: 'Images',
                        description: 'Multiple image URLs for the product.',
                    },
                ],
            },
            {
                name: 'Session & Security',
                fields: [
                    {
                        id: 'session-id',
                        name: 'Session ID',
                        description: 'Unique identifier for user sessions.',
                    },
                    {
                        id: 'expires-at',
                        name: 'Expires At',
                        description: 'When a session or token expires.',
                    },
                ],
            },
            {
                name: 'Audit Trail',
                fields: [
                    {
                        id: 'created',
                        name: 'Created At',
                        description: 'The date and time when the record was created.',
                    },
                    {
                        id: 'updated',
                        name: 'Updated At',
                        description: 'The date and time when the record was last updated.',
                    },
                    {
                        id: 'updated-by',
                        name: 'Updated By',
                        description: 'Reference to the user who last updated the record.',
                    },
                ],
            },
            {
                name: 'Soft Delete',
                fields: [
                    {
                        id: 'is-deleted',
                        name: 'Is Deleted',
                        description: 'A true/false flag indicating if the record is deleted.',
                    },
                    {
                        id: 'deleted',
                        name: 'Deleted At',
                        description: 'The date and time when the record was deleted.',
                    },
                ],
            },
        ]);
        /**
         * Resets the selection
         */
        reset() {
            this.selectedFields.clear();
            this.requestUpdate();
        }
        /**
         * Handles field selection toggle
         */
        handleFieldToggle(fieldId) {
            if (this.selectedFields.has(fieldId)) {
                this.selectedFields.delete(fieldId);
            }
            else {
                this.selectedFields.add(fieldId);
            }
            this.requestUpdate();
        }
        handleFieldSelect(e) {
            const { item } = e.detail;
            const { id } = item.dataset;
            if (!id)
                return;
            this.handleFieldToggle(id);
        }
        /**
         * Handles the Add Selected button click
         */
        handleAddSelected() {
            const result = {
                selectedFields: Array.from(this.selectedFields),
            };
            this.dispatchEvent(new CustomEvent('select', { detail: result }));
        }
        /**
         * Handles the Cancel button click
         */
        handleCancel() {
            this.dispatchEvent(new CustomEvent('cancel'));
        }
        render() {
            const selectedCount = this.selectedFields.size;
            return html `
      <ui-list class="list" @select="${this.handleFieldSelect}"
        >${this.categories.map((category) => this.renderCategory(category))}</ui-list
      >

      <div class="dialog-actions">
        <ui-button type="button" @click="${this.handleCancel}" class="cancel">Cancel</ui-button>
        <ui-button
          type="button"
          class="save"
          color="filled"
          ?disabled="${selectedCount === 0}"
          @click="${this.handleAddSelected}"
        >
          Add Selected (${selectedCount})
        </ui-button>
      </div>
    `;
        }
        /**
         * Renders a category section
         */
        renderCategory(category) {
            return html `
      <div class="category-title title-medium">${category.name}</div>
      ${category.fields.map((field) => this.renderField(field))}
    `;
        }
        /**
         * Renders a field item
         */
        renderField(field) {
            const isSelected = this.selectedFields.has(field.id);
            const classes = {
                'field-item': true,
                'selected': isSelected,
            };
            return html `
      <ui-list-item image="avatar" data-id="${field.id}" class="${classMap(classes)}" lines="two">
        <ui-checkbox slot="start" .checked="${isSelected}"></ui-checkbox>
        <div class="label">${field.name}</div>
        <div slot="supporting-text">${field.description}</div>
      </ui-list-item>
    `;
        }
    };
})();
/**
 * A component for selecting "auto fields" to add to an entity.
 *
 * @fires select - Dispatched when fields are selected with AutoFieldsSelectionResult detail
 * @fires cancel - Dispatched when the user cancels the selection
 */
export default DomainAutoFieldsDialog;
//# sourceMappingURL=DomainAutoFieldsDialog.js.map