import { jsx as r, jsxs as C } from "react/jsx-runtime";
import x from "react";
import { connect as L } from "react-redux";
import { injectIntl as J } from "react-intl";
import { CategoriesContext as M } from "./DataContext.js";
import { loadFilterItems as N, getCategories as T } from "../reducers/data.js";
import { Container as D, Segment as v } from "semantic-ui-react";
const j = ({ data: t, children: e }) => {
  const o = x.useMemo(() => t ? t.toJS() : null, [t]);
  return /* @__PURE__ */ r(M.Provider, { value: o, children: e });
};
class k extends x.Component {
  componentDidMount() {
    const { categories: e } = this.props;
    !e && !this.props.loading && this.props.onLoadData(this.props);
  }
  componentDidUpdate(e, o, n) {
    const { app: a, parentSelectedItems: p, filters: c, source: m, store: u, params: i, csv: l, group: s, editing: d } = this.props;
    e.parentSelectedItems && p && p.length != e.parentSelectedItems.length && this.props.onReLoadItems(this.props), (c != e.filters || JSON.stringify(i) != JSON.stringify(e.params) || a != e.app || e.source != m || l != e.csv) && (a === "csv" ? this.props.onSetData({ app: a, csv: l, store: u, params: i, group: s }) : (d && (i.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: o, error: n } = this.props;
    return o ? /* @__PURE__ */ r(D, { children: /* @__PURE__ */ r("div", { className: "filter-skeleton-placeholder", children: /* @__PURE__ */ r("div", { className: "filter-skeleton-shimmer" }) }) }) : e ? /* @__PURE__ */ r(j, { data: e, children: this.props.children }) : n ? /* @__PURE__ */ C(v, { color: "red", children: [
      /* @__PURE__ */ r("h1", { children: "500" }),
      /* @__PURE__ */ r("p", { children: "Wasn't able to load data" })
    ] }) : /* @__PURE__ */ r(D, { children: /* @__PURE__ */ C(v, { color: "red", children: [
      /* @__PURE__ */ r("h1", { children: "404" }),
      /* @__PURE__ */ r("p", { children: "Can't find this page" })
    ] }) });
  }
}
const R = (t, e) => {
  const { app: o, group: n, type: a, parentType: p, param: c, parentParam: m, params: u, dvzProxyDatasetId: i, uniqueStorage: l } = e, s = ["data", "categories", o];
  i && s.push(i), l && s.push(l);
  const d = t.getIn([...s, "items"]), h = d ? d.toJS() : [], y = t.getIn(["data", "filters", o, n, c]), g = h.filter((f) => f.type == a);
  g && g.length > 0 && g[0].items;
  let I = [], S = [];
  return p && (I = h.filter((f) => f.type == p), S = t.getIn(["data", "filters", o, n, m])), {
    parentSelectedItems: S,
    selectedItems: y,
    items: h,
    parentItems: I,
    data: t.getIn([...s, "items"]),
    error: t.getIn([...s, "error"]),
    loading: t.getIn([...s, "loading"])
  };
}, b = {
  onLoadData: T,
  onReLoadItems: N
}, U = L(R, b)(J(k));
export {
  U as default
};
