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'

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

export const getShipmentMethodTableColumns = ({ onDelete, isDeleting }: GetShipmentMethodTableColumnsParams = {}): ColumnType<RestaurantShipmentMethod>[] => {
    return [
        {
            key: 'title',
            title: 'عنوان',
            render: (item: RestaurantShipmentMethod) => {
                return item.shipmentMethod?.title || '-'
            }
        },
        {
            key: 'description',
            title: 'توضیحات',
            render: (item: RestaurantShipmentMethod) => {
                return item.shipmentMethod?.description || '-'
            }
        },
        {
            key: 'price',
            title: 'قیمت',
            render: (item: RestaurantShipmentMethod) => {
                return item.price ? `${formatFaNumber(item.price)} تومان` : 'رایگان'
            }
        },
        {
            key: 'minOrderPrice',
            title: 'حداقل قیمت سفارش',
            render: (item: RestaurantShipmentMethod) => {
                return item.minOrderPrice ? `${formatFaNumber(item.minOrderPrice)} تومان` : '-'
            }
        },
        {
            key: 'isActive',
            title: 'وضعیت',
            render: (item: RestaurantShipmentMethod) => {
                return (
                    <Status
                        variant={item.isActive ? 'success' : 'error'}
                        label={item.isActive ? 'فعال' : 'غیرفعال'}
                    />
                )
            }
        },
        {
            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>
                )
            }
        },
    ]
}

