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'
import type { TFunction } from 'i18next'
import { formatOptionalDate } from '@/helpers/func'

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

export const getScheduleTableColumns = ({ onDelete, isDeleting, t }: GetScheduleTableColumnsParams): ColumnType<Schedule>[] => {
    return [
        {
            key: 'weekDay',
            title: 'روز هفته',
            render: (item: Schedule) => {
                return t('schedule.weekDay.' + item.weekDay)
            },
        },
        {
            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 formatOptionalDate(item.createdAt)
            }
        },
        {
            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>
                )
            }
        },
    ]
}

