{"version":3,"file":"restore-from-recycle-bin-modal.element-UlsZVqnD.js","sources":["../../../src/packages/core/recycle-bin/entity-action/restore-from-recycle-bin/modal/restore-from-recycle-bin-modal.element.ts"],"sourcesContent":["import type { UmbRecycleBinRepository } from '../../../recycle-bin-repository.interface.js';\nimport type {\n\tUmbRestoreFromRecycleBinModalData,\n\tUmbRestoreFromRecycleBinModalValue,\n} from './restore-from-recycle-bin-modal.token.js';\nimport type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit';\nimport { html, customElement, state, css } from '@umbraco-cms/backoffice/external/lit';\nimport { UmbTextStyles } from '@umbraco-cms/backoffice/style';\nimport { UMB_MODAL_MANAGER_CONTEXT, UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';\nimport { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry';\nimport type { UmbItemRepository } from '@umbraco-cms/backoffice/repository';\n\nconst elementName = 'umb-restore-from-recycle-bin-modal';\n\n@customElement(elementName)\nexport class UmbRestoreFromRecycleBinModalElement extends UmbModalBaseElement<\n\tUmbRestoreFromRecycleBinModalData,\n\tUmbRestoreFromRecycleBinModalValue\n> {\n\t@state()\n\t_isAutomaticRestore = false;\n\n\t@state()\n\t_restoreItem?: any;\n\n\t@state()\n\t_destinationItem?: any;\n\n\t#recycleBinRepository?: UmbRecycleBinRepository;\n\n\tprotected override async firstUpdated(\n\t\t_changedProperties: PropertyValueMap | Map,\n\t): Promise {\n\t\tsuper.firstUpdated(_changedProperties);\n\t\tif (!this.data?.unique) throw new Error('Cannot restore an item without a unique identifier.');\n\n\t\tthis._restoreItem = await this.#requestItem(this.data.unique);\n\t\tconst unique = await this.#requestAutomaticRestoreDestination();\n\n\t\tif (unique !== undefined) {\n\t\t\tthis.setDestination(unique);\n\t\t\tthis._isAutomaticRestore = true;\n\t\t}\n\t}\n\n\tasync setDestination(unique: string | null) {\n\t\t// TODO: handle ROOT lookup. Currently, we can't look up the root in the item repository.\n\t\t// This is a temp solution to show something in the UI.\n\t\tif (unique === null) {\n\t\t\tthis._destinationItem = {\n\t\t\t\tname: 'ROOT',\n\t\t\t};\n\n\t\t\tthis.#setDestinationValue({\n\t\t\t\tunique: null,\n\t\t\t\tentityType: 'unknown',\n\t\t\t});\n\t\t}\n\n\t\tif (unique) {\n\t\t\tthis._destinationItem = await this.#requestItem(unique);\n\t\t\tif (!this._destinationItem) throw new Error('Cant find destination item.');\n\n\t\t\tthis.#setDestinationValue({\n\t\t\t\tunique: this._destinationItem.unique,\n\t\t\t\tentityType: this._destinationItem.entityType,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync #requestAutomaticRestoreDestination(): Promise {\n\t\tif (!this.data?.unique) throw new Error('Cannot restore an item without a unique identifier.');\n\t\tif (!this.data?.recycleBinRepositoryAlias)\n\t\t\tthrow new Error('Cannot restore an item without a recycle bin repository alias.');\n\n\t\tthis.#recycleBinRepository = await createExtensionApiByAlias(\n\t\t\tthis,\n\t\t\tthis.data.recycleBinRepositoryAlias,\n\t\t);\n\n\t\tconst { data } = await this.#recycleBinRepository.requestOriginalParent({\n\t\t\tunique: this.data.unique,\n\t\t});\n\n\t\t// only check for undefined because data can be null if the parent is the root\n\t\tif (data !== undefined) {\n\t\t\treturn data ? data.unique : null;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tasync #requestItem(unique: string) {\n\t\tif (!this.data?.itemRepositoryAlias) throw new Error('Cannot restore an item without an item repository alias.');\n\n\t\tconst itemRepository = await createExtensionApiByAlias>(this, this.data.itemRepositoryAlias);\n\t\tconst { data } = await itemRepository.requestItems([unique]);\n\n\t\treturn data?.[0];\n\t}\n\n\tasync #onSelectCustomDestination() {\n\t\tif (!this.data?.pickerModal) throw new Error('Cannot select a destination without a picker modal.');\n\n\t\tconst modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);\n\t\tconst modal = modalManager.open(this, this.data.pickerModal, {\n\t\t\tdata: {\n\t\t\t\tmultiple: false,\n\t\t\t},\n\t\t});\n\n\t\tconst { selection } = await modal.onSubmit();\n\n\t\tif (selection.length > 0) {\n\t\t\tconst unique = selection[0];\n\t\t\tthis.setDestination(unique);\n\t\t}\n\t}\n\n\tasync #onSubmit() {\n\t\tif (!this.value.destination) throw new Error('Cannot restore an item without a destination.');\n\t\tif (!this.#recycleBinRepository) throw new Error('Cannot restore an item without a destination.');\n\t\tif (!this.data?.unique) throw new Error('Cannot restore an item without a unique identifier.');\n\n\t\tconst { error } = await this.#recycleBinRepository.requestRestore({\n\t\t\tunique: this.data.unique,\n\t\t\tdestination: { unique: this.value.destination.unique },\n\t\t});\n\n\t\tif (!error) {\n\t\t\tthis._submitModal();\n\t\t}\n\t}\n\n\t#setDestinationValue(destination: UmbRestoreFromRecycleBinModalValue['destination']) {\n\t\tthis.updateValue({ destination });\n\t}\n\n\toverride render() {\n\t\treturn html`\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t${this._isAutomaticRestore\n\t\t\t\t\t\t? html` Restore ${this._restoreItem?.name} to ${this._destinationItem?.name}`\n\t\t\t\t\t\t: this.#renderCustomSelectDestination()}\n\t\t\t\t\n\t\t\t\t${this.#renderActions()}\n\t\t\t\n\t\t`;\n\t}\n\n\t#renderCustomSelectDestination() {\n\t\treturn html`\n\t\t\t

Cannot automatically restore this item.

\n\t\t\t

There is no location where this item can be automatically restored. You can select a new location below.

\n\t\t\t
Restore to:
\n\t\t\t${this._destinationItem\n\t\t\t\t? html`\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t (this._destinationItem = undefined)} label=\"Remove\"\n\t\t\t\t\t\t\t\t>${this.localize.term('general_remove')}\n\t\t\t\t\t\t\n\t\t\t\t\t`\n\t\t\t\t: html` Select location`}\n\t\t`;\n\t}\n\n\t#renderActions() {\n\t\treturn html`\n\t\t\t\n\t\t\t\n\t\t`;\n\t}\n\n\tstatic override styles = [\n\t\tUmbTextStyles,\n\t\tcss`\n\t\t\t#placeholder {\n\t\t\t\twidth: 100%;\n\t\t\t}\n\t\t`,\n\t];\n}\n\nexport default UmbRestoreFromRecycleBinModalElement;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t[elementName]: UmbRestoreFromRecycleBinModalElement;\n\t}\n}\n"],"names":["_recycleBinRepository","_UmbRestoreFromRecycleBinModalElement_instances","requestAutomaticRestoreDestination_fn","requestItem_fn","onSelectCustomDestination_fn","onSubmit_fn","setDestinationValue_fn","renderCustomSelectDestination_fn","renderActions_fn","elementName","UmbRestoreFromRecycleBinModalElement","UmbModalBaseElement","__privateAdd","_changedProperties","__privateMethod","unique","html","__privateSet","createExtensionApiByAlias","data","__privateGet","itemRepository","modal","UMB_MODAL_MANAGER_CONTEXT","selection","error","destination","UmbTextStyles","css","__decorateClass","state","customElement","UmbRestoreFromRecycleBinModalElement$1"],"mappings":";;;;;;;;;;wYAAAA,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAYA,MAAMC,IAAc;AAGP,IAAAC,IAAN,cAAmDC,EAGxD;AAAA,EAHK,cAAA;AAAA,UAAA,GAAA,SAAA,GAAAC,EAAA,MAAAX,CAAA,GAKgB,KAAA,sBAAA,IAQtBW,EAAA,MAAAZ,CAAA;AAAA,EAAA;AAAA,EAEA,MAAyB,aACxBa,GACgB;AAEhB,QADA,MAAM,aAAaA,CAAkB,GACjC,CAAC,KAAK,MAAM,OAAc,OAAA,IAAI,MAAM,qDAAqD;AAE7F,SAAK,eAAe,MAAMC,EAAA,MAAKb,GAALE,CAAA,EAAA,KAAA,MAAkB,KAAK,KAAK,MAAA;AAChD,UAAAY,IAAS,MAAMD,EAAA,MAAKb,GAALC,CAAA,EAAA,KAAA,IAAA;AAErB,IAAIa,MAAW,WACd,KAAK,eAAeA,CAAM,GAC1B,KAAK,sBAAsB;AAAA,EAE7B;AAAA,EAEA,MAAM,eAAeA,GAAuB;AAc3C,QAXIA,MAAW,SACd,KAAK,mBAAmB;AAAA,MACvB,MAAM;AAAA,IAAA,GAGPD,EAAA,MAAKb,MAAL,KAA0B,MAAA;A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