"use client";

import type { ColumnDef } from "@tanstack/react-table";
import Link from "next/link";

import { Button } from "@/components/ui/button";

import { buildCreateMarketPriceHref } from "./constants";
import type { MissingMarketPriceIsinRow } from "./schema";

export function createMissingMarketPriceIsinColumns(
  pageOffset: number,
): ColumnDef<MissingMarketPriceIsinRow>[] {
  return [
    {
      id: "rowNumber",
      header: "#",
      enableColumnFilter: false,
      cell: ({ row }) => (
        <span className="text-muted-foreground text-sm tabular-nums">
          {pageOffset + row.index + 1}
        </span>
      ),
    },
    {
      accessorKey: "ticker",
      header: "ISIN",
      cell: ({ row }) => (
        <span className="font-mono text-sm">
          {row.original.ticker}{" "}
          <strong className="font-semibold text-foreground">
            ({row.original.fTypeLabel})
          </strong>
        </span>
      ),
    },
    {
      id: "option",
      header: "Option",
      enableColumnFilter: false,
      cell: ({ row }) => (
        <Button variant="link" size="sm" className="h-auto px-0" asChild>
          <Link
            href={buildCreateMarketPriceHref(
              row.original.ticker,
              row.original.fType,
              row.original.fTypeLabel,
            )}
          >
            Add Price
          </Link>
        </Button>
      ),
    },
  ];
}
