"use client";

import {
  Feature,
  GeneralFeature,
  NonInstrusiveFeature,
  Rating,
} from "@/app/db/schema/property";
import { Badge } from "@/app/shadcn_components/ui/badge";
import { ColumnDef } from "@tanstack/react-table";

function RatingBadge({ rating }: { rating: Rating }) {
  const colourMap = {
    "Very good": "bg-green-500 hover:bg-green-600",
    Good: "bg-green-300 hover:bg-green-400",
    Poor: "bg-yellow-300 hover:bg-yellow-400",
    "Very poor": "bg-red-500 hover:bg-red-600",
    "N/A": "bg-gray-500 hover:bg-gray-600",
  };
  const ratingConfig = colourMap[rating];
  return <Badge className={ratingConfig}>{rating}</Badge>;
}

export const retrofitColumns: ColumnDef<Feature>[] = [
  {
    accessorKey: "feature",
    header: "Feature",
  },
  {
    accessorKey: "description",
    header: "Description",
  },
  {
    accessorKey: "rating",
    header: "Rating",
    cell: ({ row }) => {
      return (
        <div className="">
          <RatingBadge rating={row.getValue("rating")} />
        </div>
      );
    },
  },
];

export const generalColumns: ColumnDef<GeneralFeature>[] = [
  {
    accessorKey: "feature",
    header: "Feature",
    size: 100,
  },
  {
    accessorKey: "description",
    header: "Description",
  },
];

export const nonInstrusiveColumns: ColumnDef<NonInstrusiveFeature>[] = [
  {
    accessorKey: "title",
    header: "Feature",
    size: 100,
  },
  {
    accessorKey: "note",
    header: "Recorded Observation",
  },
];
