const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_serve = require("../../../serve.js");
const require_utils = require("./utils.js");
const require_constants = require("../constants.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/ticketBooking/components/bookingDataPanel/bookingList/index.tsx
const BookingList = (0, react.forwardRef)((props, ref) => {
	const { bookingTimeStartBetween, onBookingClick, bookingId } = props;
	/** 原始列表 */
	const [bookingList, setBookingList] = (0, react.useState)([]);
	/** 搜索 本地搜索 */
	const [search, setSearch] = (0, react.useState)("");
	/** 排序 本地排序 */
	const [sort, setSort] = (0, react.useState)("");
	/** 列表筛选类型 */
	const [listSelectType, setListSelectType] = (0, react.useState)("all");
	/** 是否显示弹窗 */
	const [open, setOpen] = (0, react.useState)(false);
	const params = (0, react.useMemo)(() => {
		return {
			["with"]: [
				"order",
				"order.customer",
				"contacts",
				"item",
				"appointmentForm.formRecord",
				"holder.formRecord"
			],
			booking_time_start_between: bookingTimeStartBetween,
			child_booking: 1,
			skip: 1,
			num: 1e3
		};
	}, [bookingTimeStartBetween]);
	(0, react.useEffect)(() => {
		getBookingList(params);
	}, [params]);
	(0, react.useImperativeHandle)(ref, () => ({ refresh: () => {
		getBookingList(params);
	} }));
	const showList = (0, react.useMemo)(() => {
		return require_utils.formatShowList(bookingList, {
			search,
			listSelectType,
			sort
		});
	}, [
		bookingList,
		search,
		listSelectType,
		sort
	]);
	const getBookingList = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (params) {
			setBookingList((yield require_serve.getBookingList2(params)).list);
		});
		return function getBookingList(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	const sortProps = (0, react.useMemo)(() => {
		return {
			list: [
				{
					label: _pisell_utils.locales.getText("pisell2.ticket-booking.start-time"),
					name: "startDateTime",
					type: "date",
					isCustom: false
				},
				{
					label: _pisell_utils.locales.getText("pisell2.ticket-booking.create-time"),
					name: "created_at",
					type: "date",
					isCustom: false
				},
				{
					label: _pisell_utils.locales.getText("pisell2.ticket-booking.customer"),
					name: "customer",
					type: "string",
					isCustom: false
				},
				{
					label: _pisell_utils.locales.getText("pisell2.ticket-booking.total"),
					name: "total_amount",
					type: "number",
					isCustom: false
				}
			],
			value: sort,
			onChange: (value) => {
				setSort(value);
			}
		};
	}, [sort]);
	const handleBookingClick = (booking) => {
		if (require_utils.getBookingType(booking) === "pisell1") {
			setOpen(true);
			return;
		}
		onBookingClick(booking);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-ticket-booking-list" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-ticket-booking-list-header" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
		size: "large",
		placeholder: _pisell_utils.locales.getText("pisell2.ticket-booking.search"),
		value: search,
		onChange: (e) => setSearch(e.target.value)
	}), /* @__PURE__ */ react.default.createElement(_pisell_materials.Sort, sortProps)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-ticket-booking-list-content" }, /* @__PURE__ */ react.default.createElement(BookingListTable, {
		list: showList,
		onBookingClick: handleBookingClick,
		bookingId
	})), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal.Information, {
		title: _pisell_utils.locales.getText("pisell2.ticket-booking.inform"),
		describe: _pisell_utils.locales.getText("pisell2.ticket-booking.check-management"),
		okText: _pisell_utils.locales.getText("pisell2.ticket-booking.confirm"),
		open,
		okVisible: true,
		footerDivider: true,
		closable: true,
		cancelVisible: false,
		onOk: () => {
			setOpen(false);
		},
		onCancel: () => {
			setOpen(false);
		}
	}));
});
const BookingListTable = (0, react.memo)((props) => {
	const { list, onBookingClick, bookingId } = props;
	const renderCustomerName = (record) => {
		var _record$order, _record$order2, _record$order3, _record$order4, _record$order5, _record$order6;
		const display_name = ((record === null || record === void 0 || (_record$order = record.order) === null || _record$order === void 0 || (_record$order = _record$order.customer) === null || _record$order === void 0 ? void 0 : _record$order.display_name) || "").trim();
		const nickname = ((record === null || record === void 0 || (_record$order2 = record.order) === null || _record$order2 === void 0 || (_record$order2 = _record$order2.customer) === null || _record$order2 === void 0 ? void 0 : _record$order2.nickname) || "").trim();
		if (!(record === null || record === void 0 || (_record$order3 = record.order) === null || _record$order3 === void 0 ? void 0 : _record$order3.customer) || [0, 1].includes(record === null || record === void 0 || (_record$order4 = record.order) === null || _record$order4 === void 0 || (_record$order4 = _record$order4.customer) === null || _record$order4 === void 0 ? void 0 : _record$order4.id)) return /* @__PURE__ */ react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-walk-in" }, "Walk-In");
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-name" }, display_name || nickname), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-contact" }, record === null || record === void 0 || (_record$order5 = record.order) === null || _record$order5 === void 0 || (_record$order5 = _record$order5.customer) === null || _record$order5 === void 0 ? void 0 : _record$order5.phone), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-ticket-booking-list-customer-contact" }, record === null || record === void 0 || (_record$order6 = record.order) === null || _record$order6 === void 0 || (_record$order6 = _record$order6.customer) === null || _record$order6 === void 0 ? void 0 : _record$order6.email));
	};
	const renderPaymentStatus = (record) => {
		var _record$order7, _record$order8;
		return /* @__PURE__ */ react.default.createElement("div", {
			className: "pisell-ticket-booking-list-payment-status",
			style: { backgroundColor: require_constants.payStatusColorMap[(_record$order7 = record.order) === null || _record$order7 === void 0 ? void 0 : _record$order7.payment_status] }
		}, require_constants.getPayStatusMap()[(_record$order8 = record.order) === null || _record$order8 === void 0 ? void 0 : _record$order8.payment_status]);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-ticket-booking-list-table" }, !list.length ? /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellEmpty, null) : list.map((item) => {
		var _item$order, _item$order2;
		const isActive = bookingId === item.order.id;
		return /* @__PURE__ */ react.default.createElement("div", {
			key: item.id,
			className: "pisell-ticket-booking-list-table-item",
			onClick: () => onBookingClick(item),
			style: {
				backgroundColor: isActive ? "#fff" : "rgba(255, 255, 255, 0.07)",
				zIndex: isActive ? 10 : 1,
				color: isActive ? "#000" : "#fff"
			}
		}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-ticket-booking-list-table-item-left" }, /* @__PURE__ */ react.default.createElement("div", null, item.start_time), /* @__PURE__ */ react.default.createElement("div", null, renderCustomerName(item))), /* @__PURE__ */ react.default.createElement("div", null, renderPaymentStatus(item)), /* @__PURE__ */ react.default.createElement("div", null, `${(item === null || item === void 0 || (_item$order = item.order) === null || _item$order === void 0 ? void 0 : _item$order.currency_symbol) || "-"}${(item === null || item === void 0 || (_item$order2 = item.order) === null || _item$order2 === void 0 ? void 0 : _item$order2.total_amount) || "0.00"}`));
	}));
});
//#endregion
exports.default = BookingList;
