require("../../../_virtual/_rolldown/runtime.js");
const require_serve = require("../../orderList/serve.js");
let _pisell_utils = require("@pisell/utils");
//#region src/plus/pisellSalesManagement/config/order.ts
/**
* 获取支付状态映射
*/
const getPaymentStatusMap = () => ({
	authorized: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.authorized"),
	paid: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.paid"),
	partially_paid: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.partially_paid"),
	partially_refunded: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.partially_refunded"),
	refunded: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.refunded"),
	unpaid: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.unpaid"),
	voided: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.voided"),
	payment_processing: _pisell_utils.locales.getText("pisell2.orderList.paymentStatus.payment_processing")
});
const PAYMENT_STATUS_COLOR_MAP = {
	unpaid: "#B2DDFF",
	payment_processing: "#FEDF89",
	partially_paid: "#FDB022",
	authorized: "#ABEFC6",
	paid: "#ABEFC6",
	refunded: "#FECDCA",
	partially_refunded: "#FCCEEE",
	voided: "#D0D5DD"
};
const getPlatformMap = () => ({
	online_store: _pisell_utils.locales.getText("pisell2.orderList.platform.online_store"),
	wholesalebusiness: _pisell_utils.locales.getText("pisell2.orderList.platform.wholesalebusiness"),
	"table-order": _pisell_utils.locales.getText("pisell2.orderList.platform.table-order"),
	mobile_order: _pisell_utils.locales.getText("pisell2.orderList.platform.mobile_order"),
	kiosk: _pisell_utils.locales.getText("pisell2.orderList.platform.kiosk"),
	pos: _pisell_utils.locales.getText("pisell2.orderList.platform.pos")
});
/**
* 获取订单状态映射
* @param locales - 多语言对象
*/
const getOrderStatusMap = () => ({
	open: _pisell_utils.locales.getText("pisell2.orderList.orderStatus.open"),
	completed: _pisell_utils.locales.getText("pisell2.orderList.orderStatus.completed"),
	cancelled: _pisell_utils.locales.getText("pisell2.orderList.orderStatus.cancelled")
});
const ORDER_STATUS_COLOR_MAP = {
	open: {
		borderColor: "#1570EF",
		textColor: "#175CD3"
	},
	completed: {
		borderColor: "#079455",
		textColor: "#067647"
	},
	cancelled: {
		borderColor: "#D92D20",
		textColor: "#B42318"
	}
};
/**
* 获取处理状态映射
*/
const getShippingStatusMap = () => ({
	fulfilled: _pisell_utils.locales.getText("pisell2.orderList.shippingStatus.falseulfilled"),
	unfulfilled: _pisell_utils.locales.getText("pisell2.orderList.shippingStatus.unfulfilled"),
	fulfilling: _pisell_utils.locales.getText("pisell2.orderList.shippingStatus.fulfilling"),
	partial_fulfilled: _pisell_utils.locales.getText("pisell2.orderList.shippingStatus.partial_fulfilled")
});
const FULFILLMENT_STATUS_COLOR_MAP = {
	fulfilling: {
		borderColor: "#DC6803",
		textColor: "#B54708"
	},
	unfulfilled: {
		borderColor: "#DC6803",
		textColor: "#B54708"
	},
	partial_fulfilled: {
		borderColor: "#088AB2",
		textColor: "#0E7090"
	},
	fulfilled: {
		borderColor: "#475467",
		textColor: "#344054"
	}
};
/**
* 获取配送方式映射
*/
const getDeliveryTypeMap = () => ({
	nil: _pisell_utils.locales.getText("pisell2.orderList.deliveryType.nil"),
	shipping: _pisell_utils.locales.getText("pisell2.orderList.deliveryType.shipping"),
	local_delivery: _pisell_utils.locales.getText("pisell2.orderList.deliveryType.local_delivery"),
	pickup: _pisell_utils.locales.getText("pisell2.orderList.deliveryType.pickup"),
	shop_service: _pisell_utils.locales.getText("pisell2.orderList.deliveryType.shop_service")
});
/**
* 获取到店服务类型映射
* @param locales - 多语言对象
*/
const getShopServiceTypeMap = () => ({
	"dine-in": _pisell_utils.locales.getText("pisell2.orderList.shopServiceType.dine-in"),
	takeaway: _pisell_utils.locales.getText("pisell2.orderList.shopServiceType.takeaway")
});
const DELIVERY_TYPE_COLOR_MAP = {
	shipping: "",
	local_delivery: "orange",
	pickup: "blue"
};
const SHOP_SERVICE_TYPE_COLOR_MAP = {
	"dine-in": "green",
	takeaway: "red"
};
const getOrderHeaderLabels = () => ({
	saleBrief: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.saleBrief"),
	customer: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.customer"),
	contact: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.contact"),
	paymentInfo: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.paymentInfo"),
	items: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.items"),
	paymentStatus: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.paymentStatus"),
	orderOrigin: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.orderOrigin"),
	shippingMethod: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.shippingMethod"),
	orderStatus: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.orderStatus"),
	fulfillmentStatus: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.fulfillmentStatus"),
	updated: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.updated"),
	orderId: _pisell_utils.locales.getText("pisell2.salesManagement.order.column.orderId"),
	orderNote: _pisell_utils.locales.getText("pisell2.salesManagement.order.common.orderNote"),
	internalNote: _pisell_utils.locales.getText("pisell2.salesManagement.order.common.internalNote"),
	createdBy: _pisell_utils.locales.getText("pisell2.salesManagement.order.common.createdBy"),
	guest: _pisell_utils.locales.getText("pisell2.salesManagement.order.common.guest"),
	walkIn: _pisell_utils.locales.getText("pisell2.salesManagement.order.common.walkIn")
});
const getFilterButtonList = () => {
	const ORDER_STATUS_MAP = getOrderStatusMap();
	const PAYMENT_STATUS_MAP = getPaymentStatusMap();
	const SHIPPING_STATUS_MAP = getShippingStatusMap();
	const DELIVERY_TYPE_MAP = getDeliveryTypeMap();
	return [
		{
			name: "status",
			type: "single",
			key: "status",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.orderStatus.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.orderStatus.placeholder"),
				options: Object.entries(ORDER_STATUS_MAP).map(([key, value]) => ({
					label: value,
					value: key
				}))
			}
		},
		{
			name: "payment_status",
			type: "single",
			key: "payment_status",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.paymentStatus.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.paymentStatus.placeholder"),
				options: Object.entries(PAYMENT_STATUS_MAP).map(([key, value]) => ({
					label: value,
					value: key
				}))
			}
		},
		{
			name: "shipping_status",
			type: "single",
			key: "shipping_status",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.shippingStatus.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.shippingStatus.placeholder"),
				options: Object.entries(SHIPPING_STATUS_MAP).map(([key, value]) => ({
					label: value,
					value: key
				}))
			}
		},
		{
			name: "customer_id",
			type: "single",
			key: "customer_id",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.customer.label"),
			other: {
				allowClear: true,
				isSearchServer: true,
				showSearch: true,
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.customer.placeholder"),
				options: (params) => require_serve.getCustomerSelectOptions(params).then((res) => res.map((item) => ({
					label: item.display_name,
					value: item.id
				})))
			}
		},
		{
			name: "order_sales_channel",
			type: "single",
			key: "order_sales_channel",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.salesChannel.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.salesChannel.placeholder"),
				options: () => require_serve.getChannelSelectOptions().then((res) => res.map((item) => ({
					label: item.name,
					value: item.code
				})))
			}
		},
		{
			name: "payment_methods",
			type: "single",
			key: "payment_methods",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.paymentMethod.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.paymentMethod.placeholder"),
				options: () => require_serve.getPaymentSelectOptions().then((res) => {
					const map = new Map(res.map((item) => [item.code, {
						label: item.name,
						value: item.code
					}]));
					return Array.from(map.values());
				})
			}
		},
		{
			name: "total_amount",
			type: "numberRange",
			key: "total_amount",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.totalAmount.label"),
			other: {
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.totalAmount.placeholder"),
				minInputNumberProps: { min: 0 },
				maxInputNumberProps: { min: 0 }
			}
		},
		{
			name: "tag_ids",
			type: "single",
			key: "tag_ids",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.tags.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				isSearchServer: true,
				showSearch: true,
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.tags.placeholder"),
				options: (params) => require_serve.getTagSelectOptions(params).then((res) => res.map((item) => ({
					label: item.name,
					value: item.id
				})))
			}
		},
		{
			name: "shipping_type",
			type: "single",
			key: "shipping_type",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.shippingType.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.shippingType.placeholder"),
				options: Object.entries(DELIVERY_TYPE_MAP).filter(([key]) => !["nil", "shop_service"].includes(key)).map(([key, value]) => ({
					label: value,
					value: key
				}))
			}
		},
		{
			name: "delivery_zone_name",
			type: "text",
			key: "delivery_zone_name",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.deliveryZone.label"),
			other: { placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.deliveryZone.placeholder") }
		},
		{
			name: "location_id",
			type: "single",
			key: "location_id",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.pickupLocation.label"),
			other: {
				allowClear: true,
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.pickupLocation.placeholder"),
				options: () => require_serve.getLocationSelectOptions().then((res) => res.map((item) => ({
					label: item.name,
					value: item.id
				})))
			}
		},
		{
			name: "shipping_order_number",
			type: "text",
			key: "shipping_order_number",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.trackingNumber.label"),
			other: { placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.trackingNumber.placeholder") }
		},
		{
			name: "logistics_company_id",
			type: "single",
			key: "logistics_company_id",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.logistics.label"),
			other: {
				allowClear: true,
				mode: "multiple",
				maxTagCount: "responsive",
				placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.logistics.placeholder"),
				options: () => require_serve.getLogisticsSelectOptions().then((res) => res.map((item) => ({
					label: item.name,
					value: item.id
				})))
			}
		},
		{
			name: "zip",
			type: "text",
			key: "zip",
			label: _pisell_utils.locales.getText("pisell2.orderList.filter.zipCode.label"),
			other: { placeholder: _pisell_utils.locales.getText("pisell2.orderList.filter.zipCode.placeholder") }
		}
	];
};
const getSortList = () => {
	return [
		{
			type: "time",
			isCustom: true,
			name: "created_at",
			label: _pisell_utils.locales.getText("pisell2.orderList.sort.createdAt"),
			getSortItems: () => {
				return [{
					key: "created_at:asc",
					label: _pisell_utils.locales.getText("pisell2.salesManagement.sort.oldestFirst")
				}, {
					key: "created_at:desc",
					label: _pisell_utils.locales.getText("pisell2.salesManagement.sort.newestFirst")
				}];
			}
		},
		{
			type: "time",
			isCustom: true,
			name: "updated_at",
			label: _pisell_utils.locales.getText("pisell2.orderList.sort.updatedAt"),
			getSortItems: () => {
				return [{
					key: "updated_at:asc",
					label: _pisell_utils.locales.getText("pisell2.salesManagement.sort.oldestFirst")
				}, {
					key: "updated_at:desc",
					label: _pisell_utils.locales.getText("pisell2.salesManagement.sort.newestFirst")
				}];
			}
		},
		{
			type: "number",
			isCustom: false,
			name: "total_amount",
			label: _pisell_utils.locales.getText("pisell2.orderList.sort.totalAmount")
		},
		{
			type: "number",
			isCustom: false,
			name: "amount_gap",
			label: _pisell_utils.locales.getText("pisell2.salesManagement.sort.balanceDue")
		},
		{
			type: "string",
			isCustom: false,
			name: "customer_name",
			label: _pisell_utils.locales.getText("pisell2.orderList.sort.customerName")
		}
	];
};
//#endregion
exports.DELIVERY_TYPE_COLOR_MAP = DELIVERY_TYPE_COLOR_MAP;
exports.FULFILLMENT_STATUS_COLOR_MAP = FULFILLMENT_STATUS_COLOR_MAP;
exports.ORDER_STATUS_COLOR_MAP = ORDER_STATUS_COLOR_MAP;
exports.PAYMENT_STATUS_COLOR_MAP = PAYMENT_STATUS_COLOR_MAP;
exports.SHOP_SERVICE_TYPE_COLOR_MAP = SHOP_SERVICE_TYPE_COLOR_MAP;
exports.getDeliveryTypeMap = getDeliveryTypeMap;
exports.getFilterButtonList = getFilterButtonList;
exports.getOrderHeaderLabels = getOrderHeaderLabels;
exports.getOrderStatusMap = getOrderStatusMap;
exports.getPaymentStatusMap = getPaymentStatusMap;
exports.getPlatformMap = getPlatformMap;
exports.getShippingStatusMap = getShippingStatusMap;
exports.getShopServiceTypeMap = getShopServiceTypeMap;
exports.getSortList = getSortList;
