import type { ColumnType } from '@/components/types/TableTypes'
import type { RoleType } from '../types/Types'
import TrashWithConfrim from '@/components/TrashWithConfrim'
import { Eye } from 'iconsax-react'
import { Link } from 'react-router-dom'
import { Pages } from '@/config/Pages'

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

export const getRoleTableColumns = ({ onDelete, isDeleting }: GetRoleTableColumnsParams = {}): ColumnType<RoleType>[] => {
    return [
        {
            key: 'name',
            title: 'نام نقش',
        },
        {
            key: 'permissions',
            title: 'تعداد دسترسی‌ها',
            render: (item: RoleType) => {
                return item.permissions?.length || 0
            }
        },
        {
            key: 'createdAt',
            title: 'تاریخ ایجاد',
            render: (item: RoleType) => {
                return new Date(item.createdAt).toLocaleDateString('fa-IR')
            }
        },
        {
            key: 'actions',
            title: '',
            render: (item: RoleType) => {
                return (
                    <div className='flex gap-2 items-center'>
                        <Link to={Pages.roles.update + item.id}>
                            <Eye
                                size={20}
                                color='#8C90A3'
                                className='cursor-pointer'
                            />
                        </Link>
                        {onDelete && (
                            <TrashWithConfrim
                                onDelete={() => onDelete(item.id)}
                                isLoading={isDeleting}
                            />
                        )}
                    </div>
                )
            }
        },
    ]
}

