import { getServiceTime } from "../../../utils.js";
import Like from "../like/index.js";
import CollapsibleList from "../../../components/collapsibleList/index.js";
import { renderBundles } from "../../../components/collapsibleList/utils.js";
import Actions from "../actions/index.js";
import React, { useMemo } from "react";
import { Alert, Button } from "antd";
import { formatAmount, locales } from "@pisell/utils";
import { Iconfont } from "@pisell/materials";
import "./index.less";
//#region src/components/booking/info/service/serviceItem/index.tsx
const ServiceItem = ({ d, handleEditService, state, handleLike, resourceItem, errorMessage, handleDeleteService }) => {
	var _d$_extend3, _d$_extend4, _d$_extend5, _d$_extend6, _d$_extend7, _d$_extend8, _d$_extend9, _d$_extend$relation_d;
	let resourceName = (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.labelText) || d.relation_form_name;
	const isDiscount = useMemo(() => {
		var _d$_extend, _d$_extend2;
		return Number((_d$_extend = d._extend) === null || _d$_extend === void 0 ? void 0 : _d$_extend.total) != Number((_d$_extend2 = d._extend) === null || _d$_extend2 === void 0 ? void 0 : _d$_extend2.origin_total);
	}, [(_d$_extend3 = d._extend) === null || _d$_extend3 === void 0 ? void 0 : _d$_extend3.total, (_d$_extend4 = d._extend) === null || _d$_extend4 === void 0 ? void 0 : _d$_extend4.origin_total]);
	return /* @__PURE__ */ React.createElement("div", {
		key: d._id,
		className: "pisell-lowcode__booking-service-item",
		onClick: () => {
			handleEditService(d);
		}
	}, !state.channelDisabledEdit && /* @__PURE__ */ React.createElement("div", {
		className: "pisell-lowcode__booking-service-item-delete",
		onClick: (e) => {
			e.stopPropagation();
			handleDeleteService(d);
		}
	}, /* @__PURE__ */ React.createElement(Button, {
		type: "text",
		icon: /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-trash-01" })
	})), d.id || d.isCustomItem ? /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-title" }, d.title) : null, d._extend ? /* @__PURE__ */ React.createElement(React.Fragment, null, state.renderType !== "eventBooking" && /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-date" }, getServiceTime(d, state.date.value)), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-technician" }, d._extend.resource ? /* @__PURE__ */ React.createElement(Like, {
		style: { marginRight: 4 },
		status: d._extend.like_status,
		onChange: (e) => {
			handleLike(e, d);
		}
	}) : null, resourceName)) : null, (((_d$_extend5 = d._extend) === null || _d$_extend5 === void 0 || (_d$_extend5 = _d$_extend5.other) === null || _d$_extend5 === void 0 ? void 0 : _d$_extend5.bundle) || []).length ? /* @__PURE__ */ React.createElement(CollapsibleList, {
		border: true,
		list: ((_d$_extend6 = d._extend) === null || _d$_extend6 === void 0 || (_d$_extend6 = _d$_extend6.other) === null || _d$_extend6 === void 0 ? void 0 : _d$_extend6.bundle) || [],
		renderItem: (item) => renderBundles(item, state.amountSymbol)
	}) : null, d.id || d.isCustomItem ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-price-wrap" }, /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-service-item-price" }, formatAmount((_d$_extend7 = d._extend) === null || _d$_extend7 === void 0 ? void 0 : _d$_extend7.total, 2, state.amountSymbol)), isDiscount ? /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-service-item-original-price" }, formatAmount(d._extend.origin_total, 2, state.amountSymbol)) : null)) : null, isDiscount && ((_d$_extend8 = d._extend) === null || _d$_extend8 === void 0 ? void 0 : _d$_extend8.discount_reason) ? /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-discount-reason" }, /* @__PURE__ */ React.createElement("span", null, locales.getText("pisell2.text.discount-reason"), ":"), " ", (_d$_extend9 = d._extend) === null || _d$_extend9 === void 0 ? void 0 : _d$_extend9.discount_reason) : null, ((_d$_extend$relation_d = d._extend.relation_details) === null || _d$_extend$relation_d === void 0 ? void 0 : _d$_extend$relation_d.length) ? /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-relation-details" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-title" }, locales.getText("page.booking.text.sales")), d._extend.relation_details.map((item, index) => {
		return /* @__PURE__ */ React.createElement("div", {
			className: "pisell-lowcode__booking-service-item-relation-detail",
			key: item.id
		}, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-relation-detail-title" }, item.product_title), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__booking-service-item-relation-detail-info" }, /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-service-item-relation-detail-info-price" }, formatAmount(item.payment_price, 2, state.amountSymbol)), /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-service-item-relation-detail-info-unit" }, "x"), /* @__PURE__ */ React.createElement("span", { className: "pisell-lowcode__booking-service-item-relation-detail-info-quantity" }, item.product_quantity)));
	})) : null, /* @__PURE__ */ React.createElement(Actions, { currentService: d }), errorMessage ? /* @__PURE__ */ React.createElement(Alert, {
		message: errorMessage,
		type: "warning",
		showIcon: true,
		className: "pisell-lowcode__booking-service-item-error"
	}) : null);
};
//#endregion
export { ServiceItem as default };
