import useLoginUser from "../../../../../hooks/useLoginUser.js";
import { useSales } from "../../../../../businessModel/SalesModel/Sales/index.js";
import { useStep } from "../../../../Sales/Step/index.js";
import { useCustomer } from "../../../../Sales/Customer/index.js";
import { useEvent } from "../../../../Sales/Event/index.js";
import { useEventDetail } from "../../../../Sales/Event/Detail.js";
import BookingServiceList from "../../bookingServiceList/index.js";
import BookingDetailModal from "../../bookingDetailModal/index.js";
import React, { useEffect, useState } from "react";
import { Skeleton } from "antd";
import { isMobile, locales } from "@pisell/utils";
import "./index.less";
//#region src/components/eventBooking/components/Provider/Event/index.tsx
const Event = () => {
	var _data$resourceData2;
	const { eventData, selectEvent, getEventList, getEventListByTitle } = useEvent();
	const { data } = useSales();
	const { changeAutoOperate } = useStep();
	const { onOpenEventDetail, open } = useEventDetail();
	const [lists, setLists] = useState();
	const customer = useLoginUser();
	const { appUtils } = useCustomer();
	useEffect(() => {
		var _data$stepData;
		const eventList = (eventData === null || eventData === void 0 ? void 0 : eventData.eventList) || [];
		setLists(eventList);
		if ((eventList === null || eventList === void 0 ? void 0 : eventList.length) === 1 && (data === null || data === void 0 || (_data$stepData = data.stepData) === null || _data$stepData === void 0 ? void 0 : _data$stepData.isAutoOperate)) {
			selectEvent(eventList[0]);
			onOpenEventDetail(eventList[0]);
			changeAutoOperate(false);
		}
	}, [eventData === null || eventData === void 0 ? void 0 : eventData.eventList]);
	useEffect(() => {
		var _data$resourceData, _appUtils$getHistory, _history$location;
		const id = data === null || data === void 0 || (_data$resourceData = data.resourceData) === null || _data$resourceData === void 0 || (_data$resourceData = _data$resourceData.currentResourceItem) === null || _data$resourceData === void 0 ? void 0 : _data$resourceData.id;
		if (!id) return;
		const history = (appUtils === null || appUtils === void 0 || (_appUtils$getHistory = appUtils.getHistory) === null || _appUtils$getHistory === void 0 ? void 0 : _appUtils$getHistory.call(appUtils)) || {};
		const query = history === null || history === void 0 || (_history$location = history.location) === null || _history$location === void 0 ? void 0 : _history$location.query;
		const params = {
			event_item_resource_id: id,
			skip: 1,
			num: 100,
			customer_id: customer === null || customer === void 0 ? void 0 : customer.id,
			open_quotation: 1
		};
		if (query === null || query === void 0 ? void 0 : query.ids) {
			var _query$ids;
			params.ids = query === null || query === void 0 || (_query$ids = query.ids) === null || _query$ids === void 0 ? void 0 : _query$ids.split(",");
		}
		getEventList.run(params);
	}, [data === null || data === void 0 || (_data$resourceData2 = data.resourceData) === null || _data$resourceData2 === void 0 || (_data$resourceData2 = _data$resourceData2.currentResourceItem) === null || _data$resourceData2 === void 0 ? void 0 : _data$resourceData2.id, customer === null || customer === void 0 ? void 0 : customer.id]);
	/**
	* @title: 点击选择event
	* @description:
	* @param {any} item
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-15 22:06
	*/
	const handleClick = (item) => {
		selectEvent(item);
		onOpenEventDetail(item);
	};
	/**
	* @title: 搜索
	* @description:
	* @param {string} value
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-16 10:25
	*/
	const handleSearch = (e) => {
		var _e$target;
		setLists(getEventListByTitle((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value));
	};
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: `event-interface-service-wrap ${isMobile() ? "event-interface-service-mobile-wrap" : ""}` }, /* @__PURE__ */ React.createElement(Skeleton, {
		active: true,
		loading: getEventList.loading,
		style: { padding: "16px" }
	}, /* @__PURE__ */ React.createElement(BookingServiceList, {
		dataSource: lists,
		showSearch: true,
		showCategory: false,
		showImage: true,
		onClick: handleClick,
		onSearch: handleSearch,
		placeholder: locales.getText("pisell2.event.search"),
		isShowEmpty: !getEventList.loading,
		description: locales.getText("pisell2.event.empty.event")
	}))), /* @__PURE__ */ React.createElement(BookingDetailModal, { open }));
};
//#endregion
export { Event as default };
