"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),C=require("react"),D=require("react-redux"),q=require("react-intl"),y=require("./DataContext.js"),j=require("../reducers/data.js"),p=require("semantic-ui-react"),L=({data:s,children:e})=>{const r=C.useMemo(()=>s?s.toJS():null,[s]);return t.jsx(y.CategoriesContext.Provider,{value:r,children:e})};class M extends C.Component{componentDidMount(){const{categories:e}=this.props;!e&&!this.props.loading&&this.props.onLoadData(this.props)}componentDidUpdate(e,r,i){const{app:a,parentSelectedItems:c,filters:h,source:m,store:x,params:o,csv:l,group:n,editing:d}=this.props;e.parentSelectedItems&&c&&c.length!=e.parentSelectedItems.length&&this.props.onReLoadItems(this.props),(h!=e.filters||JSON.stringify(o)!=JSON.stringify(e.params)||a!=e.app||e.source!=m||l!=e.csv)&&(a==="csv"?this.props.onSetData({app:a,csv:l,store:x,params:o,group:n}):(d&&(o.v=(Math.random()+1).toString(36).substring(7)),this.setState({showLoading:!1}),this.props.onLoadData(this.props),setTimeout(this.checkLoadingTime,100)))}render(){const{data:e,loading:r,error:i}=this.props;return r?t.jsx(p.Container,{children:t.jsx("div",{className:"filter-skeleton-placeholder",children:t.jsx("div",{className:"filter-skeleton-shimmer"})})}):e?t.jsx(L,{data:e,children:this.props.children}):i?t.jsxs(p.Segment,{color:"red",children:[t.jsx("h1",{children:"500"}),t.jsx("p",{children:"Wasn't able to load data"})]}):t.jsx(p.Container,{children:t.jsxs(p.Segment,{color:"red",children:[t.jsx("h1",{children:"404"}),t.jsx("p",{children:"Can't find this page"})]})})}}const R=(s,e)=>{const{app:r,group:i,type:a,parentType:c,param:h,parentParam:m,params:x,dvzProxyDatasetId:o,uniqueStorage:l}=e,n=["data","categories",r];o&&n.push(o),l&&n.push(l);const d=s.getIn([...n,"items"]),u=d?d.toJS():[],v=s.getIn(["data","filters",r,i,h]),g=u.filter(f=>f.type==a);g&&g.length>0&&g[0].items;let I=[],S=[];return c&&(I=u.filter(f=>f.type==c),S=s.getIn(["data","filters",r,i,m])),{parentSelectedItems:S,selectedItems:v,items:u,parentItems:I,data:s.getIn([...n,"items"]),error:s.getIn([...n,"error"]),loading:s.getIn([...n,"loading"])}},J={onLoadData:j.getCategories,onReLoadItems:j.loadFilterItems},T=D.connect(R,J)(q.injectIntl(M));exports.default=T;
