import type { ColumnType } from '@/components/types/TableTypes'
import type { RestaurantPaymentMethod } 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'

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

export const getPaymentMethodTableColumns = ({ onDelete, isDeleting }: GetPaymentMethodTableColumnsParams = {}): ColumnType<RestaurantPaymentMethod>[] => {
    return [
        {
            key: 'method',
            title: 'روش',
            render: (item: RestaurantPaymentMethod) => {
                return item.method || '-'
            }
        },
        {
            key: 'gateway',
            title: 'درگاه',
            render: (item: RestaurantPaymentMethod) => {
                return item.gateway || '-'
            }
        },
        {
            key: 'description',
            title: 'توضیحات',
            render: (item: RestaurantPaymentMethod) => {
                return item.description || '-'
            }
        },
        {
            key: 'enabled',
            title: 'وضعیت',
            render: (item: RestaurantPaymentMethod) => {
                return (
                    <Status
                        variant={item.enabled ? 'success' : 'error'}
                        label={item.enabled ? 'فعال' : 'غیرفعال'}
                    />
                )
            }
        },
        {
            key: 'order',
            title: 'ترتیب',
            render: (item: RestaurantPaymentMethod) => {
                return item.order || '-'
            }
        },
        {
            key: 'merchantId',
            title: 'شناسه مرچنت',
            render: (item: RestaurantPaymentMethod) => {
                return item.merchantId || '-'
            }
        },
        {
            key: 'cards',
            title: 'شماره کارت',
            render: (item: RestaurantPaymentMethod) => {
                if (!item.cards?.length) return '-'
                return item.cards.map((card) => card.cardNumber).join('، ')
            }
        },
        {
            key: 'cardOwners',
            title: 'نام صاحب کارت',
            render: (item: RestaurantPaymentMethod) => {
                if (!item.cards?.length) return '-'
                return item.cards.map((card) => card.owner).join('، ')
            }
        },
        {
            key: 'actions',
            title: '',
            render: (item: RestaurantPaymentMethod) => {
                return (
                    <div className='flex gap-2 items-center'>
                        <Link to={Pages.payment_methods.update + item.id}>
                            <Eye
                                size={20}
                                color='#8C90A3'
                                className='cursor-pointer'
                            />
                        </Link>
                        {onDelete && (
                            <TrashWithConfrim
                                onDelete={() => onDelete(item.id)}
                                isloading={isDeleting}
                            />
                        )}
                    </div>
                )
            }
        },
    ]
}

