import { faInfoCircle as infoIcon } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import classNames from 'classnames';
import { UncontrolledTooltip } from 'reactstrap';
import { formatHumanFriendly, parseISO } from '../../utils/dates/helpers/date';
import { useElementRef } from '../../utils/helpers/hooks';
import { prettify } from '../../utils/helpers/numbers';
import type { ShortUrl } from '../data';
import { ShortUrlDetailLink } from './ShortUrlDetailLink';
import './ShortUrlVisitsCount.scss';
interface ShortUrlVisitsCountProps {
shortUrl?: ShortUrl | null;
visitsCount: number;
active?: boolean;
asLink?: boolean;
}
export const ShortUrlVisitsCount = (
{ visitsCount, shortUrl, active = false, asLink = false }: ShortUrlVisitsCountProps,
) => {
const { maxVisits, validSince, validUntil } = shortUrl?.meta ?? {};
const hasLimit = !!maxVisits || !!validSince || !!validUntil;
const visitsLink = (
{prettify(visitsCount)}
);
if (!hasLimit) {
return visitsLink;
}
const tooltipRef = useElementRef();
return (
<>
{visitsLink}
{maxVisits && <> / {prettify(maxVisits)}>}
{maxVisits && (
-
This short URL will not accept more than {prettify(maxVisits)} visit{maxVisits === 1 ? '' : 's'}.
)}
{validSince && (
-
This short URL will not accept visits
before {formatHumanFriendly(parseISO(validSince))}.
)}
{validUntil && (
-
This short URL will not accept visits
after {formatHumanFriendly(parseISO(validUntil))}.
)}
>
);
};