Liferay.Loader.define("@liferay/content-dashboard-web@2.0.69/js/components/SidebarPanel",["module","exports","require","@frontend-taglib-clay$clayui/alert","@frontend-taglib-clay$clayui/loading-indicator","@liferay/frontend-js-react-web","frontend-js-web","liferay!frontend-js-react-web$react","./Sidebar"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=d(r("@frontend-taglib-clay$clayui/alert")),a=d(r("@frontend-taglib-clay$clayui/loading-indicator")),l=r("@liferay/frontend-js-react-web"),o=r("frontend-js-web"),u=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=i();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var l=n?Object.getOwnPropertyDescriptor(e,a):null;l&&(l.get||l.set)?Object.defineProperty(r,a,l):r[a]=e[a]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),c=d(r("./Sidebar"));function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function d(e){return e&&e.__esModule?e:{default:e}}function f(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function p(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e={data:null,error:null,loading:!1,open:!0},O=(t,r)=>{var n;switch(r.type){case"CLOSE_SIDEBAR":return s(s({},t),{},{isOpen:!1});case"LOAD_DATA":return s(s({},t),{},{data:null,error:null,loading:!0});case"OPEN_SIDEBAR":return s(s({},t),{},{isOpen:!0});case"SET_ERROR":return s(s({},t),{},{data:null,error:r.error,loading:!1});case"SET_HTML":return s(s({},t),{},{data:{html:r.html},error:null,loading:!1});case"SET_JSON":return s(s({},t),{},{data:r.data,error:null===(n=r.data)||void 0===n?void 0:n.error,loading:!1});default:return e}};var y=u.default.forwardRef((({fetchURL:t,onClose:r,viewComponent:i},d)=>{const f=(0,u.useRef)(i),s=(0,l.useIsMounted)(),[p,y]=(0,u.useReducer)(O,e),b=e=>{s()&&y(e)},g=e=>{b({type:"LOAD_DATA"}),(0,o.fetch)(e,{method:"GET"}).then((e=>e.headers.get("content-type").includes("json")?e.json().then((e=>b({data:e,type:"SET_JSON"}))):e.text().then((e=>b({html:e,type:"SET_HTML"}))))).catch((()=>{b({error:Liferay.Language.get("an-unexpected-error-occurred"),type:"SET_ERROR"})}))};return(0,u.useEffect)((()=>{g(t)}),[t]),(0,u.useEffect)((()=>{f.current=i}),[i]),(0,u.useImperativeHandle)(d,(()=>({close:()=>b({type:"CLOSE_SIDEBAR"}),open:(e,t)=>{f.current=t,g(e),b({type:"OPEN_SIDEBAR"})}}))),u.default.createElement(c.default,{fetchData:()=>g(t),onClose:()=>r?r():b({type:"CLOSE_SIDEBAR"}),open:p.isOpen},(null==p?void 0:p.loading)?u.default.createElement("div",{className:"align-items-center d-flex loading-indicator-wrapper"},u.default.createElement(a.default,{small:!0})):(null==p?void 0:p.error)?u.default.createElement(u.default.Fragment,null,u.default.createElement(c.default.Header,null),u.default.createElement(n.default,{displayType:"danger",variant:"stripe"},p.error)):(null==p?void 0:p.data)&&u.default.createElement(f.current,p.data))}));t.default=y}}));
//# sourceMappingURL=SidebarPanel.js.map