const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../../businessModel/SalesModel/Sales/index.js");
const require_index$1 = require("../../../../Sales/Step/index.js");
const require_index$2 = require("../../../../Sales/Cart/index.js");
const require_index$3 = require("../../../../Sales/Resource/index.js");
const require_utils = require("../../../utils.js");
const require_index$4 = require("../../resourceDisplay/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/components/eventBooking/components/Provider/Resource/index.tsx
const Resource = () => {
	var _data$resourceData2, _data$resourceData3, _data$resourceData4;
	const { data } = require_index.useSales();
	const { getResourceList, selectResource } = require_index$3.useResource();
	const { createCartItem } = require_index$2.useCart();
	const { nextStep } = require_index$1.useStep();
	(0, react.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.default.createElement(require_index$4.default, {
			mode: "campus",
			dataSource: item,
			direction: "vertical",
			shape: "square",
			bordered: false,
			borderRadius: 8,
			padding: 8,
			onClick: () => handleClick(item)
		});
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: `event-interface-resource-wrap ${(0, _pisell_utils.isMobile)() ? "event-interface-resource-mobile-wrap" : ""}` }, /* @__PURE__ */ react.default.createElement("span", { className: "title" }, _pisell_utils.locales.getText("pisell2.event.select.campus")(require_utils.resourceTitle(data))), /* @__PURE__ */ react.default.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.default.createElement(_pisell_materials.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.default.createElement("div", {
			key: index,
			className: "content-item"
		}, /* @__PURE__ */ react.default.createElement("span", { className: "content-title" }, item === null || item === void 0 ? void 0 : item.title), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellViewGrid, {
			dataSource: item === null || item === void 0 ? void 0 : item.children,
			columns: (0, _pisell_utils.isMobile)() ? 1 : 3,
			verticalGap: 20,
			horizontalGap: 20,
			loading: false,
			renderItem,
			className: "content-grid"
		}));
	})));
};
//#endregion
exports.default = Resource;
