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

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

export const getScheduleTableColumns = ({ onDelete, isDeleting }: GetScheduleTableColumnsParams = {}): ColumnType<Schedule>[] => {
    return [
        {
            key: 'openTime',
            title: 'زمان باز',
        },
        {
            key: 'closeTime',
            title: 'زمان بسته',
        },
        {
            key: 'isActive',
            title: 'وضعیت',
            render: (item: Schedule) => {
                return (
                    <Status variant={item.isActive ? 'success' : 'error'} label={item.isActive ? 'فعال' : 'غیرفعال'} />
                )
            }
        },
        {
            key: 'createdAt',
            title: 'تاریخ ایجاد',
            render: (item: Schedule) => {
                return new Date(item.createdAt).toLocaleDateString('fa-IR')
            }
        },
        {
            key: 'actions',
            title: '',
            render: (item: Schedule) => {
                return (
                    <div className='flex gap-2 items-center'>
                        <Link to={Pages.schedule.update + item.id}>
                            <Eye
                                size={20}
                                color='#8C90A3'
                                className='cursor-pointer'
                            />
                        </Link>
                        {onDelete && (
                            <TrashWithConfrim
                                onDelete={() => onDelete(item.id)}
                                isLoading={isDeleting}
                            />
                        )}
                    </div>
                )
            }
        },
    ]
}

