import { Eye, Star1 } from 'iconsax-react'
import type { ColumnType } from '@/components/types/TableTypes'
import type { Review } from '../types/Types'
import { formatOptionalDate } from '@/helpers/func'
import Status from '@/components/Status'
import { Link } from 'react-router-dom'
import { Pages } from '@/config/Pages'
import { getReviewStatusVariant, reviewStatusLabels } from '../utils/reviewStatus'

export const getReviewTableColumns = (): ColumnType<Review>[] => {
    return [
        {
            key: 'user',
            title: 'کاربر',
            render: (item: Review) => {
                const name = [item.user?.firstName, item.user?.lastName].filter(Boolean).join(' ')
                return name || '-'
            }
        },
        {
            key: 'food',
            title: 'غذا',
            render: (item: Review) => {
                return item.food.title || '-'
            }
        },
        {
            key: 'rating',
            title: 'امتیاز',
            render: (item: Review) => {
                return (
                    <div className="flex items-center gap-1">
                        <Star1
                            size={16}
                            color="black"
                            variant="Bold"
                        />
                        <div className='mt-1 text-sm'>{item.rating}</div>
                    </div>
                )
            }
        },
        {
            key: 'comment',
            title: 'نظر',
            render: (item: Review) => {
                return (
                    <div className="max-w-xs truncate" title={item.comment}>
                        {item.comment || '-'}
                    </div>
                )
            }
        },
        {
            key: 'status',
            title: 'وضعیت',
            render: (item: Review) => {
                return (
                    <Status
                        variant={getReviewStatusVariant(item.status)}
                        label={reviewStatusLabels[item.status] || item.status}
                    />
                )
            }
        },
        {
            key: 'createdAt',
            title: 'تاریخ ثبت',
            render: (item: Review) => {
                return formatOptionalDate(item.createdAt, {
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit',
                    hour: '2-digit',
                    minute: '2-digit',
                })
            }
        },
        {
            key: 'details',
            title: '',
            render: (item: Review) => {
                return (
                    <Link to={Pages.reviews.detail + item.id}>
                        <Eye size={20} color="#8C90A3" className="cursor-pointer" />
                    </Link>
                )
            }
        },
    ]
}
