import { Table } from "@tanstack/react-table";

import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";
import { useGlobal } from "@/context/global";
import { GoToFirst, GoToLast, GoToNext, GoToPrevious } from "./_buttons";

interface DataTablePaginationProps<TData> {
  table: Table<TData>;
}

export function DataTablePagination<TData>({
  table,
}: DataTablePaginationProps<TData>) {
  const { dict } = useGlobal();

  return (
    <div className="mt-4 flex items-center justify-between px-2">
      <div className="text-muted-foreground flex-1 text-sm"></div>
      <div className="flex items-center space-x-6 lg:space-x-8">
        <div className="flex items-center space-x-2">
          <p className="text-sm font-medium">
            {dict.pages.project_list.table.navigation.rows_per_page}
          </p>
          <Select
            value={`${table.getState().pagination.pageSize}`}
            onValueChange={(value) => {
              table.setPageSize(Number(value));
            }}
          >
            <SelectTrigger className="h-8 w-[70px]">
              <SelectValue placeholder={table.getState().pagination.pageSize} />
            </SelectTrigger>
            <SelectContent side="top">
              {[10, 20, 30, 40, 50].map((pageSize) => (
                <SelectItem key={pageSize} value={`${pageSize}`}>
                  {pageSize}
                </SelectItem>
              ))}
            </SelectContent>
          </Select>
        </div>
        <div className="flex w-[100px] items-center justify-center text-sm font-medium">
          {dict.pages.project_list.table.navigation.page}{" "}
          {table.getState().pagination.pageIndex + 1}
          {" / "}
          {table.getPageCount()}
        </div>
        <div className="flex items-center gap-1">
          <GoToFirst table={table} />
          <GoToPrevious table={table} />
          <GoToNext table={table} />
          <GoToLast table={table} />
        </div>
      </div>
    </div>
  );
}
