var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _GxIdeDetailsAcknowledgements_getFormatedDate, _GxIdeDetailsAcknowledgements_renderLicenseInfo, _GxIdeDetailsAcknowledgements_renderLicensesViewButtons, _GxIdeDetailsAcknowledgements_getLicenseId, _GxIdeDetailsAcknowledgements_viewLicenseClickedHandler, _GxIdeDetailsAcknowledgements_openLinkClickedHandler;
import { Host, h, getAssetPath } from "@stencil/core";
import { getIconPath } from "@genexus/mercury";
import { Locale } from "../../common/locale";
const OPEN_WINDOW_ICON = getIconPath({
    category: "gemini-tools",
    name: "open-window",
    colorType: "primary"
});
const IMAGES_PATH = "./gx-ide-assets/details-acknowledgements/images";
const BACKGROUND_SIZE = "300px";
const GENEXUS_NEXT_LOGO_SRC = getAssetPath(`${IMAGES_PATH}/genexus-next-logo.svg`);
const BG_IMAGE_TOP_START = getAssetPath(`${IMAGES_PATH}/top-start.svg`);
const BG_IMAGE_BOTTOM_START = getAssetPath(`${IMAGES_PATH}/bottom-start.svg`);
const BG_IMAGE_BOTTOM_END = getAssetPath(`${IMAGES_PATH}/bottom-end.svg`);
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/typography",
    "utils/elevation",
    "components/button",
    "components/icon",
    "chameleon/scrollbar"
];
export class GxIdeDetailsAcknowledgements {
    constructor() {
        _GxIdeDetailsAcknowledgements_getFormatedDate.set(this, (date) => {
            return date === null || date === void 0 ? void 0 : date.toISOString().split("T")[0];
        });
        _GxIdeDetailsAcknowledgements_renderLicenseInfo.set(this, (license, type = "name", packageData) => {
            const licenseId = __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_getLicenseId, "f").call(this, packageData, license.name);
            const showDescription = licenseId === this.expandedLicenseId;
            return type === "name" ? (h("ul", { class: "licenses-names-list" }, h("li", { class: "body-regular-m licenses-names-item" }, license.name))) : (h("ul", { class: "licenses-descriptions-list" }, h("li", { class: "licenses-descriptions-item", key: license.name }, showDescription ? (h("p", { class: "code-box color-neutral licenses-descriptions-description scrollable" }, license.description)) : null)));
        });
        _GxIdeDetailsAcknowledgements_renderLicensesViewButtons.set(this, (license, packageData) => {
            const licenseId = __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_getLicenseId, "f").call(this, packageData, license.name);
            const visibleLicenseButton = licenseId === this.expandedLicenseId;
            const viewLicenseButtonLabel = visibleLicenseButton
                ? this._componentLocale.detailsCard.hide
                : this._componentLocale.detailsCard.show;
            return (h("div", { class: "licenses-buttons-container buttons-spacer" }, h("button", { class: {
                    "button-icon-and-text": true,
                    "button-primary": !visibleLicenseButton,
                    "button-secondary": visibleLicenseButton,
                    "show-more-button": true
                }, onClick: __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_viewLicenseClickedHandler, "f").call(this, licenseId) }, viewLicenseButtonLabel)));
        });
        _GxIdeDetailsAcknowledgements_getLicenseId.set(this, (packageData, licenseName) => {
            return `${packageData.packageName}-${packageData.packageVersion}-${licenseName}`;
        });
        _GxIdeDetailsAcknowledgements_viewLicenseClickedHandler.set(this, (licenseId) => () => {
            if (licenseId === this.expandedLicenseId) {
                // collapse
                this.expandedLicenseId = undefined;
            }
            else {
                // expand collapse
                this.expandedLicenseId = licenseId;
            }
        });
        _GxIdeDetailsAcknowledgements_openLinkClickedHandler.set(this, (url) => (e) => {
            if (this.openPackageUrlCallback) {
                e.preventDefault();
                this.openPackageUrlCallback(url);
            }
        });
        this.expandedLicenseId = undefined;
        this.dateGenerated = undefined;
        this.release = undefined;
        this.packages = undefined;
        this.openPackageUrlCallback = undefined;
    }
    async componentWillLoad() {
        this._componentLocale = await Locale.getComponentStrings(this.el);
    }
    render() {
        var _a;
        const formatedDate = __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_getFormatedDate, "f").call(this, this.dateGenerated);
        return (h(Host, { class: "scrollable", style: {
                backgroundImage: `url(${BG_IMAGE_TOP_START}), url(${BG_IMAGE_BOTTOM_START}), url(${BG_IMAGE_BOTTOM_END})`,
                backgroundPosition: "left top, left bottom, right bottom",
                backgroundRepeat: "no-repeat, no-repeat, no-repeat",
                backgroundSize: `${BACKGROUND_SIZE}, ${BACKGROUND_SIZE}, ${BACKGROUND_SIZE}`
            } }, h("ch-theme", { model: CSS_BUNDLES }), h("div", { class: "main-wrapper" }, h("div", { style: {
                mask: `url(${GENEXUS_NEXT_LOGO_SRC}) no-repeat center`
            }, class: "logo" }), h("div", { class: "card card-details elevation-1" }, h("div", { class: "intro-container" }, h("h1", { class: "title heading-3" }, this._componentLocale.detailsCard.title), h("p", { class: "body-regular-m" }, this._componentLocale.detailsCard.mainDescription), h("p", { class: "color-neutral body-italic-s" }, this._componentLocale.detailsCard.secondaryDescription)), h("hr", null), h("div", { class: "date-container" }, h("p", { class: "color-neutral" }, this._componentLocale.detailsCard.dateGenerated), h("time", { dateTime: formatedDate }, formatedDate))), (_a = this.packages) === null || _a === void 0 ? void 0 :
            _a.map(packageItem => {
                let packageName = `${packageItem.packageName} ${packageItem.packageVersion}`;
                const headingContent = packageItem.packageURL ? (h("a", { href: packageItem.packageURL, target: "_blank", onClick: __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_openLinkClickedHandler, "f").call(this, packageItem.packageURL), class: "package-link" }, packageName, h("ch-image", { src: OPEN_WINDOW_ICON, class: "package-icon icon-s" }))) : (packageName);
                return (h("article", { class: "card card-package elevation-1" }, h("h2", { class: {
                        "subtitle-semi-bold-s": true,
                        "package-name": true,
                        "has-link": !!packageItem.packageURL
                    } }, headingContent), h("p", { class: "subtitle-semi-bold-s" }, this._componentLocale.packageCard.declaredLicenses), __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_renderLicenseInfo, "f").call(this, packageItem.declaredLicense, "name", packageItem), __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_renderLicenseInfo, "f").call(this, packageItem.declaredLicense, "description", packageItem), __classPrivateFieldGet(this, _GxIdeDetailsAcknowledgements_renderLicensesViewButtons, "f").call(this, packageItem.declaredLicense, packageItem)));
            }))));
    }
    static get is() { return "gx-ide-details-acknowledgements"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["details-acknowledgements.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["details-acknowledgements.css"]
        };
    }
    static get assetsDirs() { return ["gx-ide-assets/details-acknowledgements"]; }
    static get properties() {
        return {
            "dateGenerated": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Date",
                    "resolved": "Date",
                    "references": {
                        "Date": {
                            "location": "global",
                            "id": "global::Date"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The date when the current release was published"
                }
            },
            "release": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "The version of the current release"
                },
                "attribute": "release",
                "reflect": false
            },
            "packages": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "PackageData[]",
                    "resolved": "PackageData[]",
                    "references": {
                        "PackageData": {
                            "location": "import",
                            "path": "./types",
                            "id": "src/components/details-acknowledgements/types.d.ts::PackageData"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The list of packages that the current release contains"
                }
            },
            "openPackageUrlCallback": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "OpenPackageURLCallback",
                    "resolved": "(url: string) => Promise<void>",
                    "references": {
                        "OpenPackageURLCallback": {
                            "location": "import",
                            "path": "./types",
                            "id": "src/components/details-acknowledgements/types.d.ts::OpenPackageURLCallback"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Callback invoked when the user clicks a package with a packageURL.\nIf openPackageUrlCallback is defined, the default link action is\nprevented and the URL is passed to the host via the callback.\nOtherwise, the link opens in a new tab as usual."
                }
            }
        };
    }
    static get states() {
        return {
            "expandedLicenseId": {}
        };
    }
    static get elementRef() { return "el"; }
}
_GxIdeDetailsAcknowledgements_getFormatedDate = new WeakMap(), _GxIdeDetailsAcknowledgements_renderLicenseInfo = new WeakMap(), _GxIdeDetailsAcknowledgements_renderLicensesViewButtons = new WeakMap(), _GxIdeDetailsAcknowledgements_getLicenseId = new WeakMap(), _GxIdeDetailsAcknowledgements_viewLicenseClickedHandler = new WeakMap(), _GxIdeDetailsAcknowledgements_openLinkClickedHandler = new WeakMap();
//# sourceMappingURL=details-acknowledgements.js.map
