"use client";

import { PortfolioPlanRecommendation } from "@/app/db/schema/recommendations";
import { formatNumber } from "@/app/utils";
import { ColumnDef } from "@tanstack/react-table";

const formattedQuantity = {
  m2: "m²",
  part: " Units",
};

const formattedMeasure = {
  internal_wall_insulation: "Internal Wall Insulation",
  external_wall_insulation: "External Wall Insulation",
  suspended_floor_insulation: "Suspended Floor Insulation",
  solid_floor_insulation: "Solid Floor Insulation",
  mechanical_ventilation: "Mechanical Ventilation",
  loft_insulation: "Loft Insulation",
  cavity_wall_insulation: "Cavity Wall Insulation",
  flat_roof_insulation: "Flat Roof Insulation",
  exposed_floor_insulation: "Exposed Floor Insulation",
  room_roof_insulation: "Room Roof Insulation",
};

export const portfolioPlanColumns: ColumnDef<PortfolioPlanRecommendation>[] = [
  {
    accessorKey: "materialType",
    header: "Retrofit Measure",
    cell: ({ row }) => {
      return (
        <div>
          {
            formattedMeasure[
              row.original.materialType as keyof typeof formattedMeasure
            ]
          }
        </div>
      );
    },
  },
  {
    accessorKey: "numberOfProperties",
    header: "Number of properties",
    cell: ({ row }) => {
      return (
        <div className="text-center">{row.original.numberOfProperties}</div>
      );
    },
  },
  {
    accessorKey: "quantity",
    header: "Quantity required",
    cell: ({ row }) => {
      return (
        <div>
          {row.original.quantity +
            formattedQuantity[
              row.original.quantityUnit as keyof typeof formattedQuantity
            ]}
        </div>
      );
    },
  },
  {
    accessorKey: "estimatedCost",
    header: "Estimated Cost",
    cell: ({ row }) => {
      return <div>{"£" + formatNumber(row.original.estimatedCost)}</div>;
    },
  },
];
