'use client';

import { Button } from '@repo/shadcn/components/ui/button';
import { DataTableSearch } from '@repo/shadcn/table/data-table-search';
import { Plus } from 'lucide-react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useTrainingTableFilters } from './use-training-table-filters';

export default function TrainingTableAction() {
  const { searchQuery, setPage, setSearchQuery } = useTrainingTableFilters();
  const router = useRouter();
  const { data: session } = useSession();
  const role = session?.user.role[0]?.rol;
  return (
    <div className="flex items-center justify-between mt-4 ">
      <div className="flex items-center gap-4 flex-grow">
        <DataTableSearch
          searchKey="nombre"
          searchQuery={searchQuery || ''}
          setSearchQuery={setSearchQuery}
          setPage={setPage}
        />
      </div>{' '}
      {['superadmin', 'autoridad', 'admin', 'manager', 'coordinators'].includes(
        role ?? '',
      ) && (
          <Button
            onClick={() => router.push(`/dashboard/formulario/nuevo`)}
            size="sm"
          >
            <Plus className="h-4 w-4" />
            <span className="hidden md:inline">Nuevo Registro</span>
          </Button>
        )}
    </div>
  );
}
