import { j as jsxRuntimeExports } from "../../../../../../../_virtual/jsx-runtime.js";
import "react";
import "../../../../../../../node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import "../../../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/react-hot-toast/dist/index.js";
import { BsDatabaseAdd } from "../../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.1.1/node_modules/react-icons/bs/index.js";
import { useDatarecords } from "../../../hooks/use-datarecord.js";
import { useEditorHelpers } from "../../../../../../../use-editor.js";
import { fieldLabel } from "../form-class.js";
import { Root as C, Trigger as u, Content as g, Group as y, Item as v } from "../../../../../../../node_modules/.pnpm/@radix-ui_themes@3.2.1_@types_react-dom@19.1.9_@types_react@19.1.13__@types_react@19.1._832fa1fef691e6e9510ada03948dc85c/node_modules/@radix-ui/themes/dist/esm/components/select.js";
import { IconButton as o } from "../../../../../../../node_modules/.pnpm/@radix-ui_themes@3.2.1_@types_react-dom@19.1.9_@types_react@19.1.13__@types_react@19.1._832fa1fef691e6e9510ada03948dc85c/node_modules/@radix-ui/themes/dist/esm/components/icon-button.js";
const DatarecordField = (props) => {
  const { currentValue, onChange, schema } = props;
  const editorHelpers = useEditorHelpers();
  const datarecords = useDatarecords();
  const onSettingsChange = (newVal) => {
    onChange(newVal);
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "layout-field basis-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start text-center justify-between flex-wrap gap-x-4 gap-y-1 pr-1", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between gap-1 flex-1 items-center", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: fieldLabel, children: "Schema" }),
      datarecords.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-500", children: "No forms schema found" }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
        C,
        {
          defaultValue: currentValue,
          size: "2",
          onValueChange: (value) => onSettingsChange(value),
          children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(
              u,
              {
                radius: "large",
                variant: "ghost",
                placeholder: schema["ui:placeholder"] ?? "Select a form schema"
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsx(g, { position: "popper", children: /* @__PURE__ */ jsxRuntimeExports.jsx(y, { children: datarecords.map((dr) => /* @__PURE__ */ jsxRuntimeExports.jsx(v, { value: dr.id, children: dr.label }, dr.id)) }) })
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(
      o,
      {
        type: "button",
        onClick: () => {
          editorHelpers.onShowPopup?.("add-form-schema");
        },
        variant: "ghost",
        size: "1",
        radius: "large",
        "aria-label": "Create new form",
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(BsDatabaseAdd, { size: 20 })
      }
    )
  ] }) });
};
export {
  DatarecordField
};
//# sourceMappingURL=datarecord.js.map
