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' import moment from 'moment-jalaali' import { NumberFormat } from '../config/func' type Props = { item: ItemServiceType, className?: string, isLinkPanel?: boolean, businessName?: string, isDisabled?: boolean, isQuikAccess?: boolean, onMoreClick?: () => void, subscriptionId?: string, endDate?: string, } const ServiceItem: FC = (props: Props) => { const { t } = useTranslation('global') const { item } = props const getRemainingDays = (endDate: string): number => { const now = moment() const end = moment(endDate) const diff = end.diff(now, 'days') return diff } const getRemainingDaysColor = (days: number): string => { if (days < 0) return 'text-red-600' if (days <= 7) return 'text-red-500' if (days <= 30) return 'text-orange-500' return 'text-green-600' } const getRemainingDaysText = (endDate: string): string => { const days = getRemainingDays(endDate) if (days < 0) { return `${NumberFormat(Math.abs(days))} روز گذشته` } if (days === 0) { return 'امروز آخرین روز' } if (days === 1) { return '۱ روز باقی مانده' } return `${NumberFormat(days)} روز باقی مانده` } return (
{ props.isQuikAccess &&
}
{item.name}
{item.name}
{ props.isLinkPanel &&
{props.businessName}
} { props.isLinkPanel && props.endDate &&
{getRemainingDaysText(props.endDate)}
}
{ !props.isLinkPanel &&
{item.title}
}
{ props.subscriptionId &&
{t('service.extend')}
}
) } export default ServiceItem