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/Event/index.tsx
var Event_exports = {};
__export(Event_exports, {
  default: () => Event_default
});
module.exports = __toCommonJS(Event_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_Sales = require("../../../../Sales");
var import_bookingServiceList = __toESM(require("../../bookingServiceList"));
var import_bookingDetailModal = __toESM(require("../../bookingDetailModal"));
var import_index = require("./index.less");
var import_useLoginUser = __toESM(require("../../../../../hooks/useLoginUser"));
var Event = () => {
  var _a, _b;
  const { eventData, selectEvent, getEventList, getEventListByTitle } = (0, import_Sales.useEvent)();
  const { data } = (0, import_Sales.useSales)();
  const { changeAutoOperate } = (0, import_Sales.useStep)();
  const { onOpenEventDetail, open } = (0, import_Sales.useEventDetail)();
  const [lists, setLists] = (0, import_react.useState)();
  const customer = (0, import_useLoginUser.default)();
  const { appUtils } = (0, import_Sales.useCustomer)();
  (0, import_react.useEffect)(() => {
    var _a2;
    const eventList = (eventData == null ? void 0 : eventData.eventList) || [];
    setLists(eventList);
    if ((eventList == null ? void 0 : eventList.length) === 1 && ((_a2 = data == null ? void 0 : data.stepData) == null ? void 0 : _a2.isAutoOperate)) {
      selectEvent(eventList[0]);
      onOpenEventDetail(eventList[0]);
      changeAutoOperate(false);
    }
  }, [eventData == null ? void 0 : eventData.eventList]);
  (0, import_react.useEffect)(() => {
    var _a2, _b2, _c, _d, _e;
    const id = (_b2 = (_a2 = data == null ? void 0 : data.resourceData) == null ? void 0 : _a2.currentResourceItem) == null ? void 0 : _b2.id;
    if (!id) return;
    const history = ((_c = appUtils == null ? void 0 : appUtils.getHistory) == null ? void 0 : _c.call(appUtils)) || {};
    const query = (_d = history == null ? void 0 : history.location) == null ? void 0 : _d.query;
    const params = {
      event_item_resource_id: id,
      skip: 1,
      num: 100,
      customer_id: customer == null ? void 0 : customer.id,
      open_quotation: 1
    };
    if (query == null ? void 0 : query.ids) {
      params.ids = (_e = query == null ? void 0 : query.ids) == null ? void 0 : _e.split(",");
    }
    getEventList.run(params);
  }, [(_b = (_a = data == null ? void 0 : data.resourceData) == null ? void 0 : _a.currentResourceItem) == null ? void 0 : _b.id, customer == null ? void 0 : customer.id]);
  const handleClick = (item) => {
    selectEvent(item);
    onOpenEventDetail(item);
  };
  const handleSearch = (e) => {
    var _a2;
    const value = (_a2 = e.target) == null ? void 0 : _a2.value;
    const events = getEventListByTitle(value);
    setLists(events);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `event-interface-service-wrap ${(0, import_utils.isMobile)() ? "event-interface-service-mobile-wrap" : ""}`
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Skeleton,
      {
        active: true,
        loading: getEventList.loading,
        style: { padding: "16px" }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_bookingServiceList.default,
        {
          dataSource: lists,
          showSearch: true,
          showCategory: false,
          showImage: true,
          onClick: handleClick,
          onSearch: handleSearch,
          placeholder: import_utils.locales.getText("pisell2.event.search"),
          isShowEmpty: !getEventList.loading,
          description: import_utils.locales.getText("pisell2.event.empty.event")
        }
      )
    )
  ), /* @__PURE__ */ import_react.default.createElement(import_bookingDetailModal.default, { open }));
};
var Event_default = Event;
