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/products/index.tsx
var products_exports = {};
__export(products_exports, {
  default: () => products_default
});
module.exports = __toCommonJS(products_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_CurrentDay = __toESM(require("../components/CurrentDay"));
var import_list = __toESM(require("./list"));
var import_ProductDetailDrawer = __toESM(require("./ProductDetailDrawer"));
var import_model = require("../model");
var import_serve = require("./serve");
var import_utils = require("./utils");
var import_index = require("./index.less");
var Products = () => {
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const { products, currentSelectDayDetail } = state;
  const _getProducts = (0, import_ahooks.useRequest)(import_serve.getProductList, {
    manual: true
  });
  (0, import_react.useEffect)(() => {
    dispatch({
      type: "setProducts",
      payload: {
        list: (0, import_utils.formatProductSchedules)(
          _getProducts.data || [],
          state.schedules.scheduleMap
        )
      }
    });
  }, [_getProducts.data, state.schedules.scheduleMap]);
  const _init = () => {
    dispatch({
      type: "setProducts",
      payload: {
        search: "",
        currentProduct: null,
        openProductDetailDrawer: false,
        openAddSchedulesDrawer: false
      }
    });
    if (currentSelectDayDetail && (!currentSelectDayDetail.scheduleIds || !currentSelectDayDetail.scheduleIds.length)) {
      _getProducts.mutate([]);
    } else {
      _getProducts.run({
        skip: 1,
        num: 500,
        // extension_type: ["normal"],
        with: ["category"],
        status: "published",
        open_quotation: 1,
        with_schedule: true,
        schedule: 1,
        schedule_ids: currentSelectDayDetail ? currentSelectDayDetail.scheduleIds || [] : void 0
      });
    }
  };
  (0, import_react.useEffect)(() => {
    _init();
  }, [currentSelectDayDetail]);
  const handleClose = () => {
    dispatch({
      type: "setState",
      payload: {
        currentSelectDayDetail: null
      }
    });
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-component-products" }, /* @__PURE__ */ import_react.default.createElement(
    import_CurrentDay.default,
    {
      onClose: handleClose,
      currentDay: currentSelectDayDetail == null ? void 0 : currentSelectDayDetail.date
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_list.default, { loading: _getProducts.loading, list: products.list }), /* @__PURE__ */ import_react.default.createElement(import_ProductDetailDrawer.default, null));
};
var products_default = Products;
