import { useRoles } from '../../roles/hooks/useRoles'
import type { RolDto } from '../../roles/api/types'

export interface RolOption {
  codigo: string
  nombre: string
}

interface UseRolesForSelectResult {
  options: RolOption[]
  isLoading: boolean
  isError: boolean
}

// Returns only ACTIVE roles, mapped to a select-friendly shape.
export function useRolesForSelect(): UseRolesForSelectResult {
  const { data, isLoading, isError } = useRoles()
  const options: RolOption[] = (data ?? [])
    .filter((r: RolDto) => r.activo)
    .map((r) => ({ codigo: r.codigo, nombre: r.nombre }))
  return { options, isLoading, isError }
}
