{"version":3,"file":"workspace-variant-menu-breadcrumb.element-DctKfTVh.js","sources":["../../../src/packages/core/workspace/components/workspace-breadcrumb/workspace-variant-menu-breadcrumb/workspace-variant-menu-breadcrumb.element.ts"],"sourcesContent":["import { css, customElement, html, ifDefined, state } from '@umbraco-cms/backoffice/external/lit';\nimport { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';\nimport { UmbTextStyles } from '@umbraco-cms/backoffice/style';\nimport { UmbVariantId } from '@umbraco-cms/backoffice/variant';\nimport { UMB_APP_LANGUAGE_CONTEXT } from '@umbraco-cms/backoffice/language';\nimport { UMB_SECTION_CONTEXT } from '@umbraco-cms/backoffice/section';\nimport { UMB_VARIANT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace';\nimport type { UmbAppLanguageContext } from '@umbraco-cms/backoffice/language';\nimport type { UmbVariantDatasetWorkspaceContext } from '@umbraco-cms/backoffice/workspace';\nimport type { UmbVariantStructureItemModel } from '@umbraco-cms/backoffice/menu';\n\n@customElement('umb-workspace-variant-menu-breadcrumb')\nexport class UmbWorkspaceVariantMenuBreadcrumbElement extends UmbLitElement {\n\t@state()\n\t_name: string = '';\n\n\t@state()\n\t_structure: Array = [];\n\n\t@state()\n\t_workspaceActiveVariantId?: UmbVariantId;\n\n\t@state()\n\t_appDefaultCulture?: string;\n\n\t#sectionContext?: typeof UMB_SECTION_CONTEXT.TYPE;\n\t#workspaceContext?: UmbVariantDatasetWorkspaceContext;\n\t#appLanguageContext?: UmbAppLanguageContext;\n\t#structureContext?: any;\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis.consumeContext(UMB_APP_LANGUAGE_CONTEXT, (instance) => {\n\t\t\tthis.#appLanguageContext = instance;\n\t\t\tthis.#observeDefaultCulture();\n\t\t});\n\n\t\tthis.consumeContext(UMB_SECTION_CONTEXT, (instance) => {\n\t\t\tthis.#sectionContext = instance;\n\t\t});\n\n\t\tthis.consumeContext(UMB_VARIANT_WORKSPACE_CONTEXT, (instance) => {\n\t\t\tif (!instance) return;\n\t\t\tthis.#workspaceContext = instance;\n\t\t\tthis.#observeWorkspaceActiveVariant();\n\t\t\tthis.#observeStructure();\n\t\t});\n\n\t\t// TODO: set up context token\n\t\tthis.consumeContext('UmbMenuStructureWorkspaceContext', (instance) => {\n\t\t\tif (!instance) return;\n\t\t\tthis.#structureContext = instance;\n\t\t\tthis.#observeStructure();\n\t\t});\n\t}\n\n\t#observeStructure() {\n\t\tif (!this.#structureContext || !this.#workspaceContext) return;\n\t\tconst isNew = this.#workspaceContext.getIsNew();\n\n\t\tthis.observe(this.#structureContext.structure, (value) => {\n\t\t\t// TODO: get the type from the context\n\t\t\tconst structure = value as Array;\n\t\t\tthis._structure = isNew ? structure : structure.slice(0, -1);\n\t\t});\n\t}\n\n\t#observeDefaultCulture() {\n\t\tthis.observe(this.#appLanguageContext!.appDefaultLanguage, (value) => {\n\t\t\tthis._appDefaultCulture = value?.unique;\n\t\t});\n\t}\n\n\t#observeWorkspaceActiveVariant() {\n\t\tthis.observe(\n\t\t\tthis.#workspaceContext?.splitView.activeVariantsInfo,\n\t\t\t(value) => {\n\t\t\t\tif (!value) return;\n\t\t\t\tthis._workspaceActiveVariantId = UmbVariantId.Create(value[0]);\n\t\t\t\tthis.#observeActiveVariantName();\n\t\t\t},\n\n\t\t\t'breadcrumbWorkspaceActiveVariantObserver',\n\t\t);\n\t}\n\n\t#observeActiveVariantName() {\n\t\tthis.observe(\n\t\t\tthis.#workspaceContext?.name(this._workspaceActiveVariantId),\n\t\t\t(value) => (this._name = value || ''),\n\t\t\t'breadcrumbWorkspaceNameObserver',\n\t\t);\n\t}\n\n\t// TODO: we should move the fallback name logic to a helper class. It will be used in multiple places\n\t#getItemVariantName(structureItem: UmbVariantStructureItemModel) {\n\t\tconst fallbackName =\n\t\t\tstructureItem.variants.find((variant) => variant.culture === this._appDefaultCulture)?.name ??\n\t\t\tstructureItem.variants[0].name ??\n\t\t\t'Unknown';\n\t\tconst name = structureItem.variants.find((variant) => this._workspaceActiveVariantId?.compare(variant))?.name;\n\t\treturn name ?? `(${fallbackName})`;\n\t}\n\n\t#getHref(structureItem: any) {\n\t\tconst workspaceBasePath = `section/${this.#sectionContext?.getPathname()}/workspace/${structureItem.entityType}/edit`;\n\t\treturn structureItem.isFolder\n\t\t\t? undefined\n\t\t\t: `${workspaceBasePath}/${structureItem.unique}/${this._workspaceActiveVariantId?.culture}`;\n\t}\n\n\toverride render() {\n\t\treturn html`\n\t\t\t\n\t\t\t\t${this._structure.map(\n\t\t\t\t\t(structureItem) =>\n\t\t\t\t\t\thtml`${this.localize.string(this.#getItemVariantName(structureItem))}`,\n\t\t\t\t)}\n\t\t\t\t${this._name}\n\t\t\t\n\t\t`;\n\t}\n\n\tstatic override styles = [\n\t\tUmbTextStyles,\n\t\tcss`\n\t\t\t:host {\n\t\t\t\t/* TODO: This is a temp solution to handle an issue where long nested breadcrumbs would hide workspace actions */\n\t\t\t\toverflow: hidden;\n\t\t\t\tdisplay: flex;\n\t\t\t\tflex-direction: row-reverse;\n\t\t\t\tmargin-left: var(--uui-size-layout-1);\n\t\t\t}\n\t\t`,\n\t];\n}\n\nexport default UmbWorkspaceVariantMenuBreadcrumbElement;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'umb-workspace-variant-menu-breadcrumb': UmbWorkspaceVariantMenuBreadcrumbElement;\n\t}\n}\n"],"names":["_sectionContext","_workspaceContext","_appLanguageContext","_structureContext","_UmbWorkspaceVariantMenuBreadcrumbElement_instances","observeStructure_fn","observeDefaultCulture_fn","observeWorkspaceActiveVariant_fn","observeActiveVariantName_fn","getItemVariantName_fn","getHref_fn","UmbWorkspaceVariantMenuBreadcrumbElement","UmbLitElement","__privateAdd","UMB_APP_LANGUAGE_CONTEXT","instance","__privateSet","__privateMethod","UMB_SECTION_CONTEXT","UMB_VARIANT_WORKSPACE_CONTEXT","html","structureItem","ifDefined","__privateGet","isNew","value","structure","UmbVariantId","fallbackName","variant","workspaceBasePath","UmbTextStyles","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