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/list/index.tsx
var list_exports = {};
__export(list_exports, {
  default: () => list_default
});
module.exports = __toCommonJS(list_exports);
var import_react = __toESM(require("react"));
var import_tabProduct = __toESM(require("../../../tabProduct"));
var import_Search = __toESM(require("../../components/Search"));
var import_utils = require("../utils");
var import_model = require("../../model");
var import_emptyBooking = __toESM(require("../../../booking/components/emptyBooking"));
var import_ProductItem = __toESM(require("./ProductItem"));
var import_antd = require("antd");
var import_index = require("./index.less");
var import_utils2 = require("@pisell/utils");
var ProductList = ({ loading, list }) => {
  const [search, setSearch] = (0, import_react.useState)("");
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const { products, currentSelectDayDetail } = state;
  const renderList = (0, import_react.useMemo)(() => {
    const isIncludes = (str) => {
      return str.toLowerCase().indexOf(search.toLowerCase()) !== -1;
    };
    if (currentSelectDayDetail) {
      return list.filter((item) => isIncludes(item.title));
    }
    return (0, import_utils.formatProductListByCategory)(
      list,
      search ? (item) => isIncludes(item.title) : void 0
    );
  }, [search, list, currentSelectDayDetail]);
  console.log("state.scheduleMap", renderList);
  const searchChange = (e) => {
    setSearch(e);
  };
  const onClickItem = (item) => {
    let newData = {
      products: {
        ...products,
        currentProduct: item,
        openProductDetailDrawer: !currentSelectDayDetail
      }
    };
    if (currentSelectDayDetail) {
      newData = {
        tabKey: "schedules",
        products: {
          ...products,
          currentProduct: item,
          openProductDetailDrawer: !currentSelectDayDetail
        }
      };
    }
    dispatch({
      type: "setState",
      payload: newData
    });
  };
  const empty = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_emptyBooking.default,
      {
        description: import_utils2.locales.getText("pisell2.text.products.no-products")
      }
    );
  }, []);
  const listDom = (0, import_react.useMemo)(() => {
    if (currentSelectDayDetail) {
      return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-component-products-list-day" }, renderList.map((item) => {
        return /* @__PURE__ */ import_react.default.createElement(
          import_ProductItem.default,
          {
            key: item.id,
            item,
            onClickItem,
            layout: "day"
          }
        );
      }));
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_tabProduct.default,
      {
        scrollDom: ".pisell-lowcode__schedules-component-products",
        list: renderList,
        renderItem: (item) => {
          return /* @__PURE__ */ import_react.default.createElement(import_ProductItem.default, { key: item.id, item, onClickItem });
        }
      }
    );
  }, [currentSelectDayDetail, renderList, onClickItem]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Skeleton,
    {
      className: "pisell-lowcode__schedules-component-products-list-wrap",
      round: true,
      active: true,
      loading
    },
    !list.length ? empty : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
      import_Search.default,
      {
        value: search,
        onChange: searchChange,
        style: { marginTop: 16 }
      }
    ), renderList.length ? listDom : empty)
  );
};
var list_default = ProductList;
