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/eventBooking/components/Provider/Resource/index.tsx
var Resource_exports = {};
__export(Resource_exports, {
  default: () => Resource_default
});
module.exports = __toCommonJS(Resource_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_Sales = require("../../../../Sales");
var import_resourceDisplay = __toESM(require("../../resourceDisplay"));
var import_utils2 = require("../../../utils");
var import_index = require("./index.less");
var Resource = () => {
  var _a, _b, _c, _d, _e;
  const { data } = (0, import_Sales.useSales)();
  const { getResourceList, selectResource } = (0, import_Sales.useResource)();
  const { createCartItem } = (0, import_Sales.useCart)();
  const { nextStep } = (0, import_Sales.useStep)();
  (0, import_react.useEffect)(() => {
    var _a2, _b2, _c2;
    const resourceList = ((_a2 = data == null ? void 0 : data.resourceData) == null ? void 0 : _a2.resourceList) || [];
    if ((resourceList == null ? void 0 : resourceList.length) <= 0) {
      return;
    }
    const resourceListChildren = ((_b2 = resourceList == null ? void 0 : resourceList[0]) == null ? void 0 : _b2.children) || [];
    if ((resourceList == null ? void 0 : resourceList.length) === 1 && (resourceListChildren == null ? void 0 : resourceListChildren.length) === 1 && ((_c2 = data == null ? void 0 : data.stepData) == null ? void 0 : _c2.isAutoOperate)) {
      createCartItem();
      selectResource(resourceListChildren[0]);
      nextStep();
    }
  }, [(_a = data == null ? void 0 : data.resourceData) == null ? void 0 : _a.resourceList]);
  const handleClick = (item) => {
    createCartItem();
    selectResource(item);
    nextStep();
  };
  const renderItem = (item) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_resourceDisplay.default,
      {
        mode: "campus",
        dataSource: item,
        direction: "vertical",
        shape: "square",
        bordered: false,
        borderRadius: 8,
        padding: 8,
        onClick: () => handleClick(item)
      }
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `event-interface-resource-wrap ${(0, import_utils.isMobile)() ? "event-interface-resource-mobile-wrap" : ""}`
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "title" }, import_utils.locales.getText("pisell2.event.select.campus")((0, import_utils2.resourceTitle)(data))),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "content" }, !((_c = (_b = data == null ? void 0 : data.resourceData) == null ? void 0 : _b.resourceList) == null ? void 0 : _c.length) ? /* @__PURE__ */ import_react.default.createElement(import_materials.Skeleton, { loading: true, active: true, paragraph: { rows: 3 } }) : (_e = (_d = data == null ? void 0 : data.resourceData) == null ? void 0 : _d.resourceList) == null ? void 0 : _e.map((item, index) => {
      return /* @__PURE__ */ import_react.default.createElement("div", { key: index, className: "content-item" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "content-title" }, item == null ? void 0 : item.title), /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellViewGrid,
        {
          dataSource: item == null ? void 0 : item.children,
          columns: (0, import_utils.isMobile)() ? 1 : 3,
          verticalGap: 20,
          horizontalGap: 20,
          loading: false,
          renderItem,
          className: "content-grid"
        }
      ));
    }))
  );
};
var Resource_default = Resource;
