import { FC, useState } from 'react'
import TitleLine from '../../../components/TitleLine'
import { useTranslation } from 'react-i18next'
import { useGetCategoriesPublic, useGetServicesByCategory } from '../hooks/useServiceData'
import { SwiperSlide, Swiper } from 'swiper/react'
import { CategoryItemType, ItemServiceType } from '../types/ServiecTypes'
import { clx } from '../../../helpers/utils'
import ServiceItem from '../../../components/ServiceItem'

const OtherServicesComponent: FC = () => {

    const { t } = useTranslation('global')
    const [categoryId, setCategoryId] = useState<string>('')
    const getCategory = useGetCategoriesPublic()
    const getServices = useGetServicesByCategory(categoryId)

    return (
        <div>
            <div className='w-full mt-8'>
                <TitleLine title={t('service.other_services')} />
            </div>

            <div className='mt-6'>
                <Swiper
                    className='w-full'
                    spaceBetween={15} // فاصله پیش‌فرض بین اسلایدها
                    slidesPerView='auto'
                >
                    <SwiperSlide className='max-w-[158px]'>
                        <div onClick={() => setCategoryId('')} className={clx(
                            'h-10 cursor-pointer rounded-full border-2 border-white bg-white/45 flex gap-2 justify-center items-center',
                            '' === categoryId && 'bg-white'
                        )}>
                            <div className='text-sm'>{t('all')}</div>
                        </div>
                    </SwiperSlide>
                    {
                        getCategory.data?.data?.categories?.map((item: CategoryItemType) => {
                            return (
                                <SwiperSlide key={item.id} className='max-w-[158px]'>
                                    <div onClick={() => setCategoryId(item.id)} className={clx(
                                        'h-10 cursor-pointer rounded-full border-2 border-white bg-white/45 flex gap-2 justify-center items-center',
                                        item.id === categoryId && 'bg-white'
                                    )}>
                                        <img src={item.icon} className='size-5 rounded-full object-cover' />
                                        <div className='text-sm'>{item.title}</div>
                                    </div>
                                </SwiperSlide>
                            )
                        })
                    }

                </Swiper>
            </div>



            <div className='flex w-full gap-6 items-center'>
                <div className='flex items-stretch w-full flex-wrap xl:gap-6 gap-4 mt-8'>
                    {
                        getServices.data?.data?.services?.map((item: ItemServiceType) => {
                            return (
                                <ServiceItem
                                    key={item.id}
                                    item={item}
                                />
                            )
                        })
                    }
                    <div className='flex-1 min-w-[40%] xl:min-w-[30%] xl:p-6 p-4'></div>
                    <div className='flex-1 min-w-[40%] xl:min-w-[30%] xl:p-6 p-4'></div>
                </div>

            </div>
        </div>
    )
}

export default OtherServicesComponent