{"version":3,"file":"rename-server-file-modal.element-BADtV52y.js","sources":["../../../src/packages/core/server-file-system/rename/modal/rename-server-file-modal.element.ts"],"sourcesContent":["import type { UmbRenameServerFileRepository } from '../types.js';\nimport type { UmbRenameModalData, UmbRenameServerFileModalValue } from './rename-server-file-modal.token.js';\nimport type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit';\nimport { html, customElement, css, state } from '@umbraco-cms/backoffice/external/lit';\nimport { UmbTextStyles } from '@umbraco-cms/backoffice/style';\nimport { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';\nimport { UmbExtensionApiInitializer } from '@umbraco-cms/backoffice/extension-api';\nimport { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';\nimport type { UmbItemRepository } from '@umbraco-cms/backoffice/repository';\n\n@customElement('umb-rename-modal')\nexport class UmbRenameModalElement extends UmbModalBaseElement {\n\t// TODO: make base type for item and detail models\n\t#itemRepository?: UmbItemRepository;\n\t#renameRepository?: UmbRenameServerFileRepository;\n\t#init?: Promise;\n\n\t@state()\n\t_name = '';\n\n\toverride connectedCallback(): void {\n\t\tsuper.connectedCallback();\n\t\tthis.#observeRepository();\n\t}\n\n\t#observeRepository() {\n\t\tif (!this.data?.renameRepositoryAlias) throw new Error('A rename repository alias is required');\n\t\tif (!this.data?.itemRepositoryAlias) throw new Error('An item repository alias is required');\n\n\t\t// TODO: We should properly look into how we can simplify the one time usage of a extension api, as its a bit of overkill to take conditions/overwrites and observation of extensions into play here: [NL]\n\t\t// But since this happens when we execute an action, it does most likely not hurt any users, but it is a bit of a overkill to do this for every action: [NL]\n\t\tthis.#init = Promise.all([\n\t\t\tnew UmbExtensionApiInitializer(\n\t\t\t\tthis,\n\t\t\t\tumbExtensionsRegistry,\n\t\t\t\tthis.data.itemRepositoryAlias,\n\t\t\t\t[this],\n\t\t\t\t(permitted, ctrl) => {\n\t\t\t\t\tthis.#itemRepository = permitted ? (ctrl.api as UmbItemRepository) : undefined;\n\t\t\t\t},\n\t\t\t).asPromise(),\n\n\t\t\tnew UmbExtensionApiInitializer(\n\t\t\t\tthis,\n\t\t\t\tumbExtensionsRegistry,\n\t\t\t\tthis.data.renameRepositoryAlias,\n\t\t\t\t[this],\n\t\t\t\t(permitted, ctrl) => {\n\t\t\t\t\tthis.#renameRepository = permitted ? (ctrl.api as UmbRenameServerFileRepository) : undefined;\n\t\t\t\t},\n\t\t\t).asPromise(),\n\t\t]);\n\t}\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('Unique identifier is not available');\n\t\tawait this.#init;\n\t\tif (!this.#itemRepository) throw new Error('Item repository is not available');\n\n\t\tconst { data } = await this.#itemRepository.requestItems([this.data.unique]);\n\t\tthis._name = data?.[0].name ?? '';\n\t}\n\n\tasync #onSubmit(event: SubmitEvent) {\n\t\tevent.preventDefault();\n\t\tif (!this.#renameRepository) throw new Error('Rename repository is not available');\n\t\tif (!this.data?.unique) throw new Error('Unique identifier is not available');\n\n\t\tconst form = event.target as HTMLFormElement;\n\t\tif (!form) return;\n\n\t\tconst isValid = form.checkValidity();\n\t\tif (!isValid) return;\n\n\t\tconst formData = new FormData(form);\n\t\tconst name = formData.get('name') as string;\n\n\t\tconst { data } = await this.#renameRepository.rename(this.data.unique, name);\n\n\t\tif (data) {\n\t\t\tthis._submitModal();\n\t\t} else {\n\t\t\tthis._rejectModal();\n\t\t}\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\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tName\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t
\n\n\t\t\t\t\n\t\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#name {\n\t\t\t\twidth: 100%;\n\t\t\t}\n\t\t`,\n\t];\n}\n\nexport default UmbRenameModalElement;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'umb-rename-modal': UmbRenameModalElement;\n\t}\n}\n"],"names":["_itemRepository","_renameRepository","_init","_UmbRenameModalElement_instances","observeRepository_fn","onSubmit_fn","UmbRenameModalElement","UmbModalBaseElement","__privateAdd","__privateMethod","_changedProperties","__privateGet","data","html","__privateSet","UmbExtensionApiInitializer","umbExtensionsRegistry","permitted","ctrl","event","form","name","UmbTextStyles","css","__decorateClass","state","customElement","UmbRenameModalElement$1"],"mappings":";;;;;;;;;;;wYAAAA,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAWa,IAAAC,IAAN,cAAoCC,EAAuE;AAAA,EAA3G,cAAA;AAAA,UAAA,GAAA,SAAA,GAAAC,EAAA,MAAAL,CAAA,GAENK,EAAA,MAAAR,CAAA,GACAQ,EAAA,MAAAP,CAAA,GACAO,EAAA,MAAAN,CAAA,GAGQ,KAAA,QAAA;AAAA,EAAA;AAAA,EAEC,oBAA0B;AAClC,UAAM,kBAAkB,GACxBO,EAAA,MAAKN,GAALC,CAAA,EAAA,KAAA,IAAA;AAAA,EACD;AAAA,EA+BA,MAAyB,aACxBM,GACgB;AAEhB,QADA,MAAM,aAAaA,CAAkB,GACjC,CAAC,KAAK,MAAM,OAAc,OAAA,IAAI,MAAM,oCAAoC;AAE5E,QADA,MAAMC,EAAK,MAAAT,CAAA,GACP,CAACS,EAAK,MAAAX,CAAA,EAAuB,OAAA,IAAI,MAAM,kCAAkC;AAEvE,UAAA,EAAE,MAAAY,EAAK,IAAI,MAAMD,EAAA,MAAKX,CAAgB,EAAA,aAAa,CAAC,KAAK,KAAK,MAAM,CAAC;AAC3E,SAAK,QAAQY,IAAO,CAAC,EAAE,QAAQ;AAAA,EAChC;AAAA,EAyBS,SAAS;AACV,WAAAC;AAAA,+BACsB,QAAQ;AAAA;AAAA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