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: 'f8b1d7505feec325eae8668672afe3768a4892aa' }, h("limebb-property-selector", { key: '03f71edd8692c6a46612f87a9df21aabd2bf71eb', platform: this.platform, context: this.context, limetype: this.limetype, label: "Property", value: propertyPath, required: true, onChange: this.handlePathChange }), h("div", { key: 'a1a6db7060f8dc862d7acfb5750861293e2411d3', class: "control-buttons" }, h("limel-icon-button", { key: '76703911899c38d71f116dc8256d00cb7c937971', icon: direction === 'ASC'
                ? 'sort_ascending'
                : 'sort_descending', label: direction === 'ASC' ? 'Ascending' : 'Descending', onClick: this.handleToggleDirection }), h("limel-icon-button", { key: '91a3370d5c6151370b96e7b67d59f226ad526f21', 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"
                        }
                    }
                }
            }];
    }
}
