import { useAuthStore } from '@/src/store/authStore'
import { verifyAccess } from '@/src/utils/accessControl'
import Link from 'next/link'

import { FaEye, FaPencilAlt } from 'react-icons/fa'
import { FaLock, FaRegTrashCan } from 'react-icons/fa6'

interface Props {
  studentId: string
  onChangePassword: (studentId: string) => void
  onDelete: (studentId: string) => void
}

export const ActionButtons = ({
  studentId,
  onChangePassword,
  onDelete,
}: Props) => {
  const { user } = useAuthStore()

  const handleChangePassword = () => onChangePassword(studentId)

  const handleDelete = () => onDelete(studentId)

  return (
    <div className="flex space-x-3 justify-center">
      <Link
        href={`students/${studentId}/grades-report`}
        className="text-gray-600 hover:underline flex items-center space-x-1">
        <FaEye />
        <span className="text-nowrap">Ver Reporte de notas</span>
      </Link>
      <Link
        href="/students"
        className="text-gray-600 hover:underline flex items-center space-x-1">
        <FaEye />
        <span className="text-nowrap">Reporte de matrícula</span>
      </Link>

      {user && user.role && (
        <>
          {verifyAccess(user.role, 'students_edit') && (
            <>
              <button
                className="text-gray-600 hover:underline flex items-center space-x-1 text-nowrap"
                onClick={handleChangePassword}>
                <FaLock />
                <span>Cambiar contraseña</span>
              </button>
              <Link
                href={`/students/${studentId}/edit`}
                className="text-blue-600 hover:underline flex items-center space-x-1">
                <FaPencilAlt />
                <span>Editar</span>
              </Link>
            </>
          )}
          {verifyAccess(user.role, 'students_delete') && (
            <button
              className="text-red-600 hover:underline flex items-center space-x-1"
              onClick={handleDelete}>
              <FaRegTrashCan />
              <span>Eliminar</span>
            </button>
          )}
        </>
      )}
    </div>
  )
}
