import { FC } from 'react'
import { Link } from 'react-router-dom'
import { Pages } from '../config/Pages'
import { ArrowLeft, More } from 'iconsax-react'
import Button from './Button'
import { useTranslation } from 'react-i18next'
import { ItemServiceType } from '../pages/service/types/ServiecTypes'

type Props = {
    item: ItemServiceType,
    className?: string,
    isLinkPanel?: boolean,
    businessName?: string,
    isDisabled?: boolean,
    isQuikAccess?: boolean,
    onMoreClick?: () => void,
}

const ServiceItem: FC<Props> = (props: Props) => {

    const { t } = useTranslation('global')
    const { item } = props

    return (
        <div className={`flex-1 relative flex flex-col self-stretch min-w-[45%] xl:min-w-[30%] bg-white rounded-3xl xl:p-6 p-4 ${props.className} ${props.isDisabled ? 'opacity-50' : ''}`}>
            {
                props.isQuikAccess &&
                <div onClick={props.onMoreClick} className='absolute  size-6 flex justify-center items-center left-4 top-4'>
                    <More size={14} color='black' className='rotate-90' />
                </div>
            }
            <div className='flex gap-2 items-center'>
                <div className='xl:size-[50px] xl:min-w-[50px] min-w-10 size-10 overflow-hidden rounded-xl'>
                    <img src={item.icon} alt={item.name} className='w-full h-full' />
                </div>
                <div className='flex flex-col'>
                    <div className=' text-sm pl-3'>
                        {item.name}
                    </div>
                    {
                        props.isLinkPanel &&
                        <div className='text-xs text-description'>
                            {props.businessName}
                        </div>
                    }
                </div>
            </div>
            {
                !props.isLinkPanel &&
                <div className='mt-4 text-xs'>
                    <div className='font-extralight'>{item.title} </div>
                </div>
            }


            <div className='mt-4 flex-1 flex items-end'>
                <Link target={props.isLinkPanel && !props.isDisabled ? '_blank' : ''} to={props.isDisabled ? '#' : props.isLinkPanel ? item.link : Pages.services.detail + item.slug}>
                    <Button
                        className='h-8 w-fit px-5 text-xs text-black bg-description bg-opacity-20 rounded-xl'
                    >
                        <div className='flex gap-2 whitespace-nowrap'>
                            {
                                props.isLinkPanel ?
                                    t('panel_service')
                                    :
                                    t('service.detail')
                            }
                            <ArrowLeft color='black' size={16} />
                        </div>
                    </Button>
                </Link>
            </div>
        </div>
    )
}

export default ServiceItem