import { useEffect, useState } from "react"; import { useSearchParams } from "react-router-dom"; import { supabase } from "../services/supabase"; import "./EmployeeCard.css"; function toDriveDirectUrl(url) { if (!url) return url; // Detectamos si es una URL de Google Drive if (url.includes("drive.google.com")) { // Expresión regular para extraer el ID const match = url.match(/(?:file\/d\/|id=)([a-zA-Z0-9_-]+)/); if (match) { const fileId = match[1]; // Usamos el endpoint de thumbnail que no tiene problemas de CORS return `https://drive.google.com/thumbnail?id=${fileId}&sz=w1000`; } } // Si es de BambooHR u otra URL, la devolvemos tal cual return url; } export default function EmployeeCard() { const [searchParams] = useSearchParams(); const employeeNumber = searchParams.get("id"); const [employee, setEmployee] = useState(null); const [loading, setLoading] = useState(true); const [notFound, setNotFound] = useState(false); useEffect(() => { async function loadEmployee() { const { data, error } = await supabase .rpc("get_carnet_publico", { p_cedula: employeeNumber }); if (error || !data || data.length === 0) { setNotFound(true); } else { setEmployee(data[0]); } setLoading(false); } loadEmployee(); }, [employeeNumber]); if (loading) { return (