import { PlatformServiceName, } from "@limetech/lime-web-components";
import { h } from "@stencil/core";
import { LimeWebComponentTemplate } from "../../../util/web-component-template";
/**
 * Popover content for a rule-editor chip. Carries its own styles so
 * they travel with the element when `limel-popover` portals it out of
 * the rule-editor's shadow DOM.
 *
 * @private
 */
export class RuleChipPopover {
    constructor() {
        this.isNegated = false;
        this.readonly = false;
        this.disabled = false;
        this.isMutable = true;
        this.handleNegateChange = (event) => {
            event.stopPropagation();
            this.negate.emit(event.detail);
        };
        this.handleArgsChange = (event) => {
            event.stopPropagation();
            this.updateArgs.emit(event.detail);
        };
        this.handleDelete = () => {
            this.deleteChip.emit();
        };
    }
    render() {
        return (h("div", { key: '6aae573b524737ee3d2a4b2d3df68ec9bf1f1a0f', class: "popover" }, this.renderHeader(), this.renderBody()));
    }
    renderHeader() {
        var _a, _b, _c, _d;
        const title = ((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.title)
            ? this.translator.get(this.metadata.title)
            : ((_c = (_b = this.refNode) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '');
        return (h("limel-header", { class: "popover__header is-narrow", heading: title, icon: (_d = this.metadata) === null || _d === void 0 ? void 0 : _d.icon }, this.renderHeaderActions()));
    }
    renderHeaderActions() {
        if (!this.isMutable) {
            return null;
        }
        return (h("div", { slot: "actions", class: "popover__header-actions" }, h("limel-switch", { class: "popover__negate-switch", label: this.translator.get('webclient.rule-editor.negate'), value: this.isNegated, onChange: this.handleNegateChange }), h("limel-icon-button", { class: "popover__delete-button", icon: "trash", label: this.translator.get('webclient.rule-editor.delete'), onClick: this.handleDelete })));
    }
    get translator() {
        return this.platform.get(PlatformServiceName.Translate);
    }
    renderBody() {
        var _a, _b;
        const configComponent = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.configComponent;
        if (!configComponent) {
            return null;
        }
        return (h("div", { class: "popover__body" }, h(LimeWebComponentTemplate, { platform: this.platform, context: this.context, name: configComponent.name, props: Object.assign(Object.assign({}, configComponent.props), { value: (_b = this.refNode) === null || _b === void 0 ? void 0 : _b.args, readonly: this.readonly, disabled: this.disabled, onChange: this.handleArgsChange }) })));
    }
    static get is() { return "limebb-rule-chip-popover"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["rule-chip-popover.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["rule-chip-popover.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": ""
                },
                "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": ""
                },
                "getter": false,
                "setter": false
            },
            "refNode": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "RuleRef",
                    "resolved": "RuleRef",
                    "references": {
                        "RuleRef": {
                            "location": "import",
                            "path": "@limetech/lime-web-components",
                            "id": "node_modules::RuleRef",
                            "referenceLocation": "RuleRef"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "isNegated": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "is-negated",
                "defaultValue": "false"
            },
            "metadata": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "PrimitiveMetadata",
                    "resolved": "ConfigMetadata & { id: string; reads: readonly (keyof ContextMap)[]; } | undefined",
                    "references": {
                        "PrimitiveMetadata": {
                            "location": "import",
                            "path": "@limetech/lime-web-components",
                            "id": "node_modules::PrimitiveMetadata",
                            "referenceLocation": "PrimitiveMetadata"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "readonly": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "readonly",
                "defaultValue": "false"
            },
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "disabled",
                "defaultValue": "false"
            },
            "isMutable": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "is-mutable",
                "defaultValue": "true"
            }
        };
    }
    static get events() {
        return [{
                "method": "negate",
                "name": "negate",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                }
            }, {
                "method": "updateArgs",
                "name": "updateArgs",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "JsonValue",
                    "resolved": "JsonValue[] | boolean | null | number | string | { [key: string]: JsonValue; }",
                    "references": {
                        "JsonValue": {
                            "location": "import",
                            "path": "@limetech/lime-web-components",
                            "id": "node_modules::JsonValue",
                            "referenceLocation": "JsonValue"
                        }
                    }
                }
            }, {
                "method": "deleteChip",
                "name": "deleteChip",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "void",
                    "resolved": "void",
                    "references": {}
                }
            }];
    }
}
