import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useGetShopSmsCount } from '../hooks/useIconData'
import PageLoading from '../../../components/PageLoading'
import Td from '../../../components/Td'
import { ShopSmsCountItem } from '../types/Types'

const SmsCountList: FC = () => {
    const { t } = useTranslation('global')
    const { data: smsCount, isLoading } = useGetShopSmsCount()

    const smsCountList = (smsCount as { data?: ShopSmsCountItem[] })?.data || []

    return (
        <div className='mt-4'>
            <div className='flex w-full justify-between items-center'>
                <div>
                    {t('shop.list_sms_count')}
                </div>
            </div>

            {
                isLoading ?
                    <PageLoading />
                    :
                    <div className='relative overflow-x-auto rounded-3xl mt-9 w-full'>
                        <table className='w-full text-sm '>
                            <thead className='thead'>
                                <tr>
                                    <Td text={t('shop.name')} />
                                    <Td text={t('shop.sms_count')} />
                                </tr>
                            </thead>
                            <tbody>
                                {
                                    smsCountList.map((item: ShopSmsCountItem) => {
                                        return (
                                            <tr key={item.shopId} className='tr'>
                                                <Td text={item.shopName} />
                                                <Td text={item.smsCount.toString()} />
                                            </tr>
                                        )
                                    })
                                }
                            </tbody>
                        </table>
                    </div>
            }
        </div>
    )
}

export default SmsCountList
