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/booking/info/hooks/useInfoHolder.ts
var useInfoHolder_exports = {};
__export(useInfoHolder_exports, {
  default: () => useInfoHolder_default
});
module.exports = __toCommonJS(useInfoHolder_exports);
var import_ahooks = require("ahooks");
var import_react = require("react");
var import_useHolderConfig = __toESM(require("./useHolderConfig"));
var import_utils = require("../utils");
var import_useGetHolderList = __toESM(require("./useGetHolderList"));
var import_utils2 = require("../../info2/service/addService/utils");
var import_utilsByBooking = require("../../info2/utilsByBooking");
var useInfoHolder = (state, dispatch) => {
  var _a, _b, _c, _d;
  const detailRef = (0, import_react.useRef)();
  const editNormalServiceRef = (0, import_react.useRef)(null);
  const { holder, isFormSubject, appointment_subject } = (0, import_useHolderConfig.default)(state);
  const getHolders = (0, import_useGetHolderList.default)(state, dispatch);
  (0, import_react.useEffect)(() => {
    if (isFormSubject) {
      getHolders();
    }
  }, [appointment_subject, holder, (_b = (_a = state.client) == null ? void 0 : _a.value) == null ? void 0 : _b.id]);
  const appointment_card = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    return ((_c2 = (_b2 = (_a2 = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _a2.config) == null ? void 0 : _b2.information_tab) == null ? void 0 : _c2.appointment_card) || {
      quick_time: 1
    };
  }, [(_d = (_c = state == null ? void 0 : state.bookingConfig) == null ? void 0 : _c.config) == null ? void 0 : _d.information_tab]);
  const showAddTimeModal = (0, import_react.useMemo)(() => {
    return (0, import_utils.isOpenAddTime)(state);
  }, [state, appointment_card.quick_time]);
  const handleEdit = (0, import_ahooks.useMemoizedFn)((cacheItem, type) => {
    var _a2, _b2, _c2;
    const isNoSpecAndPackage = (0, import_utilsByBooking.getIsNoSpecAndPackage)(cacheItem);
    if (isNoSpecAndPackage) {
      (_a2 = editNormalServiceRef.current) == null ? void 0 : _a2.init(cacheItem);
    } else {
      (_c2 = (_b2 = detailRef.current) == null ? void 0 : _b2.init) == null ? void 0 : _c2.call(_b2, cacheItem, false, type === "edit_product");
    }
  });
  const dispatchService = (type, payload) => {
    dispatch({
      type,
      payload: { ...payload }
    });
  };
  const handleAction = (0, import_ahooks.useMemoizedFn)((dataSource) => {
    const cacheItem = (0, import_utils2.getProductExtend)({
      cacheItem: { ...dataSource._origin, new: 0 },
      state
    });
    dispatch({
      type: "setService",
      payload: {
        addTimeModal: true,
        cacheItem
      }
    });
  });
  return {
    detailRef,
    handleEdit,
    dispatchService,
    handleAction,
    showAddTimeModal,
    editNormalServiceRef
  };
};
var useInfoHolder_default = useInfoHolder;
