Liferay.Loader.define("document-library-opener-onedrive-web@3.0.42/js/DocumentLibraryOpener.es",["module","exports","require","@liferay/frontend-icons-web","frontend-js-web"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=r("@liferay/frontend-icons-web"),i=r("frontend-js-web");const e=500,n=2e3,s=Liferay.Language.get("an-unexpected-error-occurred");class DocumentLibraryOpener{constructor({namespace:e}){this._namespace=e,this._dialogLoadingId="".concat(e,"OneDriveLoadingDialog"),this._refreshAfterNavigate=!1}_hideLoading(){(0,i.getWindow)(this._dialogLoadingId).hide()}_openExternal({externalURL:e}){window.open(e),this._hideLoading(),this._refreshAfterNavigate&&(this._refreshAfterNavigate=!1,Liferay.Portlet.refresh("#p_p_id".concat(this._namespace)))}_polling({statusURL:t}){return(0,i.fetch)(t).then((e=>{if(!e.ok)throw s;return e.json()})).then((r=>{if(!r.complete){if(r.error)throw s;return new Promise((r=>{setTimeout((()=>{this._polling({statusURL:t}).then(r)}),e)}))}this._openExternal({externalURL:r.office365EditURL})})).catch((e=>{this._showError(e)}))}_showError(e){(0,i.openToast)({message:e,type:"danger"})}_showLoading({dialogMessage:e}){return new Promise((t=>{(0,i.openWindow)({dialog:{bodyContent:"<p>".concat(e,'</p><div aria-hidden="true" class="loading-animation"></div>'),cssClass:"office-365-redirect-modal",height:172,modal:!0,resizable:!1,title:"",width:320},id:this._dialogLoadingId},(()=>{setTimeout(t,n)}))}))}createWithName({dialogTitle:e,formSubmitURL:t}){(0,i.openSimpleInputModal)({alert:{message:Liferay.Language.get("the-document-has-been-checked-out-.please-check-in-the-document-after-edits-are-made-to-save-the-changes-into-the-document-library"),style:"info",title:Liferay.Language.get("info")},dialogTitle:e,formSubmitURL:t,mainFieldLabel:Liferay.Language.get("title"),mainFieldName:"title",namespace:this._namespace,onFormSuccess:e=>{e.oneDriveBackgroundTaskStatusURL&&this.open({dialogMessage:e.dialogMessage,refresh:!0,statusURL:e.oneDriveBackgroundTaskStatusURL})},spritemap:(0,a.getSpritemap)()})}edit({formSubmitURL:e}){this._refreshAfterNavigate=!0;const t=this._showLoading({dialogMessage:Liferay.Language.get("you-are-being-redirected-to-an-external-editor-to-edit-this-document")}),r=(0,i.fetch)(e).then((e=>{if(!e.ok)throw s;return e.json()})).then((e=>{if(e.redirectURL)(0,i.navigate)(e.redirectURL);else{if(e.oneDriveBackgroundTaskStatusURL)return this._polling({statusURL:e.oneDriveBackgroundTaskStatusURL});if(e.error)throw e.error.errorMessage||s}})).catch((e=>{this._showError(e)}));return Promise.all([t,r])}open({dialogMessage:e=Liferay.Language.get("you-are-being-redirected-to-an-external-editor-to-edit-this-document"),statusURL:t,refresh:r=!1}){this._refreshAfterNavigate=r;const a=this._showLoading({dialogMessage:e}),i=this._polling({statusURL:t});return Promise.all([a,i])}}var o=DocumentLibraryOpener;t.default=o}}));
//# sourceMappingURL=DocumentLibraryOpener.es.js.map