import { _objectSpread2 } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import dayjs from "dayjs";
//#region src/components/ticketBooking/components/bookingDataPanel/bookingList/utils.ts
const formatShowList = (list, options) => {
	const { search, listSelectType, sort } = options;
	let showList = [];
	list.forEach((item) => {
		let searchBol = true;
		let typeBol = true;
		if (search) searchBol = JSON.stringify(item).includes(search);
		if (listSelectType) {
			if (listSelectType === "all") typeBol = true;
			else if (listSelectType === "notStarted") typeBol = [
				"new",
				"confirmed",
				"arrived"
			].includes(item.appointment_status);
			else if (listSelectType === "started") typeBol = ["started"].includes(item.appointment_status);
			else if (listSelectType === "finished") typeBol = ["completed"].includes(item.appointment_status);
			else if (listSelectType === "canceled") typeBol = ["cancelled"].includes(item.appointment_status);
		}
		if (searchBol && typeBol) {
			var _item$order, _item$order2, _item$order3;
			showList.push(_objectSpread2(_objectSpread2({}, item), {}, {
				startDateTime: `${item.start_date} ${item.start_time}`,
				endDateTime: `${item.end_date} ${item.end_time}`,
				total_amount: item === null || item === void 0 || (_item$order = item.order) === null || _item$order === void 0 ? void 0 : _item$order.total_amount,
				customer: (item === null || item === void 0 || (_item$order2 = item.order) === null || _item$order2 === void 0 || (_item$order2 = _item$order2.customer) === null || _item$order2 === void 0 || (_item$order2 = _item$order2.display_name) === null || _item$order2 === void 0 ? void 0 : _item$order2.trim()) || ((item === null || item === void 0 || (_item$order3 = item.order) === null || _item$order3 === void 0 || (_item$order3 = _item$order3.customer) === null || _item$order3 === void 0 ? void 0 : _item$order3.nickname) || "").trim()
			}));
		}
	});
	if (sort) {
		const [key, order] = sort.split(":");
		showList = showList.sort((a, b) => {
			let valueA, valueB;
			if (["startDateTime", "created_at"].includes(key)) {
				valueA = dayjs(a[key]);
				valueB = dayjs(b[key]);
			} else {
				valueA = a[key];
				valueB = b[key];
			}
			if (order === "asc") {
				if (valueA < valueB) return -1;
				if (valueA > valueB) return 1;
			} else {
				if (valueA > valueB) return -1;
				if (valueA < valueB) return 1;
			}
			return 0;
		});
	}
	return showList;
};
const getBookingType = (record) => {
	if (record.parent_id > 0 && record.item_type !== "recurring_booking") return "pisell2";
	return "pisell1";
};
//#endregion
export { formatShowList, getBookingType };
