import { j as u } from "../../../../_virtual/jsx-runtime.js";
import { Chip as r } from "../../../Chip/Chip.js";
import { getSelectors as o, commonDateSelectors as s } from "../../utils.js";
import { SelectorsWrapper as b } from "./styles.js";
function $({
  selectors: e,
  handleChange: d,
  narrow: m,
  selectedSelector: c,
  "data-testid": n
}) {
  const f = (a) => () => {
    const l = e == null ? void 0 : e.find((t) => t.value === a);
    l && (d == null || d(l));
  };
  return /* @__PURE__ */ u.jsx(b, { narrow: !!m, "data-testid": n, children: e == null ? void 0 : e.map((a) => /* @__PURE__ */ u.jsx(
    r,
    {
      label: a.label || "",
      selected: a.value === c.value,
      disabled: a.disabled,
      variant: "primary",
      "data-testid": `${n}-${a.value}`,
      onClick: f(a.value)
    },
    a.label
  )) });
}
function k(e) {
  var f;
  const d = e.defaultSelectorValues && Object.entries(e.defaultSelectorValues), m = o(s), c = m.reduce(
    (a, l) => {
      if (d) {
        const t = d.find(
          (i) => i[0].toUpperCase() === l.value
        );
        if (t != null && t[1]) {
          const i = {
            ...l,
            label: t[1].label
          };
          return [...a, i];
        } else if (t && t[1] === null)
          return [...a];
      }
      return [...a, l];
    },
    []
  );
  function n(a, l) {
    if (l) {
      const t = m.find(
        (i) => i.value === a
      );
      t && e.handleChange(t);
    } else if (e.customSelectors) {
      const t = e.customSelectors.find(
        (i) => i.value === a
      );
      t && e.handleChange(t);
    }
  }
  return /* @__PURE__ */ u.jsxs(
    b,
    {
      narrow: !!e.narrow,
      "data-testid": e["data-testid"],
      children: [
        c.map((a) => /* @__PURE__ */ u.jsx(
          r,
          {
            label: a.label || "",
            selected: a.value === e.selectedSelector.value,
            disabled: a.disabled,
            variant: "primary",
            "data-testid": `${e["data-testid"]}-${a.value}`,
            onClick: () => n(a.value, !0)
          },
          a.label
        )),
        (f = e.customSelectors) == null ? void 0 : f.map((a) => /* @__PURE__ */ u.jsx(
          r,
          {
            label: a.label,
            selected: a.value === e.selectedSelector.value,
            disabled: a.disabled,
            variant: "primary",
            "data-testid": `${e["data-testid"]}-${a.value}`,
            onClick: () => n(a.value, !1)
          },
          a.label
        ))
      ]
    }
  );
}
export {
  $ as Selectors,
  k as SelectorsOld
};
