import { h, Host } from "@stencil/core";
/**
 * Order By Item Component
 *
 * Represents a single order by specification with property selection and direction toggle
 * Part of the order by editor
 * @private
 */
export class OrderByItemComponent {
    constructor() {
        this.handlePathChange = (event) => {
            event.stopPropagation();
            const newPath = event.detail;
            if (!newPath) {
                // If path is cleared, keep the current item but with empty path
                const currentDirection = this.item[Object.keys(this.item)[0]] || 'ASC';
                this.itemChange.emit({ '': currentDirection });
                return;
            }
            // Get current direction
            const currentPath = Object.keys(this.item)[0];
            const currentDirection = this.item[currentPath] || 'ASC';
            // Create new item with new path but same direction
            const newItem = { [newPath]: currentDirection };
            this.itemChange.emit(newItem);
        };
        this.handleToggleDirection = () => {
            const propertyPath = Object.keys(this.item)[0] || '';
            const currentDirection = this.item[propertyPath] || 'ASC';
            const newDirection = currentDirection === 'ASC' ? 'DESC' : 'ASC';
            const newItem = { [propertyPath]: newDirection };
            this.itemChange.emit(newItem);
        };
        this.handleRemove = () => {
            this.itemChange.emit(null);
        };
    }
    render() {
        const propertyPath = Object.keys(this.item)[0] || '';
        const direction = this.item[propertyPath] || 'ASC';
        return (h(Host, { key: '77f58753af7831ffe97728cdbc5b03ac68a47773' }, h("limebb-property-selector", { key: '5d4c27d2f81ea7f1260298e16a52f9670d9fc641', platform: this.platform, context: this.context, limetype: this.limetype, label: "Property", value: propertyPath, required: true, onChange: this.handlePathChange }), h("div", { key: '7e8ad17d20935c423f4d48d49761008622030ea3', class: "control-buttons" }, h("limel-icon-button", { key: 'c9f1b7cc8e6bc28bc1b61205a9ed791a7bd19403', icon: direction === 'ASC'
                ? 'sort_ascending'
                : 'sort_descending', label: direction === 'ASC' ? 'Ascending' : 'Descending', onClick: this.handleToggleDirection }), h("limel-icon-button", { key: '42b34e92359a662bce151c4daa300fc79d2fcbbb', icon: "trash", label: "Remove", onClick: this.handleRemove }))));
    }
    static get is() { return "limebb-lime-query-order-by-item"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["order-by-item.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["order-by-item.css"]
        };
    }
    static get properties() {
        return {
            "platform": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "LimeWebComponentPlatform",
                    "resolved": "LimeWebComponentPlatform",
                    "references": {
                        "LimeWebComponentPlatform": {
                            "location": "import",
                            "path": "@limetech/lime-web-components",
                            "id": "node_modules::LimeWebComponentPlatform",
                            "referenceLocation": "LimeWebComponentPlatform"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Platform service provider"
                },
                "getter": false,
                "setter": false
            },
            "context": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "LimeWebComponentContext",
                    "resolved": "LimeWebComponentContext",
                    "references": {
                        "LimeWebComponentContext": {
                            "location": "import",
                            "path": "@limetech/lime-web-components",
                            "id": "node_modules::LimeWebComponentContext",
                            "referenceLocation": "LimeWebComponentContext"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Component context"
                },
                "getter": false,
                "setter": false
            },
            "limetype": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The limetype to select properties from"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "limetype"
            },
            "item": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "OrderByItem",
                    "resolved": "{ [propertyPath: string]: \"ASC\" | \"DESC\"; }",
                    "references": {
                        "OrderByItem": {
                            "location": "import",
                            "path": "../lime-query.types",
                            "id": "src/components/lime-query-builder/lime-query.types.ts::OrderByItem",
                            "referenceLocation": "OrderByItem"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The order by item (e.g., { \"company.name\": \"ASC\" })"
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get events() {
        return [{
                "method": "itemChange",
                "name": "itemChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted when the item changes or should be removed"
                },
                "complexType": {
                    "original": "OrderByItem | null",
                    "resolved": "null | { [propertyPath: string]: \"ASC\" | \"DESC\"; }",
                    "references": {
                        "OrderByItem": {
                            "location": "import",
                            "path": "../lime-query.types",
                            "id": "src/components/lime-query-builder/lime-query.types.ts::OrderByItem",
                            "referenceLocation": "OrderByItem"
                        }
                    }
                }
            }];
    }
}
