import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { getServiceTime } from "../../utils.js";
import Divider from "../Divider/index.js";
import Like from "./components/Like/index.js";
import SelectResource from "./components/SelectResource/index.js";
import SelectHolder from "./components/SelectHolder/index.js";
import SelectHolderMultiple from "./components/SelectHolderMultiple/index.js";
import React, { useCallback, useMemo } from "react";
import "./index.less";
//#region src/components/productCard/components/Time/index.tsx
const prefix = "pisell-lowcode-";
const Time = ({ item, isShowHolder, onLike, isShowChangeResource, changeResource, changeHolder, isShowChangeHolder, holderMode, onAddHolder, isShowAddHolderButton, onClearHolder, onClearResource }) => {
	const { start_date, end_date, holder_title, resource_id, relation_form_name, like_status, resources, is_hide_like, holder_id, holders, multiResources, addHolderButtonText, isErrorHolder, allowClearHolder, allowClearResource, isErrorResource, resourceErrorText, isMultipleResource, isShowChangeHolder: itemIsShowChangeHolder = true, holderMode: itemHolderMode, holderMaxCount } = item;
	const holderCom = useMemo(() => {
		if (!isShowHolder) return null;
		if (isShowChangeHolder && itemIsShowChangeHolder) {
			const Cpt = (itemHolderMode || holderMode) === "multiple" ? SelectHolderMultiple : SelectHolder;
			return /* @__PURE__ */ React.createElement(Cpt, {
				holderMaxCount,
				lists: holders,
				value: holder_id,
				onChange: changeHolder,
				holderMode: itemHolderMode || holderMode,
				isShowAddHolderButton,
				onAddHolder,
				addHolderButtonText,
				onClearHolder,
				isErrorHolder,
				allowClear: allowClearHolder
			});
		}
		if (holder_title) return /* @__PURE__ */ React.createElement("div", { className: `${prefix}product-holder-wrap` }, holder_title);
	}, [
		isShowHolder,
		holder_id,
		holder_title,
		holderMode,
		holders,
		isShowAddHolderButton,
		isShowChangeHolder,
		isErrorHolder,
		addHolderButtonText,
		allowClearHolder,
		itemIsShowChangeHolder,
		itemHolderMode,
		holderMaxCount
	]);
	const likeCom = useCallback((status, item) => {
		return /* @__PURE__ */ React.createElement(Like, {
			isShowChangeResource,
			style: { marginRight: 4 },
			status,
			onLike: (e) => {
				onLike(_objectSpread2(_objectSpread2({}, item), {}, { like_status: e }));
			}
		});
	}, [isShowChangeResource]);
	const resourceCom = useCallback((item) => {
		if ((item === null || item === void 0 ? void 0 : item.hasOwnProperty("isShowChangeResource")) && !item.isShowChangeResource || !isShowChangeResource) return item === null || item === void 0 ? void 0 : item.name;
		return /* @__PURE__ */ React.createElement(SelectResource, _objectSpread2(_objectSpread2({}, item), {}, {
			lists: item === null || item === void 0 ? void 0 : item.lists,
			value: item === null || item === void 0 ? void 0 : item.id,
			onChange: changeResource,
			onClearResource,
			allowClear: item === null || item === void 0 ? void 0 : item.allowClearResource,
			isErrorResource: item === null || item === void 0 ? void 0 : item.isErrorResource,
			resourceErrorText: item === null || item === void 0 ? void 0 : item.resourceErrorText,
			resourceMode: item.resourceMode,
			maxLength: item.maxLength
		}));
	}, [isShowChangeResource]);
	const likeAndResourceCom = useMemo(() => {
		if (isMultipleResource) {
			if ((multiResources === null || multiResources === void 0 ? void 0 : multiResources.length) > 0) return multiResources.map((resourceItem) => {
				return /* @__PURE__ */ React.createElement("div", { key: (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.id) + (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem._id) }, (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.id) && !is_hide_like && !resourceItem.is_hide_like ? likeCom(resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.status, resourceItem) : null, resourceCom(resourceItem));
			});
			return null;
		}
		const _resourceCom = resourceCom({
			name: relation_form_name,
			id: resource_id,
			lists: resources,
			allowClearResource,
			isErrorResource,
			resourceErrorText
		});
		return resource_id && !is_hide_like || _resourceCom ? /* @__PURE__ */ React.createElement(React.Fragment, null, resource_id && !is_hide_like ? likeCom(like_status, item) : null, _resourceCom) : null;
	}, [
		multiResources,
		resource_id,
		resources,
		relation_form_name,
		is_hide_like,
		isShowChangeResource,
		isMultipleResource,
		allowClearResource,
		isErrorResource,
		resourceErrorText
	]);
	return useMemo(() => {
		return start_date && end_date || holderCom || likeAndResourceCom;
	}, [
		start_date,
		holderCom,
		likeAndResourceCom
	]) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Divider, null), /* @__PURE__ */ React.createElement("div", { className: `${prefix}product-time-wrap` }, start_date && end_date ? /* @__PURE__ */ React.createElement("div", { className: `${prefix}product-date` }, getServiceTime(item, start_date)) : null, holderCom, likeAndResourceCom ? /* @__PURE__ */ React.createElement("div", { className: `${prefix}product-technician ${isShowChangeResource ? "pisell-lowcode-change-resource" : ""} ${(multiResources === null || multiResources === void 0 ? void 0 : multiResources.length) > 0 ? "pisell-lowcode-multi-resources" : ""}` }, likeAndResourceCom) : null)) : null;
};
//#endregion
export { Time as default };
