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;
};
import { h, Host } from "@stencil/core";
import { PlatformServiceName, SelectCurrentLimeType, } from "@limetech/lime-web-components";
/**
 * This component generates the groups for `limebb-kanban`.
 *
 * @private
 */
export class KanbanGroup {
    constructor() {
        /**
         * List of items to display in the group.
         */
        this.items = [];
        this.handleLoadMore = (event) => {
            event.stopPropagation();
            this.loadMore.emit(this.identifier);
        };
    }
    render() {
        return (h(Host, { key: '7c08e70a3e4ea0641b3e556098ccaff818bf11c3' }, this.renderHelp(), this.renderGroupHeading(), this.renderGroupSummary(), this.renderItems()));
    }
    renderGroupSummary() {
        if (!this.summary || !this.totalCount) {
            return;
        }
        return h("limel-markdown", { class: "group-summary", value: this.summary });
    }
    renderGroupHeading() {
        return (h("limel-header", { heading: this.heading }, this.renderCounterBadge()));
    }
    renderHelp() {
        if (!this.help) {
            return;
        }
        return h("limel-help", { value: this.help });
    }
    renderSpinner() {
        if (this.loading) {
            return h("limel-spinner", { size: "small" });
        }
    }
    renderCounterBadge() {
        if (!this.totalCount) {
            return;
        }
        return [
            h("limel-badge", { slot: "actions", id: "badge-tooltip", label: this.totalCount }),
            this.renderTooltip(),
        ];
    }
    renderTooltip() {
        const genericLabel = this.translator.get('webclient.kanban.item-in-group', {
            count: this.totalCount,
        });
        const label = this.limetype ? this.labelWithLimetype() : genericLabel;
        return (h("limel-tooltip", { elementId: "badge-tooltip", label: label || '', openDirection: "top" }));
    }
    labelWithLimetype() {
        const plural = this.limetype.localname.plural;
        const singular = this.limetype.localname.singular;
        return this.translator.get('webclient.kanban.limetype-item-in-group', {
            limetype: this.totalCount > 1 ? plural : singular,
            count: this.totalCount,
        });
    }
    renderItems() {
        if (!this.loading && this.items.length === 0) {
            return;
        }
        return (h("div", { class: "items" }, this.renderKanbanItems(), this.renderSpinner(), this.renderLoadMore()));
    }
    renderKanbanItems() {
        return this.items.map((item) => {
            var _a, _b;
            const BodyComponent = (_a = item.bodyComponent) === null || _a === void 0 ? void 0 : _a.name;
            return (h("limebb-kanban-item", { tabindex: 0, platform: this.platform, context: this.context, item: item, key: item.id }, BodyComponent && (h(BodyComponent, Object.assign({ slot: "body", platform: this.platform, context: this.context }, (_b = item.bodyComponent) === null || _b === void 0 ? void 0 : _b.props)))));
        });
    }
    renderLoadMore() {
        if (this.loading || this.items.length >= this.totalCount) {
            return;
        }
        return (h("limel-icon-button", { class: "load-more-button", icon: "more", onClick: this.handleLoadMore, elevated: true, label: this.translator.get('webclient.load-more') }));
    }
    get translator() {
        return this.platform.get(PlatformServiceName.Translate);
    }
    static get is() { return "limebb-kanban-group"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["kanban-group.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["kanban-group.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": true,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "inheritdoc",
                            "text": undefined
                        }],
                    "text": "Reference to the platform service container.\n\nUse this to access all platform services like repositories, HTTP client,\ncommand bus, navigator, and more. The platform instance is shared across\nall components in the same application context."
                },
                "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": [{
                            "name": "inheritdoc",
                            "text": undefined
                        }],
                    "text": "The context describing where this component is running.\n\nThe context provides information about the current limetype and record ID\n(if viewing/editing a specific record). Components can use this to load\nrelevant data and understand their operating environment."
                },
                "getter": false,
                "setter": false
            },
            "identifier": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "A unique identifier for the group."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "identifier"
            },
            "heading": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The title of the group, which is taken from the\n`groupBy` property of the `limebb-kanban` component."
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "heading"
            },
            "help": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string | undefined",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Description of the group"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "help"
            },
            "items": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "KanbanItem[]",
                    "resolved": "KanbanItem[]",
                    "references": {
                        "KanbanItem": {
                            "location": "import",
                            "path": "../kanban-item/kanban-item.types",
                            "id": "src/components/kanban/kanban-item/kanban-item.types.ts::KanbanItem",
                            "referenceLocation": "KanbanItem"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "List of items to display in the group."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "[]"
            },
            "summary": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string | undefined",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The summary of the group."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "summary"
            },
            "loading": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "True if items have not finished loading."
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "loading"
            },
            "totalCount": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Total number of items available for the group.\nThis is used to determine if the \"load more\"\nbutton should be displayed."
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "total-count"
            }
        };
    }
    static get events() {
        return [{
                "method": "loadMore",
                "name": "loadMore",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted when the load more button is clicked"
                },
                "complexType": {
                    "original": "KanbanGroup['identifier']",
                    "resolved": "string",
                    "references": {
                        "KanbanGroup": {
                            "location": "global",
                            "id": "global::KanbanGroup"
                        }
                    }
                }
            }];
    }
}
__decorate([
    SelectCurrentLimeType()
], KanbanGroup.prototype, "limetype", void 0);
