Liferay.Loader.define("@liferay/content-dashboard-web@2.0.73/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","../utils/constants","./Sidebar"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=f(r("@frontend-taglib-clay$clayui/alert")),a=f(r("@frontend-taglib-clay$clayui/loading-indicator")),l=r("@liferay/frontend-js-react-web"),o=r("frontend-js-web"),c=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=d();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")),i=r("../utils/constants"),u=f(r("./Sidebar"));function d(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return d=function(){return e},e}function f(e){return e&&e.__esModule?e:{default:e}}function s(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 p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(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=()=>{Liferay.Util.Session.set("com.liferay.content.dashboard.web_panelState",i.CLOSE_PANEL_VALUE),Liferay.Util.Session.set("com.liferay.content.dashboard.web_selectedItemRowId","")},g=(t,r)=>{var n;switch(r.type){case"CLOSE_SIDEBAR":return O(),p(p({},t),{},{isOpen:!1});case"LOAD_DATA":return p(p({},t),{},{data:null,error:null,loading:!0});case"OPEN_SIDEBAR":return p(p({},t),{},{isOpen:!0});case"SET_ERROR":return p(p({},t),{},{data:null,error:r.error,loading:!1});case"SET_HTML":return p(p({},t),{},{data:{html:r.html},error:null,loading:!1});case"SET_JSON":return p(p({},t),{},{data:r.data,error:null===(n=r.data)||void 0===n?void 0:n.error,loading:!1});default:return e}};var b=c.default.forwardRef((({fetchURL:t,onClose:r,singlePageApplicationEnabled:i,viewComponent:d},f)=>{const s=(0,c.useRef)(d),p=(0,l.useIsMounted)(),[y,b]=(0,c.useReducer)(g,e),E=e=>{p()&&b(e)},j=e=>{E({type:"LOAD_DATA"}),(0,o.fetch)(e,{method:"GET"}).then((e=>e.headers.get("content-type").includes("json")?e.json().then((e=>E({data:e,type:"SET_JSON"}))):e.text().then((e=>E({html:e,type:"SET_HTML"}))))).catch((()=>{E({error:Liferay.Language.get("an-unexpected-error-occurred"),type:"SET_ERROR"})}))};return(0,c.useEffect)((()=>{j(t)}),[t]),(0,c.useEffect)((()=>{s.current=d}),[d]),(0,c.useEffect)((()=>{if(!i)return;const e=Liferay.on("startNavigate",(({path:e,target:t})=>{const[,r]=t.currentURL.split("?"),n=new URLSearchParams(r).get("p_p_id");e.includes(n)||O()}));return()=>{e.detach()}}),[i]),(0,c.useImperativeHandle)(f,(()=>({close:()=>E({type:"CLOSE_SIDEBAR"}),open:(e,t)=>{s.current=t,j(e),E({type:"OPEN_SIDEBAR"})}}))),c.default.createElement(u.default,{fetchData:()=>j(t),onClose:()=>r?r():E({type:"CLOSE_SIDEBAR"}),open:y.isOpen},(null==y?void 0:y.loading)?c.default.createElement("div",{className:"align-items-center d-flex loading-indicator-wrapper"},c.default.createElement(a.default,{small:!0})):(null==y?void 0:y.error)?c.default.createElement(c.default.Fragment,null,c.default.createElement(u.default.Header,null),c.default.createElement(n.default,{displayType:"danger",variant:"stripe"},y.error)):(null==y?void 0:y.data)&&c.default.createElement(s.current,y.data))}));t.default=b}}));
//# sourceMappingURL=SidebarPanel.js.map