import dayjs from 'dayjs';

const WhatsappDateChip = ({ ts }: { ts: number }) => {
  const d = dayjs.unix(ts);
  const now = dayjs();
  let label = d.format('D MMMM');
  if (d.isSame(now, 'day')) label = 'Сегодня';
  else if (d.isSame(now.subtract(1, 'day'), 'day')) label = 'Вчера';
  else if (d.isSame(now, 'year')) label = d.format('D MMMM');
  return (
    <div className="flex justify-center my-2 sticky top-2 z-[5]">
      <div
        className="px-2.5 py-1 rounded-lg text-[12px] font-medium shadow-sm
          bg-[#e1f4e5] dark:bg-[#182c24]
          text-[var(--tg-text-secondary)]"
      >
        {label}
      </div>
    </div>
  );
};

export default WhatsappDateChip;
