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/productExtension/index.tsx
var productExtension_exports = {};
__export(productExtension_exports, {
  default: () => productExtension_default
});
module.exports = __toCommonJS(productExtension_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("../../utils/index");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_server = require("./server");
var import_ahooks = require("ahooks");
var import_fields = require("./fields");
var import_card = __toESM(require("./card"));
var import_index = require("./index.less");
var import_utils2 = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_locales2 = require("../../utils/locales");
import_utils2.locales.init(import_locales.default, (0, import_locales2.getLocale)());
var ProductExtension = ({ onDataChange, type }) => {
  var _a;
  const context = (0, import_useEngineContext.default)();
  import_utils.request.setRequest(context.appHelper.utils.request);
  const _getProductExtensionFields = (0, import_ahooks.useRequest)(import_server.getProductExtensionFields, {
    manual: true,
    onSuccess: (res) => {
      onDataChange == null ? void 0 : onDataChange(res);
    }
  });
  (0, import_react.useEffect)(() => {
    _getProductExtensionFields.run({ code: "event_item" });
  }, []);
  const extension = (0, import_react.useMemo)(() => {
    return _getProductExtensionFields.data || {};
  }, [_getProductExtensionFields.data]);
  const renderItem = (item, name) => {
    let { Component, defaultProps } = import_fields.fields[item.key] || {};
    let _props = {
      ...defaultProps
    };
    if (name) {
      _props.name = name;
    }
    return Component ? /* @__PURE__ */ import_react.default.createElement(Component, { ..._props }) : null;
  };
  return /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { active: true, round: true, loading: _getProductExtensionFields.loading }, (_a = extension.filed) == null ? void 0 : _a.map((item, index) => {
    var _a2, _b, _c, _d;
    const isHidden = ((_a2 = item[0]) == null ? void 0 : _a2.key) === "event_item_type";
    if (type !== "all" && ((_b = item[0]) == null ? void 0 : _b.key) === "schedule.ids") {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_card.default,
      {
        hidden: isHidden,
        key: index,
        header: item.length === 1 ? (_c = item[0]) == null ? void 0 : _c.name : (_d = extension == null ? void 0 : extension.extension) == null ? void 0 : _d.name
      },
      item.map((child, childIndex) => {
        const name = `${child.id}|${child.key}`;
        return /* @__PURE__ */ import_react.default.createElement(
          import_antd.Form.Item,
          {
            hidden: isHidden,
            label: item.length === 1 ? "" : child.name,
            name,
            rules: child.rules || child.key === "par_value" ? [
              {
                required: true,
                message: import_utils2.locales.getText(
                  "pisell2.text.product-extension.please-select"
                )
              }
            ] : [],
            key: childIndex,
            noStyle: true,
            initialValue: child.key === "event_item_capacity" ? 1 : void 0
          },
          renderItem(child, name)
        );
      })
    );
  }));
};
var productExtension_default = ProductExtension;
