import React, { type FunctionComponent } from 'react'
import Icon from '../../atoms/Icon'
import IconButton from '../../molecules/IconButton'
import QuantitySelector from '../../molecules/QuantitySelector'
import {
Table,
TableBody,
TableCell,
TableHead,
TableRow,
} from '../../molecules/Table'
import Badge from '../../atoms/Badge'
import type { PriceFormatter } from '../../atoms/Price'
import Price from '../../atoms/Price'
import Skeleton from '../../atoms/Skeleton'
import { useUI } from '../../hooks'
import Alert from '../../molecules/Alert'
import Tooltip from '../../molecules/Tooltip'
import {
useQuickOrderDrawer,
type VariationProductColumn,
} from './provider/QuickOrderDrawerProvider'
type ImageComponentType = FunctionComponent<{
src: string
alt: string
width?: number
height?: number
loading?: 'eager' | 'lazy'
}>
// TODO: Replace with faststore Image component in final implementation
// This is a temporary reference component for storybook preview
const DefaultImageComponent: ImageComponentType = ({
src,
alt,
width,
height,
...otherProps
}) =>
export type QuickOrderDrawerProductsProps = {
columns: VariationProductColumn
formatter?: PriceFormatter
ImageComponent?: ImageComponentType
/**
* Messages for CMS configuration
*/
messages?: {
alertAriaLabel?: string
tableAriaLabel?: string
quantityUpdatedTooltip?: string
quantityUpdatedAriaLabel?: string
outOfStockLabel?: string
availableLabel?: string
selectQuantityAriaLabel?: string
removeProductAriaLabel?: string
invalidQuantityTitle?: string
invalidQuantityMessage?: (
min: number,
max: number,
quantity: number
) => string
emptyStateTitle?: string
emptyStateMessage?: string
}
}
const QuickOrderDrawerProducts = ({
columns,
formatter,
ImageComponent = DefaultImageComponent,
messages,
}: QuickOrderDrawerProductsProps) => {
const { pushToast } = useUI()
const {
products,
onChangeQuantityItem,
onDelete,
isLoading,
alertMessage,
setAlertMessage,
formatter: contextFormatter,
} = useQuickOrderDrawer()
const priceFormatter = formatter || contextFormatter
const showSkeleton = isLoading
return (