"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("react");
const emotionReactJsxRuntime_browser_esm = require("../node_modules/.pnpm/@emotion_react@11.10.4_q4mq7tnhdumujvomvw24zx33y4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
require("../lib/useAppState.js");
const Tabs = require("../components/Tabs.js");
const PageTile = require("./PageTile.js");
require("react-hot-toast");
const Draggable = require("./Draggable.js");
const Form = require("../form/components/Form.js");
require("../tailwind.js");
require("../lib/AppContext.js");
const Builder = ({
  fetcher,
  type = "update",
  useMatches,
  useParams,
  contentSchema,
  fieldSchema,
  baseSchema,
  cols,
  ...props
}) => {
  var _a, _b;
  const {
    id
  } = useParams();
  const fieldData = id ? (_b = (_a = useMatches().find((m) => m.pathname === "/admin")) == null ? void 0 : _a.data) == null ? void 0 : _b.tableData[id] : {};
  const onSubmit = (result) => {
    console.log("onSubmit-->", result);
    fetcher.submit({
      tableName: "Page",
      data: JSON.stringify(result),
      action: "form"
    }, {
      method: "post",
      action: type === "update" ? `/api/crud/Page/${id}` : `/api/crud/Page`
    });
    toast.success("\u66F4\u65B0\u6210\u529F");
  };
  const pageHeader = {
    pageTitle: fieldData.title,
    description: "\u6570\u636E\u6A21\u578B",
    back: true,
    buttons: [{
      label: "\u65B0\u589E\u6A21\u578B",
      icon: "add",
      onClick: () => ""
    }]
  };
  const tabs = [{
    name: "\u6A21\u578B\u8BBE\u7F6E",
    content: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(Form, {
      data: baseSchema,
      className: "p-6 bg-white rounded-lg shadow",
      defaultValues: fieldData,
      onSubmit: (e) => onSubmit(e),
      cols: 2,
      pageHeader: {
        pageTitle: "\u6570\u636E\u6A21\u578B\u8BBE\u7F6E",
        description: "\u57FA\u672C\u914D\u7F6E\u4FE1\u606F",
        className: "px-0 py-6",
        titleClassName: "text-xl",
        buttons: [{
          label: "\u4FDD\u5B58\u8BBE\u7F6E",
          type: "submit",
          className: "bg-sky-600 text-white hover:text-sky-600"
        }]
      }
    }, id)
  }, {
    name: "\u5B57\u6BB5\u4E0E\u5E03\u5C40",
    content: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(Draggable.Draggable, {
      cols,
      data: fieldData.columns,
      fieldSchema,
      contentSchema,
      onSubmit: (e) => onSubmit({
        columns: e
      })
    }, id)
  }];
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(emotionReactJsxRuntime_browser_esm.Fragment, {
    children: [pageHeader && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(PageTile.PageTile, {
      ...pageHeader
    }), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: "flex flex-col flex-1 px-8",
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(Tabs.Tabs, {
        tabs,
        className: "flex flex-col flex-1"
      })
    })]
  });
};
exports.Builder = Builder;
//# sourceMappingURL=Builder.js.map
