import { useSales } from "../../../../../businessModel/SalesModel/Sales/index.js";
import { useStep } from "../../../../Sales/Step/index.js";
import { useCart } from "../../../../Sales/Cart/index.js";
import { useResource } from "../../../../Sales/Resource/index.js";
import { resourceTitle } from "../../../utils.js";
import PisellResourceCard from "../../resourceDisplay/index.js";
import React, { useEffect } from "react";
import { isMobile, locales } from "@pisell/utils";
import { PisellViewGrid, Skeleton } from "@pisell/materials";
import "./index.less";
//#region src/components/eventBooking/components/Provider/Resource/index.tsx
const Resource = () => {
	var _data$resourceData2, _data$resourceData3, _data$resourceData4;
	const { data } = useSales();
	const { getResourceList, selectResource } = useResource();
	const { createCartItem } = useCart();
	const { nextStep } = useStep();
	useEffect(() => {
		var _data$resourceData, _resourceList$, _data$stepData;
		const resourceList = (data === null || data === void 0 || (_data$resourceData = data.resourceData) === null || _data$resourceData === void 0 ? void 0 : _data$resourceData.resourceList) || [];
		if ((resourceList === null || resourceList === void 0 ? void 0 : resourceList.length) <= 0) return;
		const resourceListChildren = (resourceList === null || resourceList === void 0 || (_resourceList$ = resourceList[0]) === null || _resourceList$ === void 0 ? void 0 : _resourceList$.children) || [];
		if ((resourceList === null || resourceList === void 0 ? void 0 : resourceList.length) === 1 && (resourceListChildren === null || resourceListChildren === void 0 ? void 0 : resourceListChildren.length) === 1 && (data === null || data === void 0 || (_data$stepData = data.stepData) === null || _data$stepData === void 0 ? void 0 : _data$stepData.isAutoOperate)) {
			createCartItem();
			selectResource(resourceListChildren[0]);
			nextStep();
		}
	}, [data === null || data === void 0 || (_data$resourceData2 = data.resourceData) === null || _data$resourceData2 === void 0 ? void 0 : _data$resourceData2.resourceList]);
	/**
	* @title: 选择资源
	* @description:
	* @param {any} item
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-15 18:08
	*/
	const handleClick = (item) => {
		createCartItem();
		selectResource(item);
		nextStep();
	};
	/**
	* @title: 渲染内容
	* @description:
	* @param {any} item
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-15 11:30
	*/
	const renderItem = (item) => {
		return /* @__PURE__ */ React.createElement(PisellResourceCard, {
			mode: "campus",
			dataSource: item,
			direction: "vertical",
			shape: "square",
			bordered: false,
			borderRadius: 8,
			padding: 8,
			onClick: () => handleClick(item)
		});
	};
	return /* @__PURE__ */ React.createElement("div", { className: `event-interface-resource-wrap ${isMobile() ? "event-interface-resource-mobile-wrap" : ""}` }, /* @__PURE__ */ React.createElement("span", { className: "title" }, locales.getText("pisell2.event.select.campus")(resourceTitle(data))), /* @__PURE__ */ React.createElement("div", { className: "content" }, !(data === null || data === void 0 || (_data$resourceData3 = data.resourceData) === null || _data$resourceData3 === void 0 || (_data$resourceData3 = _data$resourceData3.resourceList) === null || _data$resourceData3 === void 0 ? void 0 : _data$resourceData3.length) ? /* @__PURE__ */ React.createElement(Skeleton, {
		loading: true,
		active: true,
		paragraph: { rows: 3 }
	}) : data === null || data === void 0 || (_data$resourceData4 = data.resourceData) === null || _data$resourceData4 === void 0 || (_data$resourceData4 = _data$resourceData4.resourceList) === null || _data$resourceData4 === void 0 ? void 0 : _data$resourceData4.map((item, index) => {
		return /* @__PURE__ */ React.createElement("div", {
			key: index,
			className: "content-item"
		}, /* @__PURE__ */ React.createElement("span", { className: "content-title" }, item === null || item === void 0 ? void 0 : item.title), /* @__PURE__ */ React.createElement(PisellViewGrid, {
			dataSource: item === null || item === void 0 ? void 0 : item.children,
			columns: isMobile() ? 1 : 3,
			verticalGap: 20,
			horizontalGap: 20,
			loading: false,
			renderItem,
			className: "content-grid"
		}));
	})));
};
//#endregion
export { Resource as default };
