import { Eye, Lock1 } from "iconsax-react"; import type { ColumnType } from "@/components/types/TableTypes"; import type { CashShift } from "../types/Types"; import { formatFaNumber, formatOptionalDate, formatPrice, } from "@/helpers/func"; import Status from "@/components/Status"; import { CashShiftStatus } from "../enum/Enum"; import type { TFunction } from "i18next"; interface GetCashShiftTableColumnsParams { t: TFunction; onView: (shift: CashShift) => void; onClose?: (shift: CashShift) => void; } const getAdminName = (shift: CashShift) => { const name = [shift.admin?.firstName, shift.admin?.lastName] .filter(Boolean) .join(" "); return name || shift.admin?.phone || "-"; }; export const getCashShiftTableColumns = ({ t, onView, onClose, }: GetCashShiftTableColumnsParams): ColumnType[] => [ { key: "openedAt", title: t("cash_shift.opened_at"), render: (item) => formatOptionalDate(item.openedAt, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", }), }, { key: "closedAt", title: t("cash_shift.closed_at"), render: (item) => formatOptionalDate(item.closedAt, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", }), }, { key: "admin", title: t("cash_shift.operator"), render: (item) => getAdminName(item), }, { key: "openingAmount", title: t("cash_shift.opening_amount"), render: (item) => formatPrice(item.openingAmount), }, { key: "expectedAmount", title: t("cash_shift.expected_amount"), render: (item) => item.expectedAmount !== null ? formatPrice(item.expectedAmount) : "-", }, { key: "differenceAmount", title: t("cash_shift.difference_amount"), render: (item) => { if (item.differenceAmount === null) return "-"; const value = formatPrice(item.differenceAmount); if (item.differenceAmount > 0) { return {value}; } if (item.differenceAmount < 0) { return {value}; } return value; }, }, { key: "ordersCount", title: t("cash_shift.orders_count"), render: (item) => formatFaNumber(item.ordersCount), }, { key: "status", title: t("cash_shift.status_label"), render: (item) => ( ), }, { key: "actions", title: "", render: (item) => (
{item.status === CashShiftStatus.OPEN && onClose && ( )}
), }, ];