import { Order } from "@medusajs/medusa" import { PricedVariant } from "@medusajs/medusa/dist/types/pricing" import { createColumnHelper } from "@tanstack/react-table" import clsx from "clsx" import { useMemo } from "react" import { useTranslation } from "react-i18next" import Thumbnail from "../../../../../components/atoms/thumbnail" import Tooltip from "../../../../../components/atoms/tooltip" import SortingIcon from "../../../../../components/fundamentals/icons/sorting-icon" import IndeterminateCheckbox from "../../../../../components/molecules/indeterminate-checkbox" import { formatAmountWithSymbol } from "../../../../../utils/prices" const columnHelper = createColumnHelper() export const useAddAdditionalItemsColumns = (order: Order) => { const { t } = useTranslation() const columns = useMemo( () => [ columnHelper.display({ id: "selection", maxSize: 36, header: ({ table }) => { return (
) }, cell: ({ row: { getIsSelected, getIsSomeSelected, getToggleSelectedHandler, getCanSelect, }, }) => { const canSelect = getCanSelect() return (
{canSelect ? ( ) : ( )}
) }, }), columnHelper.accessor("title", { header: ({ header: { column: { getToggleSortingHandler, getIsSorted }, }, }) => (

Title

), cell: ({ cell: { getValue }, row: { original: { product, sku }, getCanSelect, }, }) => { const isSelectable = getCanSelect() return (

{product?.title}{" "} ({getValue()})

{sku &&

{sku}

}
) }, }), columnHelper.display({ maxSize: 80, id: "options", header: () =>

Options

, cell: ({ row: { original } }) => { return

{original.options?.map((o) => o.value).join(", ")}

}, }), columnHelper.accessor("inventory_quantity", { maxSize: 20, header: () => (

{t("add-additional-items-screen-stock", "Stock")}

), cell: ({ cell: { getValue }, row: { getCanSelect } }) => { const isSelectable = getCanSelect() return (

{getValue()}

) }, }), columnHelper.accessor("calculated_price_incl_tax", { maxSize: 80, header: () => (

{t("add-additional-items-screen-price", "Price")}

), cell: ({ getValue, row: { original: { original_price_incl_tax }, }, }) => { const price = getValue() return (
{original_price_incl_tax !== price && (

{formatAmountWithSymbol({ amount: original_price_incl_tax || 0, currency: order.currency_code, })}

)}

{formatAmountWithSymbol({ amount: price || 0, currency: order.currency_code, })}

) }, }), columnHelper.display({ id: "order_currency", maxSize: 24, cell: () => { return (

{order.currency_code.toUpperCase()}

) }, }), ], [order] ) return columns }