var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/schedules/resources/detail/detailContent.tsx
var detailContent_exports = {};
__export(detailContent_exports, {
  default: () => detailContent_default
});
module.exports = __toCommonJS(detailContent_exports);
var import_ahooks = require("ahooks");
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_MaxParticipantsModule = __toESM(require("../../products/ProductDetailDrawer/ProductDetail/MaxParticipantsModule"));
var import_SchedulesModule = __toESM(require("../../products/ProductDetailDrawer/ProductDetail/SchedulesModule"));
var import_relationProduct = __toESM(require("../relationProduct"));
var import_serve = require("../serve");
var import_index = require("./index.less");
var ResourcesDetailContent = (props, refs) => {
  const [form] = import_antd.Form.useForm();
  const useSchedule = import_antd.Form.useWatch("schedule", form);
  const {
    loading,
    onClose,
    drawerContainer,
    isAutoSetCalendarData,
    tabKey
  } = props;
  const [detail, setDetail] = (0, import_react.useState)({});
  const [isChangeData, setIsChangeData] = (0, import_react.useState)(false);
  const [canChange, setCanChange] = (0, import_react.useState)(false);
  (0, import_react.useImperativeHandle)(refs, () => {
    return {
      setFieldsValue: (data) => {
        setDetail(data);
        form.setFieldsValue(data);
      },
      getIsEdit: () => isChangeData
    };
  });
  const _setResourceRelation = (0, import_ahooks.useRequest)(import_serve.setResourceRelation, {
    manual: true,
    onSuccess: (res) => {
      if ((res == null ? void 0 : res.code) === 200) {
        onClose == null ? void 0 : onClose(true);
        import_antd.message.success(import_utils.locales.getText("pisell2.text.schedules.save-success"));
        setIsChangeData(false);
      }
    }
  });
  const onFinish = (params) => {
    _setResourceRelation.run({
      item_id: detail.form_record_id,
      item_type: "form",
      schedules: params
    });
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "resources-detail-card product-detail-card" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { round: true, active: true, loading }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form,
    {
      form,
      onFinish,
      onValuesChange: () => {
        if (canChange) {
          setIsChangeData(true);
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { noStyle: true, name: "schedule" }, /* @__PURE__ */ import_react.default.createElement(
      import_SchedulesModule.default,
      {
        drawerContainer,
        ruleFn: () => isAutoSetCalendarData,
        tabKey
      }
    )),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { noStyle: true, name: "max_participants" }, /* @__PURE__ */ import_react.default.createElement(
      import_MaxParticipantsModule.default,
      {
        form,
        useSchedule,
        onData: () => {
          setTimeout(() => {
            setCanChange(true);
          }, 500);
        }
      }
    )),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { noStyle: true, name: "products" }, /* @__PURE__ */ import_react.default.createElement(import_relationProduct.default, null))
  ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-component-resources-detail-footer" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Button,
    {
      className: "footer-btn",
      type: "primary",
      onClick: form.submit,
      loading: _setResourceRelation.loading,
      disabled: !isChangeData
    },
    import_utils.locales.getText("pisell2.text.schedules.save")
  )));
};
var detailContent_default = (0, import_react.forwardRef)(ResourcesDetailContent);
