import clsx from "clsx"
import { useAdminStore } from "medusa-react"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
import { defaultChannelsSorter } from "../../../utils/sales-channel-compare-operator"
import DelimitedList from "../../molecules/delimited-list"
import ListIcon from "../../fundamentals/icons/list-icon"
import TileIcon from "../../fundamentals/icons/tile-icon"
import ImagePlaceholder from "../../fundamentals/image-placeholder"
import StatusIndicator from "../../fundamentals/status-indicator"
const useProductTableColumn = ({ setTileView, setListView, showList }) => {
const { t } = useTranslation()
const getProductStatus = (status) => {
switch (status) {
case "proposed":
return (
)
case "published":
return (
)
case "rejected":
return (
)
case "draft":
return (
)
default:
return
}
}
const { store } = useAdminStore()
const getProductSalesChannels = (salesChannels) => {
const salesChannelsNames = (salesChannels || [])
.sort(defaultChannelsSorter(store?.default_sales_channel_id || ""))
.map((sc) => sc.name)
return
}
const columns = useMemo(
() => [
{
Header: t("product-table-name", "Name"),
accessor: "title",
Cell: ({ row: { original } }) => {
return (
{original.thumbnail ? (

) : (
)}
{original.title}
)
},
},
{
Header: t("product-table-collection", "Collection"),
accessor: "collection", // accessor is the "key" in the data
Cell: ({ cell: { value } }) => {
return {value?.title || "-"}
},
},
{
Header: t("product-table-status", "Status"),
accessor: "status",
Cell: ({ cell: { value } }) => getProductStatus(value),
},
{
Header: t("product-table-availability", "Availability"),
accessor: "sales_channels",
Cell: ({ cell: { value } }) => getProductSalesChannels(value),
},
{
Header: t("product-table-inventory", "Inventory"),
accessor: "variants",
Cell: ({ cell: { value } }) => (
{value.reduce((acc, next) => acc + next.inventory_quantity, 0)}
{t(
"product-table-inventory-in-stock-count",
" in stock for {{count}} variant(s)",
{ count: value.length }
)}
),
},
{
accessor: "col-3",
Header: (
),
},
],
[showList]
)
return [columns] as const
}
export default useProductTableColumn