import {
  DisplayIdCell,
  DisplayIdHeader
} from "./chunk-HB3BP55W.js";
import {
  DateCell,
  DateHeader
} from "./chunk-SYNUA6LQ.js";
import {
  MoneyAmountCell
} from "./chunk-5YZ3G5EZ.js";
import {
  getOrderFulfillmentStatus,
  getOrderPaymentStatus
} from "./chunk-T35QBLG7.js";
import {
  StatusCell
} from "./chunk-DB6ANJBO.js";
import {
  PlaceholderCell
} from "./chunk-PHOCVOZ5.js";

// src/hooks/table/columns/use-order-table-columns.tsx
import {
  createColumnHelper
} from "@tanstack/react-table";
import { useMemo } from "react";

// src/components/table/table-cells/order/customer-cell/customer-cell.tsx
import { useTranslation } from "react-i18next";
import { jsx } from "react/jsx-runtime";
var CustomerCell = ({
  customer
}) => {
  if (!customer) {
    return /* @__PURE__ */ jsx("span", { className: "text-ui-fg-muted", children: "-" });
  }
  const { first_name, last_name, email } = customer;
  const name = [first_name, last_name].filter(Boolean).join(" ");
  return /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: name || email }) });
};
var CustomerHeader = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t("fields.customer") }) });
};

// src/components/table/table-cells/order/fulfillment-status-cell/fulfillment-status-cell.tsx
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2 } from "react/jsx-runtime";
var FulfillmentStatusCell = ({
  status
}) => {
  const { t } = useTranslation2();
  if (!status) {
    return "-";
  }
  const { label, color } = getOrderFulfillmentStatus(t, status);
  return /* @__PURE__ */ jsx2(StatusCell, { color, children: label });
};
var FulfillmentStatusHeader = () => {
  const { t } = useTranslation2();
  return /* @__PURE__ */ jsx2("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx2("span", { className: "truncate", children: t("fields.fulfillment") }) });
};

// src/components/table/table-cells/order/payment-status-cell/payment-status-cell.tsx
import { useTranslation as useTranslation3 } from "react-i18next";
import { jsx as jsx3 } from "react/jsx-runtime";
var PaymentStatusCell = ({ status }) => {
  const { t } = useTranslation3();
  const { label, color } = getOrderPaymentStatus(t, status);
  return /* @__PURE__ */ jsx3(StatusCell, { color, children: label });
};
var PaymentStatusHeader = () => {
  const { t } = useTranslation3();
  return /* @__PURE__ */ jsx3("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx3("span", { className: "truncate", children: t("fields.payment") }) });
};

// src/components/table/table-cells/order/total-cell/total-cell.tsx
import { useTranslation as useTranslation4 } from "react-i18next";
import { jsx as jsx4 } from "react/jsx-runtime";
var TotalCell = ({ currencyCode, total, className }) => {
  if (!total) {
    return /* @__PURE__ */ jsx4(PlaceholderCell, {});
  }
  return /* @__PURE__ */ jsx4(MoneyAmountCell, { currencyCode, amount: total, className, align: "right" });
};
var TotalHeader = () => {
  const { t } = useTranslation4();
  return /* @__PURE__ */ jsx4("div", { className: "flex h-full w-full items-center justify-end", children: /* @__PURE__ */ jsx4("span", { className: "truncate", children: t("fields.total") }) });
};

// src/hooks/table/columns/use-order-table-columns.tsx
import { jsx as jsx5 } from "react/jsx-runtime";
var columnHelper = createColumnHelper();
var useOrderTableColumns = (props) => {
  const { exclude = [] } = props ?? {};
  const columns = useMemo(
    () => [
      columnHelper.accessor("display_id", {
        header: () => /* @__PURE__ */ jsx5(DisplayIdHeader, {}),
        cell: ({ getValue }) => {
          const id = getValue();
          return /* @__PURE__ */ jsx5(DisplayIdCell, { displayId: id });
        }
      }),
      columnHelper.accessor("created_at", {
        header: () => /* @__PURE__ */ jsx5(DateHeader, {}),
        cell: ({ getValue }) => {
          const date = new Date(getValue());
          return /* @__PURE__ */ jsx5(DateCell, { date });
        }
      }),
      columnHelper.accessor("customer", {
        header: () => /* @__PURE__ */ jsx5(CustomerHeader, {}),
        cell: ({ getValue }) => {
          const customer = getValue();
          return /* @__PURE__ */ jsx5(CustomerCell, { customer });
        }
      }),
      columnHelper.accessor("payment_status", {
        header: () => /* @__PURE__ */ jsx5(PaymentStatusHeader, {}),
        cell: ({ getValue }) => {
          const status = getValue();
          return /* @__PURE__ */ jsx5(PaymentStatusCell, { status });
        }
      }),
      columnHelper.accessor("fulfillment_status", {
        header: () => /* @__PURE__ */ jsx5(FulfillmentStatusHeader, {}),
        cell: ({ getValue }) => {
          const status = getValue();
          return /* @__PURE__ */ jsx5(FulfillmentStatusCell, { status });
        }
      }),
      columnHelper.accessor("total", {
        header: () => /* @__PURE__ */ jsx5(TotalHeader, {}),
        cell: ({ getValue, row }) => {
          const isFullyRefunded = row.original.payment_status === "refunded";
          const total = !isFullyRefunded ? getValue() : row.original.payment_collections?.reduce(
            (acc, payCol) => acc + (payCol.refunded_amount ?? 0),
            0
          ) || 0;
          const currencyCode = row.original.currency_code;
          return /* @__PURE__ */ jsx5(
            TotalCell,
            {
              currencyCode,
              total,
              className: isFullyRefunded ? "text-ui-fg-muted line-through" : ""
            }
          );
        }
      })
    ],
    []
  );
  const isAccessorColumnDef = (c) => {
    return c.accessorKey !== void 0;
  };
  const isDisplayColumnDef = (c) => {
    return c.id !== void 0;
  };
  const shouldExclude = (c) => {
    if (isAccessorColumnDef(c)) {
      return exclude.includes(c.accessorKey);
    } else if (isDisplayColumnDef(c)) {
      return exclude.includes(c.id);
    }
    return false;
  };
  return columns.filter(
    (c) => !shouldExclude(c)
  );
};

export {
  useOrderTableColumns
};
