import { j as e } from "../../../../../../_virtual/jsx-runtime.js";
import { tx as p } from "../../../../../style-system/dist/twind.js";
const h = p(
  `px-3 py-2 border border-base-200 rounded-md shadow-inset
  focus:(outline-2 outline-offset-0 outline-accent-500 ring-none border-accent-500)
  placeholder:text-inherit placeholder:opacity-70`
), d = ({
  fieldName: n,
  title: a,
  required: s,
  description: r,
  children: c
}) => /* @__PURE__ */ e.jsxs("div", { className: "flex-1 flex flex-col gap-1", children: [
  /* @__PURE__ */ e.jsxs("label", { htmlFor: n, className: "font-medium", children: [
    a,
    " ",
    s && /* @__PURE__ */ e.jsx("span", { children: "*" })
  ] }),
  c
] }), f = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "boolean" ? s : !1;
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsxs("div", { className: "flex items-center space-x-3", children: [
    /* @__PURE__ */ e.jsx(
      "input",
      {
        id: n,
        name: n,
        type: "checkbox",
        defaultChecked: l,
        onChange: (o) => r(o.target.checked),
        required: t,
        className: p(
          "rounded border border-base-200 focus:outline-none focus:(ring-2 ring-accent-500 border-accent-500) text-accent-500"
        )
      }
    ),
    /* @__PURE__ */ e.jsxs("label", { htmlFor: n, className: "font-medium", children: [
      c,
      " ",
      t && /* @__PURE__ */ e.jsx("span", { children: "*" })
    ] })
  ] }) });
}, C = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "number" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "input",
    {
      id: n,
      name: n,
      type: "number",
      value: l,
      onChange: (o) => {
        const m = o.target.value;
        r(m === "" ? 0 : Number(m));
      },
      placeholder: a["ui:placeholder"],
      min: a.minimum,
      max: a.maximum,
      required: t,
      className: h
    }
  ) });
}, F = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = a.enum || [], o = typeof s == "string" ? s : "", m = a.metadata?.["ui:widget"], j = l.reduce(
    (x, u) => u.length > x.length ? u : x,
    a["ui:placeholder"] || "Choose an option"
  ), b = Math.max(j.length * 0.6 + 5, 10), g = l.length === 1 ? "checkbox" : m;
  return g === "checkbox" ? /* @__PURE__ */ e.jsx("div", { className: "flex-1 flex flex-col gap-1", children: /* @__PURE__ */ e.jsxs("fieldset", { children: [
    /* @__PURE__ */ e.jsxs("legend", { className: "block text-sm font-medium ", children: [
      c,
      " ",
      t && /* @__PURE__ */ e.jsx("span", { className: "text-red-500", children: "*" })
    ] }),
    /* @__PURE__ */ e.jsx("div", { className: "space-y-2 mt-2", children: l.map((x) => /* @__PURE__ */ e.jsxs("label", { className: "flex items-center space-x-2", children: [
      /* @__PURE__ */ e.jsx(
        "input",
        {
          type: "checkbox",
          name: n,
          value: x,
          onChange: (u) => r(u.target.checked ? u.target.value : ""),
          required: t,
          className: p(
            "rounded border border-base-200 focus:outline-none focus:(ring-2 ring-accent-500 border-accent-500) text-accent-500"
          )
        }
      ),
      /* @__PURE__ */ e.jsx("span", { className: "text-sm", children: x })
    ] }, x)) })
  ] }) }) : g === "radio" ? /* @__PURE__ */ e.jsx("div", { className: "flex-1 flex flex-col gap-1", children: /* @__PURE__ */ e.jsxs("fieldset", { children: [
    /* @__PURE__ */ e.jsxs("legend", { className: "font-medium", children: [
      c,
      " ",
      t && /* @__PURE__ */ e.jsx("span", { children: "*" })
    ] }),
    /* @__PURE__ */ e.jsx("div", { className: "space-y-2 mt-2", children: l.map((x) => /* @__PURE__ */ e.jsxs("label", { className: "flex items-center space-x-2", children: [
      /* @__PURE__ */ e.jsx(
        "input",
        {
          type: "radio",
          name: n,
          value: x,
          checked: o === x,
          onChange: (u) => r(u.target.value),
          required: t,
          className: "border border-base-200 focus:outline-none focus:(ring-2 ring-accent-500 border-accent-500) text-accent-500"
        }
      ),
      /* @__PURE__ */ e.jsx("span", { children: x })
    ] }, x)) })
  ] }) }) : /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsxs(
    "select",
    {
      id: n,
      name: n,
      value: o,
      onChange: (x) => r(x.target.value),
      required: t,
      className: p(h, "w-full"),
      style: { minWidth: `${b}rem` },
      children: [
        /* @__PURE__ */ e.jsx("option", { value: "", disabled: !0, children: a["ui:placeholder"] || a.description || "Choose an option" }),
        l.map((x) => /* @__PURE__ */ e.jsx("option", { value: x, children: x }, x))
      ]
    }
  ) });
}, k = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "string" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "input",
    {
      id: n,
      name: n,
      type: "email",
      value: l,
      onChange: (o) => r(o.target.value),
      placeholder: a["ui:placeholder"],
      required: t,
      className: h
    }
  ) });
}, V = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "string" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "input",
    {
      id: n,
      name: n,
      type: "url",
      value: l,
      onChange: (o) => r(o.target.value),
      placeholder: a["ui:placeholder"],
      required: t,
      className: h
    }
  ) });
}, L = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "string" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "input",
    {
      id: n,
      name: n,
      type: "date",
      value: l,
      onChange: (o) => r(o.target.value),
      required: t,
      className: h
    }
  ) });
}, N = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "string" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "input",
    {
      id: n,
      name: n,
      type: "datetime-local",
      value: l,
      onChange: (o) => r(o.target.value),
      required: t,
      className: h
    }
  ) });
}, w = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "string" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "input",
    {
      id: n,
      name: n,
      type: "text",
      value: l,
      onChange: (o) => r(o.target.value),
      placeholder: a["ui:placeholder"],
      minLength: a.minLength,
      maxLength: a.maxLength,
      required: t,
      className: p(h)
    }
  ) });
}, W = ({
  fieldName: n,
  fieldSchema: a,
  value: s,
  onChange: r,
  title: c,
  required: t,
  description: i
}) => {
  const l = typeof s == "string" ? s : "";
  return /* @__PURE__ */ e.jsx(d, { fieldName: n, title: c, required: t, description: i, children: /* @__PURE__ */ e.jsx(
    "textarea",
    {
      id: n,
      name: n,
      value: l,
      onChange: (o) => r(o.target.value),
      placeholder: a["ui:placeholder"],
      minLength: a.minLength,
      maxLength: a.maxLength,
      required: t,
      rows: 4,
      className: h
    }
  ) });
};
export {
  f as BooleanField,
  L as DateField,
  N as DateTimeField,
  k as EmailField,
  C as NumberField,
  F as SelectField,
  w as StringField,
  W as TextareaField,
  V as UrlField
};
//# sourceMappingURL=Fields.js.map
