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/selectModal/index.tsx
var selectModal_exports = {};
__export(selectModal_exports, {
  default: () => selectModal_default
});
module.exports = __toCommonJS(selectModal_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_antd = require("antd");
var import_SearchLg = __toESM(require("@pisell/icon/es/SearchLg"));
var import_addButton = __toESM(require("../booking/components/addButton"));
var import_drawer = __toESM(require("../booking/components/drawer"));
var import_tabProduct = __toESM(require("../tabProduct"));
var import_utils = require("../booking/utils");
var import_utils2 = require("@pisell/utils");
var import_index = require("./index.less");
var MAX_LENGTH = 999;
var SelectModal = (props) => {
  const {
    value,
    onChange,
    dataSource = [],
    renderValueItem,
    renderOptionItem,
    disabled,
    className,
    style,
    maxLength = MAX_LENGTH,
    buttonProps,
    drawerProps,
    tabProductProps,
    loading
  } = props;
  const [open, setOpen] = (0, import_react.useState)(false);
  const [search, setSearch] = (0, import_react.useState)("");
  const _value = (0, import_react.useMemo)(() => {
    return value || [];
  }, [value]);
  const onOpen = () => {
    setOpen(true);
  };
  const onClose = () => {
    setSearch("");
    setOpen(false);
  };
  const renderList = (0, import_react.useMemo)(() => {
    let _list = dataSource || [];
    const isIncludes = (str) => {
      return str.toLowerCase().indexOf(search.toLowerCase()) !== -1;
    };
    return (0, import_utils.formatProductListByCategory)(
      _list,
      search ? (item) => isIncludes(item.title) : void 0
    );
  }, [search, dataSource]);
  const onSelect = (item) => {
    onChange == null ? void 0 : onChange((0, import_utils2.changeArray)(_value, item, "id"));
    onClose();
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("pisell2-select-modal", className),
      style
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { active: true, round: true, loading }, _value.map((item) => {
      return renderValueItem == null ? void 0 : renderValueItem(item, (item2) => {
        onOpen();
      });
    })),
    _value.length < maxLength ? /* @__PURE__ */ import_react.default.createElement(import_addButton.default, { onClick: onOpen, ...buttonProps }) : null,
    /* @__PURE__ */ import_react.default.createElement(
      import_drawer.default,
      {
        open,
        onClose,
        header: /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-service-header" }, /* @__PURE__ */ import_react.default.createElement(
          import_antd.Input,
          {
            prefix: /* @__PURE__ */ import_react.default.createElement(import_SearchLg.default, null),
            style: { marginTop: 16, height: 44 },
            placeholder: "",
            allowClear: true,
            value: search,
            onChange: (e) => {
              setSearch(e.target.value);
            }
          }
        )),
        ...drawerProps
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-service-body" }, /* @__PURE__ */ import_react.default.createElement(
        import_tabProduct.default,
        {
          list: renderList,
          ...tabProductProps,
          renderItem: (item) => {
            return renderOptionItem == null ? void 0 : renderOptionItem(item, onSelect);
          }
        }
      ))
    )
  );
};
var selectModal_default = SelectModal;
