require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../../info2/service/addService/utils.js");
const require_utils$1 = require("../service2/utils.js");
const require_utils$2 = require("../utils.js");
const require_useHolderConfig = require("./useHolderConfig.js");
const require_useGetHolderList = require("./useGetHolderList.js");
const require_openNormalService = require("../../info2/service/openNormalService.js");
let react = require("react");
let ahooks = require("ahooks");
//#region src/components/booking/info/hooks/useInfoHolder.ts
const useInfoHolder = (state, dispatch) => {
	var _state$client, _state$bookingConfig2;
	const detailRef = (0, react.useRef)();
	const editNormalServiceRef = (0, react.useRef)(null);
	const { holder, isFormSubject, appointment_subject } = require_useHolderConfig.default(state);
	const getHolders = require_useGetHolderList.default(state, dispatch);
	(0, react.useEffect)(() => {
		if (isFormSubject) getHolders();
	}, [
		appointment_subject,
		holder,
		(_state$client = state.client) === null || _state$client === void 0 || (_state$client = _state$client.value) === null || _state$client === void 0 ? void 0 : _state$client.id
	]);
	const showAddTimeModal = (0, react.useMemo)(() => {
		return require_utils$2.isOpenAddTime(state);
	}, [state, (0, react.useMemo)(() => {
		var _state$bookingConfig;
		return (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.information_tab) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_card) || { quick_time: 1 };
	}, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.information_tab]).quick_time]);
	const handleEdit = (0, ahooks.useMemoizedFn)((cacheItem, type) => {
		if (require_utils$1.isNormalProductByDurationSchedule(cacheItem)) {
			const openNormalService = require_openNormalService.getOpenNormalServiceHandler();
			if (openNormalService) openNormalService({
				mode: "edit",
				cacheItem,
				callback: () => {}
			});
		} else {
			var _detailRef$current, _detailRef$current$in;
			(_detailRef$current = detailRef.current) === null || _detailRef$current === void 0 || (_detailRef$current$in = _detailRef$current.init) === null || _detailRef$current$in === void 0 || _detailRef$current$in.call(_detailRef$current, cacheItem, false, type === "edit_product");
		}
	});
	const dispatchService = (type, payload) => {
		dispatch({
			type,
			payload: require_objectSpread2._objectSpread2({}, payload)
		});
	};
	return {
		detailRef,
		handleEdit,
		dispatchService,
		handleAction: (0, ahooks.useMemoizedFn)((dataSource) => {
			dispatch({
				type: "setService",
				payload: {
					addTimeModal: true,
					cacheItem: require_utils.getProductExtend({
						cacheItem: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, dataSource._origin), {}, { new: 0 }),
						state
					})
				}
			});
		}),
		showAddTimeModal,
		editNormalServiceRef
	};
};
//#endregion
exports.default = useInfoHolder;
