import { jsxs as r, jsx as l } from "react/jsx-runtime";
import { useState as x, useCallback as d, useMemo as D } from "react";
import { Dialog as F, DialogTrigger as N, DialogContent as C, DialogHeader as j, DialogTitle as y, DialogDescription as T, DialogFooter as w, DialogClose as g } from "../../../dialog/DialogPrimitive.js";
import m from "../../../button/Button.js";
import c from "../../../box/Box.js";
import k from "../../../input/Input.js";
import u from "../../../text/Text.js";
import B from "../../../icon/Icon.js";
const O = ({ conditions: n, presets: e, onSavePreset: a }) => {
  const f = Object.entries(n || {}).map(([i, o]) => ({ key: i, condition: o })), [t, h] = x(""), p = d(() => {
    !t.trim() || !n || (a == null || a([
      ...e || [],
      {
        label: t.trim(),
        value: n
      }
    ]), h(""));
  }, [t, n, a, e]), b = d(
    (i) => {
      e && (a == null || a(e.filter((o) => o.label !== i)));
    },
    [e, a]
  ), s = D(() => e == null ? void 0 : e.some((i) => i.label === t), [t, e]);
  return f.some((i) => i.condition.value.length > 0) ? /* @__PURE__ */ r(F, { children: [
    /* @__PURE__ */ l(N, { asChild: !0, children: /* @__PURE__ */ l(m, { variant: "ghost", label: "Filter speichern" }) }),
    /* @__PURE__ */ r(C, { children: [
      /* @__PURE__ */ r(j, { children: [
        /* @__PURE__ */ l(y, { children: "Filter speichern" }),
        /* @__PURE__ */ l(T, { className: "hidden" })
      ] }),
      /* @__PURE__ */ r(c, { className: "flex flex-col gap-[var(--spacing-8)]", children: [
        /* @__PURE__ */ l(c, { className: "w-full", children: /* @__PURE__ */ l(
          k,
          {
            id: "jtl-filter-preset",
            label: "Filtername",
            value: t,
            onChange: h,
            errorMessage: s ? "Filtername existiert bereits" : ""
          }
        ) }),
        e && /* @__PURE__ */ r(c, { className: "flex flex-col gap-[var(--spacing-3)]", children: [
          /* @__PURE__ */ l(u, { type: "small", weight: "medium", children: "Gespeicherte Filter" }),
          e.map((i) => /* @__PURE__ */ r(c, { className: "flex items-center justify-between gap-[var(--spacing-2-5)]", children: [
            /* @__PURE__ */ r(c, { className: "flex items-center gap-[var(--spacing-2)]", children: [
              /* @__PURE__ */ l(B, { name: "List" }),
              /* @__PURE__ */ l(u, { type: "small", weight: "regular", truncate: !0, children: i.label })
            ] }),
            /* @__PURE__ */ l(m, { variant: "ghost", icon: "Trash2", size: "iconSm", onClick: () => b(i.label) })
          ] }))
        ] })
      ] }),
      /* @__PURE__ */ r(w, { className: "gap-4", children: [
        /* @__PURE__ */ l(g, { asChild: !0, children: /* @__PURE__ */ l(m, { label: "Abbrechen", variant: "secondary" }) }),
        /* @__PURE__ */ l(g, { asChild: !0, children: /* @__PURE__ */ l(m, { label: "Filter speichern", type: "submit", onClick: p, disabled: s }) })
      ] })
    ] })
  ] }) : null;
};
export {
  O as default
};
//# sourceMappingURL=DataTableSaveFilter.js.map
