"use client";
import { jsx as a, jsxs as k } from "react/jsx-runtime";
import { AppSelect as $ } from "../../../app-select.js";
import { DatePicker as w } from "../../../date-picker.js";
import { Input as b } from "../../../input.js";
import { cn as g } from "../../../../../lib/utils.js";
function G({
  columnType: x,
  value: t,
  onChange: c,
  operator: f,
  listOptions: D = [],
  placeholder: C,
  size: o = "sm",
  className: p,
  hasError: V = !1,
  disabled: l = !1,
  i18n: s
}) {
  const m = C || s?.filters.value || "Value", T = V ? "border-red-500" : "", S = V ? "border-red-500" : "";
  if (f === "eq_null" || f === "n_eq_null" || f === "checked" || f === "unchecked")
    return null;
  switch (x) {
    case "string":
      return /* @__PURE__ */ a(
        b,
        {
          size: o,
          placeholder: m,
          className: g(p, T),
          value: t != null ? String(t) : "",
          disabled: l,
          onChange: (r) => c(r.target.value)
        }
      );
    case "number":
      return /* @__PURE__ */ a(
        b,
        {
          size: o,
          type: "number",
          placeholder: m,
          className: g(p, T),
          value: t != null ? String(t) : "",
          disabled: l,
          onChange: (r) => c(Number(r.target.value))
        }
      );
    case "boolean":
      return /* @__PURE__ */ a(
        $,
        {
          isSingleSelectClearable: !0,
          size: o,
          placeholder: m,
          className: g(p, S),
          options: [
            { value: "true", label: s?.booleanOperators.true || "True" },
            { value: "false", label: s?.booleanOperators.false || "False" }
          ],
          value: t === !0 ? "true" : t === !1 ? "false" : void 0,
          disabled: l,
          onValueChange: (r) => {
            c(r === "true" ? !0 : r === "false" ? !1 : void 0);
          }
        },
        `boolean-${t}`
      );
    case "list_single_select":
      return /* @__PURE__ */ a(
        $,
        {
          searchable: !0,
          isSingleSelectClearable: !0,
          size: o,
          placeholder: s?.filters.searchPlaceholder || m,
          className: g(p, S),
          options: D,
          value: Array.isArray(t) || typeof t == "boolean" ? void 0 : t,
          disabled: l,
          onValueChange: c
        }
      );
    case "list_multi_select":
      return /* @__PURE__ */ a(
        $,
        {
          multiple: !0,
          searchable: !0,
          size: o,
          placeholder: s?.filters.searchPlaceholder || m,
          className: g(p, S),
          options: D,
          value: Array.isArray(t) ? t : [],
          disabled: l,
          onValueChange: c
        }
      );
    case "date": {
      const r = (i) => {
        const e = i ? `${i.getFullYear()}-${(i.getMonth() + 1).toString().padStart(2, "0")}-${i.getDate().toString().padStart(2, "0")}` : void 0;
        c(e);
      }, n = t && typeof t == "string" ? new Date(t) : void 0;
      return /* @__PURE__ */ a(
        w,
        {
          value: n,
          onChange: r,
          placeholder: s?.filters.selectDate || "Select date",
          buttonVariant: "outline",
          size: o,
          dateFormat: "dd/MM/yyyy",
          disabled: l
        }
      );
    }
    case "datetime": {
      const r = (e, h) => {
        let u;
        if (e) {
          const y = h || "00:00", [M, F] = y.split(":"), d = new Date(e);
          d.setHours(parseInt(M, 10), parseInt(F, 10), 0, 0);
          const I = d.getFullYear(), N = (d.getMonth() + 1).toString().padStart(2, "0"), _ = d.getDate().toString().padStart(2, "0"), P = d.getHours().toString().padStart(2, "0"), A = d.getMinutes().toString().padStart(2, "0"), H = d.getSeconds().toString().padStart(2, "0");
          u = `${I}-${N}-${_}T${P}:${A}:${H}.000000`;
        }
        c(u);
      }, n = t && typeof t == "string" ? (() => {
        if (t.includes("T")) {
          const e = t.split("T")[0];
          if (e.match(/^\d{4}-\d{2}-\d{2}$/)) {
            const [h, u, y] = e.split("-").map(Number);
            return new Date(h, u - 1, y);
          }
        }
        return new Date(t);
      })() : void 0, i = n ? (() => {
        if (typeof t == "string" && t.includes("T")) {
          const e = t.split("T")[1];
          if (e) {
            const u = e.split(".")[0].replace("Z", "");
            if (u.match(/^\d{2}:\d{2}(:\d{2})?$/))
              return u.substring(0, 5);
          }
        }
        return `${n.getHours().toString().padStart(2, "0")}:${n.getMinutes().toString().padStart(2, "0")}`;
      })() : "00:00";
      return /* @__PURE__ */ k("div", { className: "flex flex-row gap-2", children: [
        /* @__PURE__ */ a(
          w,
          {
            value: n,
            onChange: (e) => r(e, i),
            placeholder: s?.filters.selectDate || "Select date",
            buttonVariant: "outline",
            size: o,
            dateFormat: "dd/MM/yyyy",
            disabled: l
          }
        ),
        /* @__PURE__ */ a(
          b,
          {
            type: "time",
            size: o,
            value: i,
            onChange: (e) => r(n, e.target.value),
            className: "text-sm",
            disabled: !n || l
          }
        )
      ] });
    }
    default:
      return /* @__PURE__ */ a("div", { className: "text-muted-foreground text-sm", children: s?.filters.filterNotSupported || "Filter not supported" });
  }
}
export {
  G as FilterValueInput
};
