import { jsx as A } from "react/jsx-runtime";
import { useState as _, useEffect as j } from "react";
import B from "./PostsFilterDropdown.js";
import { Config as D } from "../../conf/index.js";
const k = (i) => {
  const {
    taxonomy: t,
    group: l,
    placeholder: p,
    allLabel: c,
    noneLabel: f,
    useSingleColumn: m,
    enableTextSearch: u,
    filterType: g,
    showNoDataOption: y,
    closeOnSelect: d,
    allNoneSameBehaviour: x,
    autoApply: O,
    alphabeticalSort: S,
    ascOrder: h,
    type: P,
    categories: n,
    onChange: T,
    ...w
  } = i, [C, e] = _([]), b = async () => {
    if (!t || t === "none") {
      e([]);
      return;
    }
    const r = await (await fetch(D.REACT_APP_WP_API + "/wp/v2/" + t)).json();
    if (r) {
      const s = r.map((o) => ({
        key: o.id,
        value: o.id,
        text: o.name
      }));
      if (n) {
        const o = s.filter((v) => n.indexOf(v.value.toString()) > -1);
        e([]), e(o);
      } else
        e([]), e(s);
    }
  };
  return j(() => {
    let a = !1;
    return a || (e([]), b()), () => {
      a = !0;
    };
  }, [P, t, n]), /* @__PURE__ */ A(
    B,
    {
      ...w,
      group: l,
      placeholder: p,
      allLabel: c,
      noneLabel: f,
      useSingleColumn: m,
      enableTextSearch: u,
      filterType: g,
      showNoDataOption: y,
      closeOnSelect: d,
      allNoneSameBehaviour: x,
      autoApply: O,
      alphabeticalSort: S,
      ascOrder: h,
      options: C,
      onChange: T
    }
  );
};
export {
  k as default
};
