import { useIsApp } from "../../hooks.js";
import MoreDropdown from "../../components/MoreDropdown/index.js";
import { STATUS_COLOR_MAP, STATUS_TEXT_MAP } from "../const.js";
import dayjs from "dayjs";
import React from "react";
import { Button } from "@pisell/materials";
import "../index.less";
//#region src/components/ecocup/cupList/hooks/useColumns.tsx
const prefixCls = "ecocup-cup-list";
const useColumns = (props) => {
	const { onClickAction, locales, isEcoShare } = props;
	const isApp = useIsApp();
	const getRelativeTime = (text) => {
		if (!text) return "";
		const diff = dayjs().diff(dayjs(text), "day");
		if (diff === 0) return locales.getText("pisell2.text.ecocup.table.time-of-return.today");
		return locales.getText("pisell2.text.ecocup.table.time-of-rent.relative")(diff);
	};
	return [
		{
			title: locales.getText("pisell2.text.ecocup.table.cup-code"),
			dataIndex: "eco_cup_code",
			key: "eco_cup_code",
			align: "center",
			width: 170,
			render: (text, record) => {
				return text || (record === null || record === void 0 ? void 0 : record.code) || "";
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.customer"),
			dataIndex: "customer",
			key: "customer",
			align: "center",
			hidden: isApp,
			with: 220,
			render: (text, record) => {
				var _record$customer;
				return (record === null || record === void 0 || (_record$customer = record.customer) === null || _record$customer === void 0 ? void 0 : _record$customer.display_name) || "";
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.status"),
			dataIndex: "status",
			key: "status",
			align: "center",
			width: 120,
			render: (text) => {
				const status = STATUS_TEXT_MAP[text];
				const color = STATUS_COLOR_MAP[text];
				return /* @__PURE__ */ React.createElement("div", {
					className: `${prefixCls}-table-status`,
					style: {
						backgroundColor: color === null || color === void 0 ? void 0 : color.backgroundColor,
						color: color === null || color === void 0 ? void 0 : color.color,
						border: `1px solid ${color === null || color === void 0 ? void 0 : color.border}`
					}
				}, locales.getText(status));
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.shop-of-rent"),
			dataIndex: "rent_shop",
			key: "rent_shop",
			align: "center",
			hidden: isApp,
			width: 200,
			render: (text, record) => {
				var _record$rent_shop;
				return (record === null || record === void 0 || (_record$rent_shop = record.rent_shop) === null || _record$rent_shop === void 0 ? void 0 : _record$rent_shop.name) || "";
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.time-of-rent"),
			dataIndex: "rent_time",
			key: "rent_time",
			align: "center",
			hidden: isApp,
			width: 160,
			render: (text) => {
				if (!text) return "";
				return /* @__PURE__ */ React.createElement("div", { style: {
					display: "flex",
					flexDirection: "column",
					alignItems: "center"
				} }, /* @__PURE__ */ React.createElement("span", null, dayjs(text).format("DD/MM/YYYY")), /* @__PURE__ */ React.createElement("span", null, getRelativeTime(text)));
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.shop-of-return"),
			dataIndex: "return_shop",
			key: "return_shop",
			align: "center",
			hidden: isApp,
			width: 200,
			render: (text, record) => {
				var _record$return_shop;
				return (record === null || record === void 0 || (_record$return_shop = record.return_shop) === null || _record$return_shop === void 0 ? void 0 : _record$return_shop.name) || "";
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.time-of-return"),
			dataIndex: "return_time",
			key: "return_time",
			align: "center",
			hidden: isApp,
			width: 160,
			render: (text) => {
				return text ? dayjs(text).format("DD/MM/YYYY") : "";
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.rent"),
			dataIndex: "rent_shop",
			key: "rent_shop",
			align: "center",
			hidden: !isApp,
			width: 160,
			render: (text, record) => {
				var _record$rent_shop2, _record$rent_shop3;
				return /* @__PURE__ */ React.createElement("div", { style: {
					display: "flex",
					flexDirection: "column",
					alignItems: "center"
				} }, (record === null || record === void 0 || (_record$rent_shop2 = record.rent_shop) === null || _record$rent_shop2 === void 0 ? void 0 : _record$rent_shop2.name) ? /* @__PURE__ */ React.createElement("span", null, record === null || record === void 0 || (_record$rent_shop3 = record.rent_shop) === null || _record$rent_shop3 === void 0 ? void 0 : _record$rent_shop3.name) : null, (record === null || record === void 0 ? void 0 : record.rent_time) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", null, dayjs(record === null || record === void 0 ? void 0 : record.rent_time).format("DD/MM/YYYY")), /* @__PURE__ */ React.createElement("span", null, getRelativeTime(record === null || record === void 0 ? void 0 : record.rent_time))) : null);
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.action.return"),
			dataIndex: "return_shop",
			key: "return_shop",
			align: "center",
			hidden: !isApp,
			width: 160,
			render: (text, record) => {
				var _record$return_shop2, _record$return_shop3;
				return /* @__PURE__ */ React.createElement("div", { style: {
					display: "flex",
					flexDirection: "column",
					alignItems: "center"
				} }, (record === null || record === void 0 || (_record$return_shop2 = record.return_shop) === null || _record$return_shop2 === void 0 ? void 0 : _record$return_shop2.name) ? /* @__PURE__ */ React.createElement("span", null, record === null || record === void 0 || (_record$return_shop3 = record.return_shop) === null || _record$return_shop3 === void 0 ? void 0 : _record$return_shop3.name) : null, (record === null || record === void 0 ? void 0 : record.return_time) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", null, dayjs(record === null || record === void 0 ? void 0 : record.return_time).format("DD/MM/YYYY")), /* @__PURE__ */ React.createElement("span", null, getRelativeTime(record === null || record === void 0 ? void 0 : record.return_time))) : null);
			}
		},
		{
			title: locales.getText("pisell2.text.ecocup.table.actions"),
			dataIndex: "actions",
			key: "actions",
			hidden: isApp || isEcoShare,
			width: 180,
			render: (text, record) => {
				const _status = (record === null || record === void 0 ? void 0 : record.status) || "";
				const showMoreTypes = ["in_stock", "rent"];
				if ((record === null || record === void 0 ? void 0 : record.shop_id) !== (record === null || record === void 0 ? void 0 : record.current_shop_id) && !(record === null || record === void 0 ? void 0 : record.eco_cup_id)) return null;
				return /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-table-actions` }, _status === "rent" ? /* @__PURE__ */ React.createElement(Button, {
					type: "primary",
					onClick: () => onClickAction("return", record)
				}, locales.getText("pisell2.text.ecocup.action.return")) : null, showMoreTypes.includes(_status) ? /* @__PURE__ */ React.createElement(MoreDropdown, {
					locales,
					onClick: (key) => onClickAction(key, record)
				}) : null);
			}
		}
	];
};
//#endregion
export { useColumns };
