"use client";

import { Info } from "lucide-react";

import { displayCell } from "@/app/customer/_lib/asset-column-builders";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { formatApiDate } from "@/lib/format/dates";

/** Yii1 getMaturityDateHtml tooltip when LV/Dc maturity has passed with no sale child. */
export const MATURITY_NO_SALE_TIP = "Maturity date passed and no sale entry";

/**
 * Maturity date cell matching Yii1 `maturityDateHtml`: the formatted date plus a
 * red info icon when the date has passed and no sale child exists.
 */
export function MaturityDateWithNoSaleHint({
  date,
  maturedWithoutSale,
}: {
  date: string | null | undefined;
  maturedWithoutSale?: boolean;
}) {
  return (
    <span className="inline-flex items-center gap-1 whitespace-nowrap text-sm">
      {displayCell(formatApiDate(date, undefined, ""))}
      {maturedWithoutSale ? (
        <Tooltip>
          <TooltipTrigger asChild>
            <button
              type="button"
              className="inline-flex cursor-pointer text-red-600 dark:text-red-400"
              aria-label={MATURITY_NO_SALE_TIP}
            >
              <Info className="size-3.5" />
            </button>
          </TooltipTrigger>
          <TooltipContent>{MATURITY_NO_SALE_TIP}</TooltipContent>
        </Tooltip>
      ) : null}
    </span>
  );
}
