import type { ColumnType } from '@/components/types/TableTypes'
import type { PaymentMethod } 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<PaymentMethod>[] => {
    return [
        {
            key: 'name',
            title: 'نام',
        },
        {
            key: 'keyName',
            title: 'کلید',
        },
        {
            key: 'description',
            title: 'توضیحات',
        },
        {
            key: 'isActive',
            title: 'وضعیت',
            render: (item: PaymentMethod) => {
                return (
                    <Status 
                        variant={item.isActive ? 'success' : 'error'} 
                        label={item.isActive ? 'فعال' : 'غیرفعال'} 
                    />
                )
            }
        },
        {
            key: 'order',
            title: 'ترتیب',
        },
        {
            key: 'createdAt',
            title: 'تاریخ ایجاد',
            render: (item: PaymentMethod) => {
                return new Date(item.createdAt).toLocaleDateString('fa-IR')
            }
        },
        {
            key: 'actions',
            title: '',
            render: (item: PaymentMethod) => {
                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>
                )
            }
        },
    ]
}

