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

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

export const getAdminTableColumns = ({ onDelete, isDeleting }: GetAdminTableColumnsParams = {}): ColumnType<Admin>[] => {
    return [
        {
            key: 'firstName',
            title: 'نام',
            render: (item: Admin) => {
                return item.firstName || '-'
            }
        },
        {
            key: 'lastName',
            title: 'نام خانوادگی',
            render: (item: Admin) => {
                return item.lastName || '-'
            }
        },
        {
            key: 'phone',
            title: 'شماره تماس',
            render: (item: Admin) => {
                return item.phone || '-'
            }
        },
        {
            key: 'roles',
            title: 'تعداد نقش‌ها',
            render: (item: Admin) => {
                return item.roles?.length || 0
            }
        },
        {
            key: 'createdAt',
            title: 'تاریخ ایجاد',
            render: (item: Admin) => {
                return formatOptionalDate(item.createdAt)
            }
        },
        {
            key: 'actions',
            title: '',
            render: (item: Admin) => {
                return (
                    <div className='flex gap-2 items-center'>
                        <Link to={Pages.admins.update + item.id}>
                            <Eye
                                size={20}
                                color='#8C90A3'
                                className='cursor-pointer'
                            />
                        </Link>
                        {onDelete && (
                            <TrashWithConfrim
                                onDelete={() => onDelete(item.id)}
                                isloading={isDeleting}
                            />
                        )}
                    </div>
                )
            }
        },
    ]
}

