Liferay.Loader.define("document-library-opener-onedrive-web@3.0.31/js/DocumentLibraryOpener.es",["module","exports","require","@liferay/frontend-icons-web","frontend-js-web"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=a("@liferay/frontend-icons-web"),r=a("frontend-js-web");const e=500,n=2e3,s=Liferay.Language.get("an-unexpected-error-occurred");class d{constructor({namespace:e}){this._namespace=e,this._dialogLoadingId="".concat(e,"OneDriveLoadingDialog"),this._refreshAfterNavigate=!1}_hideLoading(){(0,r.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,r.fetch)(t).then((e=>{if(!e.ok)throw s;return e.json()})).then((a=>{if(!a.complete){if(a.error)throw s;return new Promise((a=>{setTimeout((()=>{this._polling({statusURL:t}).then(a)}),e)}))}this._openExternal({externalURL:a.office365EditURL})})).catch((e=>{this._showError(e)}))}_showError(e){(0,r.openToast)({message:e,type:"danger"})}_showLoading({dialogMessage:e}){return new Promise((t=>{(0,r.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,r.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,i.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")}),a=(0,r.fetch)(e).then((e=>{if(!e.ok)throw s;return e.json()})).then((e=>{if(e.redirectURL)(0,r.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,a])}open({dialogMessage:e=Liferay.Language.get("you-are-being-redirected-to-an-external-editor-to-edit-this-document"),statusURL:t,refresh:a=!1}){this._refreshAfterNavigate=a;const i=this._showLoading({dialogMessage:e}),r=this._polling({statusURL:t});return Promise.all([i,r])}}var o=d;t.default=o}}));
//# sourceMappingURL=DocumentLibraryOpener.es.js.map