"use client"
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
import { ArrowUpDown, BookType, Clock, Drama, SquareArrowOutUpRight } from "lucide-react"
import { Button } from "@/components/ui/button"
import { PubsWithGenres } from "./page"
import { TextInputCell } from "app/ui/tables/inputs/textInput"
import { selectCol } from "app/ui/tables/selectColumn"
import NumberInputCell from "app/ui/tables/inputs/numberInput"
import { pubSchema } from "app/ui/forms/schemas"
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"


const columnHelper = createColumnHelper<PubsWithGenres>()

export const columns: ColumnDef<PubsWithGenres>[] = [
  selectCol,
  {
    accessorKey: "title",
    header: ({ column }) => {
      return (
        <Button
          variant="ghost"
          onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
        >
          <span className="hidden sm:block">
            Title
          </span>
          <span className="block sm:hidden"><BookType /></span>
          <ArrowUpDown className="ml-2 h-4 w-4" />
        </Button>
      )
    },
    cell: TextInputCell,
    meta: { formSchema: pubSchema }
  },

  {
    accessorKey: "link",
    header: () => (
      <div className="mx-auto w-fit">
        <span className="hidden sm:block">Link</span>
        <span className="block sm:hidden"><SquareArrowOutUpRight /></span>
      </div>
    ),
    cell: TextInputCell,
    meta: { formSchema: pubSchema }
  },

  columnHelper.accessor("genres", {
    header: () => (
      <div className="w-fit mx-auto">
        <span className="hidden sm:block">Genres</span>
        <span className="sm:hidden"><Drama /></span>
      </div>
    ),
    cell: GenrePickerInputCell,
    filterFn: "arrIncludes"
    //TODO - write custom filter function, to account for an array of objects
  }),

  {
    accessorKey: "query_after_days",
    header: () => (
      <div>
        <span className="hidden sm:block">Query After (days)</span>
        <span className="sm:hidden"><Clock /></span>
      </div>
    ),
    cell: NumberInputCell,
    meta: {
      step: 10,
      formSchema: pubSchema
    },

  },
]

