import type { ColumnType } from '@/components/types/TableTypes'
import type { RestaurantShipmentMethod } from '../types/Types'
import TrashWithConfrim from '@/components/TrashWithConfrim'
import { Eye } from 'iconsax-react'
import { Link } from 'react-router-dom'
import { Pages } from '@/config/Pages'
import Status from '@/components/Status'
import { formatFaNumber } from '@/helpers/func'
import type { TFunction } from 'i18next'

interface GetShipmentMethodTableColumnsParams {
    onDelete?: (id: string) => void
    isDeleting?: boolean
    t: TFunction
}

export const getShipmentMethodTableColumns = ({ onDelete, isDeleting, t }: GetShipmentMethodTableColumnsParams): ColumnType<RestaurantShipmentMethod>[] => {
    return [
        {
            key: 'title',
            title: 'عنوان',
            render: (item: RestaurantShipmentMethod) => {
                return item.title || '-'
            }
        },
        {
            key: 'method',
            title: 'روش ارسال',
            render: (item: RestaurantShipmentMethod) => {
                return t(`shipment.${item.method}`)
            }
        },
        {
            key: 'description',
            title: 'توضیحات',
            render: (item: RestaurantShipmentMethod) => {
                return item.description || '-'
            }
        },
        {
            key: 'deliveryFee',
            title: 'هزینه ارسال',
            render: (item: RestaurantShipmentMethod) => {
                return item.deliveryFee ? `${formatFaNumber(item.deliveryFee)} تومان` : 'رایگان'
            }
        },
        {
            key: 'minOrderPrice',
            title: 'حداقل قیمت سفارش',
            render: (item: RestaurantShipmentMethod) => {
                return item.minOrderPrice ? `${formatFaNumber(item.minOrderPrice)} تومان` : '-'
            }
        },
        {
            key: 'enabled',
            title: 'وضعیت',
            render: (item: RestaurantShipmentMethod) => {
                return (
                    <Status
                        variant={item.enabled ? 'success' : 'error'}
                        label={item.enabled ? 'فعال' : 'غیرفعال'}
                    />
                )
            }
        },
        {
            key: 'actions',
            title: '',
            render: (item: RestaurantShipmentMethod) => {
                return (
                    <div className='flex gap-2 items-center'>
                        <Link to={Pages.shipment_methods.update + item.id}>
                            <Eye
                                size={20}
                                color='#8C90A3'
                                className='cursor-pointer'
                            />
                        </Link>
                        {onDelete && (
                            <TrashWithConfrim
                                onDelete={() => onDelete(item.id)}
                                isloading={isDeleting}
                            />
                        )}
                    </div>
                )
            }
        },
    ]
}

