@birhaus/patterns
Version:
BIRHAUS v3.0 Radical Minimalist Pattern Components - Glass morphism ApprovalWorkflow, RoleManager, SmartSearch, FinancialDashboard, AuditTimeline
13 lines • 69.5 kB
JavaScript
import ha,{forwardRef,useState,useCallback,useEffect,useRef,useMemo}from'react';import {AlertTriangle,RotateCcw,Building,DollarSign,GraduationCap,Settings,X,AlertCircle,Plus,ChevronUp,ChevronDown,Trash2,Save,Check,UserCheck,Search,Filter,Clock,CheckCircle,XCircle,User,TrendingUp,TrendingDown,Wallet,RefreshCw,Banknote,CreditCard,Calendar,ArrowUpRight,ArrowDownRight,Download,Info,Target,EyeOff,Eye,Minus,BarChart3}from'lucide-react';import {formatDistanceToNow}from'date-fns';import {es}from'date-fns/locale';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {useBirhausThemeV3}from'@birhaus/themes';function pa(...e){return e.filter(Boolean).join(" ")}var ba={"iglesia.creada":"cre\xF3 una iglesia","iglesia.actualizada":"actualiz\xF3 una iglesia","iglesia.eliminada":"elimin\xF3 una iglesia","pastor.creado":"registr\xF3 un pastor","pastor.actualizado":"actualiz\xF3 un pastor","pastor.eliminado":"elimin\xF3 un pastor","donacion.registrada":"registr\xF3 una donaci\xF3n","donacion.anulada":"anul\xF3 una donaci\xF3n","transferencia.creada":"cre\xF3 una transferencia","transferencia.completada":"complet\xF3 una transferencia","gasto.registrado":"registr\xF3 un gasto","gasto.aprobado":"aprob\xF3 un gasto","gasto.rechazado":"rechaz\xF3 un gasto","usuario.login":"inici\xF3 sesi\xF3n","usuario.logout":"cerr\xF3 sesi\xF3n","resumen.enviado":"envi\xF3 un resumen","resumen.aprobado":"aprob\xF3 un resumen","resumen.rechazado":"rechaz\xF3 un resumen",create:"cre\xF3",update:"actualiz\xF3",delete:"elimin\xF3",approve:"aprob\xF3",reject:"rechaz\xF3",login:"inici\xF3 sesi\xF3n",logout:"cerr\xF3 sesi\xF3n"},za={creada:"text-green-600",creado:"text-green-600",registrada:"text-green-600",registrado:"text-green-600",actualizada:"text-blue-600",actualizado:"text-blue-600",eliminada:"text-red-600",eliminado:"text-red-600",anulada:"text-yellow-600",aprobado:"text-green-600",rechazado:"text-red-600",completada:"text-green-600",enviado:"text-blue-600",login:"text-gray-500",logout:"text-gray-500"};function Ze({events:e,showFilters:a=true,maxHeight:r="600px",className:s="",emptyMessage:d="No hay eventos que mostrar",filterAllEntitiesLabel:l="Todas las entidades",filterAllActionsLabel:n="Todas las acciones",clearFiltersLabel:v="Limpiar filtros",showDetailsLabel:i="Ver detalles",hideDetailsLabel:h="Ocultar detalles"}){let[f,p]=useState("all"),[y,N]=useState("all"),[k,M]=useState(new Set),{entities:u,verbs:T}=useMemo(()=>{let c=new Set,R=new Set;return e.forEach(L=>{L.entity&&c.add(L.entity),R.add(L.verb);}),{entities:Array.from(c).sort(),verbs:Array.from(R).sort()}},[e]),C=useMemo(()=>e.filter(c=>!(f!=="all"&&c.entity!==f||y!=="all"&&c.verb!==y)),[e,f,y]),S=c=>{let R=new Set(k);R.has(c)?R.delete(c):R.add(c),M(R);},I=c=>{let R=c.split(".").pop()||"";return za[R]||"text-gray-700"},pe=c=>!c||Object.keys(c).length===0?null:jsx("div",{className:"mt-2 p-3 bg-gray-50 rounded-md text-xs space-y-1 border",children:Object.entries(c).map(([R,L])=>jsxs("div",{className:"flex gap-2",children:[jsxs("span",{className:"text-gray-500 font-medium min-w-20",children:[R,":"]}),jsx("span",{className:"text-gray-700 flex-1",children:typeof L=="object"?JSON.stringify(L,null,2):String(L)})]},R))});return jsxs("div",{className:pa("space-y-4",s),"data-birhaus-component":"audit-timeline",children:[a&&(u.length>0||T.length>0)&&jsxs("div",{className:"flex gap-3 items-center p-3 bg-gray-50 border border-gray-200 rounded-md",children:[jsx(Filter,{className:"h-4 w-4 text-gray-400"}),u.length>0&&jsxs("select",{value:f,onChange:c=>p(c.target.value),className:"px-3 py-1 border border-gray-300 rounded-md text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500",children:[jsx("option",{value:"all",children:l}),u.map(c=>jsx("option",{value:c,children:c.charAt(0).toUpperCase()+c.slice(1)},c))]}),T.length>0&&jsxs("select",{value:y,onChange:c=>N(c.target.value),className:"px-3 py-1 border border-gray-300 rounded-md text-sm bg-white focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500",children:[jsx("option",{value:"all",children:n}),T.map(c=>jsx("option",{value:c,children:ba[c]||c},c))]}),(f!=="all"||y!=="all")&&jsx("button",{onClick:()=>{p("all"),N("all");},className:"text-sm text-primary-600 hover:text-primary-700 hover:underline focus:outline-none focus:ring-2 focus:ring-primary-500 px-2 py-1 rounded",children:v})]}),jsx("div",{className:"space-y-2 overflow-y-auto pr-2 scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-gray-100",style:{maxHeight:r},children:C.length===0?jsxs("div",{className:"text-center py-8 text-gray-500 bg-gray-50 rounded-lg border-2 border-dashed border-gray-200",children:[jsx(Clock,{className:"h-8 w-8 text-gray-400 mx-auto mb-2"}),jsx("p",{children:d})]}):C.map((c,R)=>{let L=k.has(c.id),O=c.payload&&Object.keys(c.payload).length>0;return jsxs("div",{className:"flex gap-3 p-4 bg-white border border-gray-200 rounded-lg hover:border-gray-300 hover:shadow-sm transition-all duration-150",children:[jsxs("div",{className:"flex flex-col items-center",children:[jsx("div",{className:"w-2 h-2 rounded-full bg-primary-600 mt-2 flex-shrink-0"}),R<C.length-1&&jsx("div",{className:"w-px flex-1 bg-gray-200 mt-2"})]}),jsx("div",{className:"flex-1 min-w-0",children:jsxs("div",{className:"flex items-start justify-between gap-2",children:[jsxs("div",{className:"flex-1",children:[jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[jsx(User,{className:"h-3 w-3 text-gray-400"}),jsx("span",{className:"text-sm font-medium text-gray-900",children:c.actor_name||"Usuario"}),jsx("span",{className:pa("text-sm font-medium",I(c.verb)),children:ba[c.verb]||c.verb}),c.entity&&jsx("span",{className:"text-xs px-2 py-1 bg-gray-200 text-gray-700 rounded-full",children:c.entity})]}),c.entity_id&&jsxs("div",{className:"text-xs text-gray-500 mt-1 font-mono",children:["ID: ",c.entity_id]}),O&&jsx("button",{onClick:()=>S(c.id),className:"flex items-center gap-1 mt-2 text-xs text-primary-600 hover:text-primary-700 hover:underline focus:outline-none focus:ring-2 focus:ring-primary-500 px-1 py-0.5 rounded",children:L?jsxs(Fragment,{children:[jsx(ChevronUp,{className:"h-3 w-3"}),h]}):jsxs(Fragment,{children:[jsx(ChevronDown,{className:"h-3 w-3"}),i]})}),L&&pe(c.payload)]}),jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500 whitespace-nowrap",children:[jsx(Clock,{className:"h-3 w-3"}),jsx("span",{title:new Date(c.created_at).toLocaleString("es-ES"),children:formatDistanceToNow(new Date(c.created_at),{addSuffix:true,locale:es})})]})]})})]},c.id)})})]})}function ea(){let[e,a]=useState([]);return {events:e,addEvent:d=>{let l={...d,id:`audit_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,created_at:new Date().toISOString()};return a(n=>[l,...n]),l},clearEvents:()=>{a([]);}}}function _a({events:e,showFilters:a=true,maxHeight:r="600px",glassVariant:s="medium",floatingCards:d=true,magneticEvents:l=true,enableGlass:n=true,reducedMotion:v=false,themeName:i="financial",glowCritical:h=true,emptyMessage:f="No hay eventos de auditor\xEDa para mostrar",filterAllEntitiesLabel:p="Todas las entidades",filterAllActionsLabel:y="Todas las acciones",clearFiltersLabel:N="Limpiar filtros",showDetailsLabel:k="Ver detalles",hideDetailsLabel:M="Ocultar detalles",className:u,...T}){let C=useBirhausThemeV3(i),S=["birhaus-audit-timeline-v3","transition-all duration-500 ease-smooth",n?"backdrop-blur-lg bg-white/70 rounded-3xl border-white/30 border":"bg-white rounded-lg border border-gray-200",d?"p-8 shadow-2xl":"p-6 shadow-lg",u||""].filter(Boolean).join(" ");return jsxs("div",{className:S,"data-birhaus-component":"audit-timeline-v3","data-birhaus-version":"3.0","data-birhaus-theme":i,style:{maxHeight:r,"--birhaus-glass-blur":n?"12px":"0px","--birhaus-border-radius":"24px","--birhaus-spacing-generous":"2rem","--birhaus-animation-duration":v?"0ms":"300ms",...C?.cssVariables},children:[jsx(Ze,{events:e,showFilters:a,maxHeight:r,emptyMessage:f,filterAllEntitiesLabel:p,filterAllActionsLabel:y,clearFiltersLabel:N,showDetailsLabel:k,hideDetailsLabel:M,className:"space-y-6",...T}),n&&e.length>0&&jsx("div",{className:"absolute left-8 top-20 bottom-8 w-0.5 pointer-events-none",style:{background:`linear-gradient(180deg,
rgba(59, 130, 246, 0.3) 0%,
rgba(156, 163, 175, 0.2) 100%)`,backdropFilter:"blur(8px)",borderRadius:"2px"}})]})}function Ua({glass:e=true,generousSpacing:a=true,radicalBorderRadius:r=true,magnetic:s=true,glow:d=false,severity:l="info",expanded:n=false,onToggleExpanded:v,...i}){let h=()=>{let p=["transition-all duration-300 ease-smooth","border hover:shadow-xl relative"];return e?p.push("backdrop-blur-md bg-white/80 border-white/30"):p.push("bg-white border-gray-200"),a?p.push("p-6"):p.push("p-4"),r?p.push("rounded-2xl"):p.push("rounded-lg"),s&&p.push("hover:scale-[1.02] hover:-translate-y-1 cursor-pointer"),d&&l==="critical"?p.push("shadow-2xl shadow-red-500/20 ring-2 ring-red-500/30"):d&&l==="error"&&p.push("shadow-xl shadow-red-500/10 ring-1 ring-red-500/20"),p.join(" ")},f=()=>{switch(l){case "critical":return "text-red-600 bg-red-100";case "error":return "text-red-600 bg-red-50";case "warning":return "text-yellow-600 bg-yellow-50";default:return "text-blue-600 bg-blue-50"}};return jsxs("div",{className:h(),onClick:v,children:[jsxs("div",{className:"flex items-start justify-between mb-4",children:[jsxs("div",{className:"flex items-center space-x-3",children:[jsx("div",{className:`px-3 py-1 rounded-full text-xs font-medium ${f()}`,children:i.verb}),jsx("div",{className:"text-sm text-gray-600",children:i.actor_name||i.actor_id})]}),jsx("div",{className:"text-xs text-gray-500",children:new Date(i.created_at).toLocaleString("es-ES")})]}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"text-sm text-gray-800",children:[jsx("span",{className:"font-medium",children:i.verb}),i.entity&&jsxs("span",{children:[" en ",jsx("span",{className:"font-medium",children:i.entity})]}),i.entity_id&&jsxs("span",{className:"text-gray-600",children:[" (ID: ",i.entity_id,")"]})]}),n&&Object.keys(i.payload||{}).length>0&&jsxs("div",{className:`mt-4 p-4 rounded-xl ${e?"bg-white/50 border border-white/40":"bg-gray-50 border border-gray-200"}`,children:[jsx("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Detalles del evento:"}),jsx("pre",{className:"text-xs text-gray-600 overflow-x-auto",children:JSON.stringify(i.payload,null,2)})]})]}),Object.keys(i.payload||{}).length>0&&jsx("div",{className:"mt-3 flex justify-center",children:jsxs("button",{className:"text-xs text-gray-500 hover:text-gray-700 flex items-center space-x-1",children:[jsx("span",{children:n?"Ocultar detalles":"Ver detalles"}),jsx("svg",{className:`h-3 w-3 transition-transform ${n?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})})]})}function Oa(e,a){let r=ea(),[s,d]=ha.useState(a||{}),l=ha.useCallback(n=>{d(v=>({...v,...n}));},[]);return {...r,v3Configuration:s,updateV3Configuration:l,enableGlassMorphism:()=>l({enableGlass:true,glassVariant:"medium"}),enableFloatingCards:()=>l({floatingCards:true}),enableMagneticEvents:()=>l({magneticEvents:true}),setTheme:n=>l({themeName:n}),enablePerformanceMode:()=>l({reducedMotion:true,enableGlass:false,magneticEvents:false}),isV3Enabled:true}}var nt={idioma:"es",moneda:"PYG",formatoNumero:"es-PY",mostrarGraficos:true,mostrarObjetivos:true,mostrarProyecciones:true,diasProyeccion:7,actualizacionAutomatica:false,intervaloActualizacion:15};function ot({datos:e,color:a,altura:r=60,mostrarPuntos:s=false}){let{ruta:d,area:l,minY:n,maxY:v}=useMemo(()=>{if(e.length===0)return {ruta:"",area:"",minY:0,maxY:0};let i=e.map(T=>T.valor),h=Math.min(...i),f=Math.max(...i),p=f-h||1,y=200,N=4,k=e.map((T,C)=>{let S=C/(e.length-1)*(y-N*2)+N,I=r-N-(T.valor-h)/p*(r-N*2);return {x:S,y:I,valor:T.valor}}),M=k.reduce((T,C,S)=>`${T} ${S===0?"M":"L"} ${C.x} ${C.y}`,""),u=`${M} L ${k[k.length-1].x} ${r-N} L ${N} ${r-N} Z`;return {ruta:M,area:u,minY:h,maxY:f}},[e,r]);return e.length===0?jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:jsx(BarChart3,{className:"w-6 h-6"})}):jsxs("svg",{width:"200",height:r,className:"overflow-visible",children:[jsx("path",{d:l,fill:`url(#gradiente-${a.replace("#","")})`,opacity:.2}),jsx("path",{d,stroke:a,strokeWidth:2,fill:"none",strokeLinecap:"round",strokeLinejoin:"round"}),jsx("defs",{children:jsxs("linearGradient",{id:`gradiente-${a.replace("#","")}`,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:[jsx("stop",{offset:"0%",stopColor:a,stopOpacity:.4}),jsx("stop",{offset:"100%",stopColor:a,stopOpacity:0})]})}),s&&d&&e.map((i,h)=>{let f=h/(e.length-1)*192+4,p=r-4-(i.valor-n)/(v-n||1)*(r-8);return jsx("circle",{cx:f,cy:p,r:"2",fill:a,className:"opacity-60 hover:opacity-100 transition-opacity"},h)})]})}function lt({tendencia:e,tama\u00F1o:a="mediano",mostrarTexto:r=true,idioma:s}){let d=e.direccion==="subida"?TrendingUp:e.direccion==="bajada"?TrendingDown:Minus,l=e.direccion==="subida"?"text-green-600":e.direccion==="bajada"?"text-red-600":"text-gray-500",n=a==="peque\xF1o"?"w-3 h-3":a==="grande"?"w-5 h-5":"w-4 h-4",v=s==="es"?e.direccion==="subida"?"Subida":e.direccion==="bajada"?"Bajada":"Estable":e.direccion==="subida"?"Up":e.direccion==="bajada"?"Down":"Stable";return jsxs("div",{className:`flex items-center space-x-1 ${l}`,children:[jsx(d,{className:n}),r&&jsxs("div",{className:"flex items-center space-x-1",children:[jsxs("span",{className:`font-medium ${a==="peque\xF1o"?"text-xs":a==="grande"?"text-base":"text-sm"}`,children:[e.porcentaje>=0?"+":"",e.porcentaje.toFixed(1),"%"]}),jsxs("span",{className:"text-xs text-gray-500",children:["(",v,")"]})]})]})}function dt({estado:e,tama\u00F1o:a="mediano",idioma:r}){let s={saludable:{icono:CheckCircle,color:"text-green-600 bg-green-100",etiquetaEs:"Saludable",etiquetaEn:"Healthy"},precaucion:{icono:AlertCircle,color:"text-yellow-600 bg-yellow-100",etiquetaEs:"Precauci\xF3n",etiquetaEn:"Warning"},critico:{icono:AlertCircle,color:"text-red-600 bg-red-100",etiquetaEs:"Cr\xEDtico",etiquetaEn:"Critical"}},{icono:d,color:l,etiquetaEs:n,etiquetaEn:v}=s[e],i=a==="peque\xF1o"?"w-3 h-3":a==="grande"?"w-5 h-5":"w-4 h-4";return jsxs("div",{className:`flex items-center space-x-1 px-2 py-1 rounded-full text-xs ${l}`,children:[jsx(d,{className:i}),jsx("span",{className:"font-medium",children:r==="es"?n:v})]})}function ct({metrica:e,configuracion:a,compacto:r=false,mostrarGrafico:s=true,alSeleccionar:d,alMostrarDetalles:l}){let[n,v]=useState(s),i=useMemo(()=>{let y=N=>new Intl.NumberFormat(a.formatoNumero,{style:"currency",currency:a.moneda,minimumFractionDigits:a.moneda==="PYG"?0:2,maximumFractionDigits:a.moneda==="PYG"?0:2}).format(N);return e.unidad==="moneda"?y(e.valor):e.unidad==="porcentaje"?`${e.valor.toFixed(1)}%`:`${e.valor.toLocaleString(a.formatoNumero)}`},[e.valor,e.unidad,a]),h=useMemo(()=>{if(!e.objetivo)return null;let y=e.valor/e.objetivo*100;return Math.min(y,100)},[e.valor,e.objetivo]),f=useMemo(()=>{switch(e.estado){case "saludable":return "#10b981";case "precaucion":return "#f59e0b";case "critico":return "#ef4444";default:return "#6366f1"}},[e.estado]),p=useMemo(()=>{switch(e.categoria){case "ingresos":return "bg-green-100 text-green-800";case "gastos":return "bg-red-100 text-red-800";case "balance":return "bg-blue-100 text-blue-800";case "proyeccion":return "bg-purple-100 text-purple-800";default:return "bg-gray-100 text-gray-800"}},[e.categoria]);return jsxs("div",{className:`
relative overflow-hidden transition-all duration-200 hover:shadow-lg
bg-white rounded-xl shadow-sm border border-gray-200
${r?"p-4":"p-6"}
${d?"cursor-pointer hover:border-blue-300":""}
${e.estado==="critico"?"ring-2 ring-red-200 ring-opacity-50":""}
${e.estado==="precaucion"?"ring-2 ring-yellow-200 ring-opacity-50":""}
${e.estado==="saludable"?"ring-2 ring-green-200 ring-opacity-30":""}
`,onClick:()=>d?.(e.id),children:[jsxs("div",{className:"flex items-start justify-between mb-4",children:[jsxs("div",{className:"flex-1",children:[jsxs("div",{className:"flex items-center space-x-2 mb-1",children:[jsx("h3",{className:`font-semibold text-gray-900 ${r?"text-sm":"text-base"}`,children:a.idioma==="es"?e.nombreEs:e.nombreEn}),jsx("span",{className:`px-2 py-1 text-xs font-medium rounded-full ${p}`,children:e.categoria})]}),jsx("p",{className:`text-gray-600 ${r?"text-xs":"text-sm"}`,children:a.idioma==="es"?e.descripcionEs:e.descripcionEn})]}),jsxs("div",{className:"flex items-center space-x-2",children:[jsx(dt,{estado:e.estado,tama\u00F1o:r?"peque\xF1o":"mediano",idioma:a.idioma}),l&&jsx("button",{onClick:y=>{y.stopPropagation(),l(e.id);},className:"p-1 text-gray-400 hover:text-gray-600 transition-colors",children:jsx(Info,{className:"w-4 h-4"})})]})]}),jsxs("div",{className:"mb-4",children:[jsx("div",{className:`font-bold text-gray-900 ${r?"text-2xl":"text-3xl"}`,children:i}),jsxs("div",{className:"flex items-center justify-between mt-2",children:[jsx(lt,{tendencia:e.tendencia,tama\u00F1o:r?"peque\xF1o":"mediano",idioma:a.idioma}),jsx("span",{className:`text-gray-500 ${r?"text-xs":"text-sm"}`,children:e.tendencia.periodo})]})]}),a.mostrarObjetivos&&e.objetivo&&h!==null&&jsxs("div",{className:"mb-4",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxs("span",{className:`text-gray-600 flex items-center space-x-1 ${r?"text-xs":"text-sm"}`,children:[jsx(Target,{className:"w-3 h-3"}),jsx("span",{children:a.idioma==="es"?"Objetivo":"Target"})]}),jsx("span",{className:`font-medium text-gray-900 ${r?"text-xs":"text-sm"}`,children:e.unidad==="moneda"?new Intl.NumberFormat(a.formatoNumero,{style:"currency",currency:a.moneda,minimumFractionDigits:0,maximumFractionDigits:0}).format(e.objetivo):`${e.objetivo} ${e.unidad==="porcentaje"?"%":""}`})]}),jsx("div",{className:"w-full bg-gray-200 rounded-full h-2",children:jsx("div",{className:`h-2 rounded-full transition-all duration-500 ${e.estado==="saludable"?"bg-green-500":e.estado==="precaucion"?"bg-yellow-500":"bg-red-500"}`,style:{width:`${h}%`}})}),jsxs("div",{className:"flex justify-between mt-1",children:[jsx("span",{className:"text-xs text-gray-500",children:"0"}),jsxs("span",{className:"text-xs text-gray-500",children:[h.toFixed(0),"%"]})]})]}),a.mostrarGraficos&&e.datosTemporales.length>0&&jsxs("div",{className:"border-t border-gray-100 pt-4",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("span",{className:`text-gray-600 font-medium ${r?"text-xs":"text-sm"}`,children:a.idioma==="es"?"Tendencia (30 d\xEDas)":"Trend (30 days)"}),jsx("button",{onClick:y=>{y.stopPropagation(),v(!n);},className:"p-1 text-gray-400 hover:text-gray-600 transition-colors",children:n?jsx(EyeOff,{className:"w-3 h-3"}):jsx(Eye,{className:"w-3 h-3"})})]}),n&&jsx("div",{className:"flex justify-center",children:jsx(ot,{datos:e.datosTemporales,color:f,altura:r?40:60,mostrarPuntos:true})})]}),!r&&jsx("div",{className:"mt-4 pt-4 border-t border-gray-100",children:jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[jsxs("div",{children:[jsx("span",{className:"text-gray-500",children:a.idioma==="es"?"Actual":"Current"}),jsx("div",{className:"font-medium text-gray-900",children:e.unidad==="moneda"?new Intl.NumberFormat(a.formatoNumero,{style:"currency",currency:a.moneda,minimumFractionDigits:0,maximumFractionDigits:0}).format(e.tendencia.actual):`${e.tendencia.actual.toFixed(1)} ${e.unidad==="porcentaje"?"%":""}`})]}),jsxs("div",{children:[jsx("span",{className:"text-gray-500",children:a.idioma==="es"?"Anterior":"Previous"}),jsx("div",{className:"font-medium text-gray-900",children:e.unidad==="moneda"?new Intl.NumberFormat(a.formatoNumero,{style:"currency",currency:a.moneda,minimumFractionDigits:0,maximumFractionDigits:0}).format(e.tendencia.anterior):`${e.tendencia.anterior.toFixed(1)} ${e.unidad==="porcentaje"?"%":""}`})]})]})}),jsxs("div",{className:"mt-2 text-xs text-gray-400 flex items-center space-x-1",children:[jsx(Clock,{className:"w-3 h-3"}),jsxs("span",{children:[a.idioma==="es"?"Actualizado: ":"Updated: ",new Date(e.ultimaActualizacion).toLocaleString(a.formatoNumero)]})]})]})}function ra({metricas:e,posicionCaja:a,proyecciones:r=[],alertas:s=[],configuracion:d={},filtrosPeriodo:l,compacto:n=false,soloLectura:v=false,alCargarDatos:i,alCambiarPeriodo:h,alConfirmarAlerta:f,alExportarDatos:p,alSeleccionarMetrica:y,alMostrarDetalles:N,className:k="",variante:M="completo"}){let[u]=useState({...nt,...d}),[T,C]=useState(false),[S,I]=useState(false),pe=useCallback(async()=>{if(i)try{C(!0),await i();}catch(g){console.error("Error al actualizar datos financieros:",g);}finally{C(false);}},[i]),c=useCallback(g=>new Intl.NumberFormat(u.formatoNumero,{style:"currency",currency:u.moneda,minimumFractionDigits:u.moneda==="PYG"?0:2,maximumFractionDigits:u.moneda==="PYG"?0:2}).format(g),[u]),R=useCallback(g=>g>5e7?"text-green-600":g>1e7?"text-blue-600":g>0?"text-amber-600":"text-red-600",[]),L=useCallback(g=>g>5e7?{icono:TrendingUp,variante:"success"}:g>1e7?{icono:DollarSign,variante:"info"}:g>0?{icono:AlertCircle,variante:"warning"}:{icono:TrendingDown,variante:"error"},[]),O=useMemo(()=>n?e.slice(0,4):e.slice(0,7),[e,n]),_=useMemo(()=>s.filter(g=>g.prioridad==="alta"&&!g.confirmado).slice(0,3),[s]),{icono:le,variante:de}=L(a.balanceTotal);return jsxs("div",{className:`space-y-6 ${k}`,children:[_.length>0&&jsxs("div",{className:"p-4 bg-red-50 border border-red-200 rounded-xl",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsxs("div",{className:"flex items-center space-x-3",children:[jsx(AlertCircle,{className:"w-5 h-5 text-red-600"}),jsxs("div",{children:[jsxs("h3",{className:"font-medium text-red-900",children:[_.length," ",u.idioma==="es"?"Alerta":"Alert",_.length!==1?"s":"",u.idioma==="es"?" Cr\xEDtica":" Critical",_.length!==1?"s":""]}),jsx("p",{className:"text-sm text-red-700",children:u.idioma==="es"?"Requieren atenci\xF3n inmediata":"Require immediate attention"})]})]}),f&&jsxs("button",{onClick:()=>_.forEach(g=>f(g.id)),className:"px-3 py-1 text-sm font-medium text-red-700 border border-red-300 rounded-lg hover:bg-red-100 transition-colors",children:[jsx(CheckCircle,{className:"w-4 h-4 mr-1 inline"}),u.idioma==="es"?"Confirmar Todas":"Confirm All"]})]}),_.slice(0,2).map(g=>jsx("div",{className:"mt-3 p-3 bg-white rounded-lg border border-red-200",children:jsxs("div",{className:"flex items-center justify-between",children:[jsxs("div",{children:[jsx("h4",{className:"font-medium text-gray-900",children:u.idioma==="es"?g.tituloEs:g.tituloEn}),jsx("p",{className:"text-sm text-gray-600",children:u.idioma==="es"?g.mensajeEs:g.mensajeEn})]}),f&&jsx("button",{onClick:()=>f(g.id),className:"p-1 text-gray-400 hover:text-gray-600 transition-colors",children:jsx(CheckCircle,{className:"w-4 h-4"})})]})},g.id))]}),jsxs("div",{className:"overflow-hidden bg-white rounded-xl shadow-sm border border-gray-200",children:[jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 p-6 border-b border-blue-100",children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxs("div",{className:"flex items-center space-x-3",children:[jsx("div",{className:"p-2 bg-blue-500 text-white rounded-lg",children:jsx(Wallet,{className:"w-5 h-5"})}),jsxs("div",{children:[jsx("h2",{className:"text-lg font-semibold text-gray-900",children:u.idioma==="es"?"Posici\xF3n de Caja":"Cash Position"}),jsxs("p",{className:"text-sm text-gray-500",children:[u.idioma==="es"?"Actualizado ":"Updated ",new Date(a.ultimaActualizacion).toLocaleTimeString(u.formatoNumero)]})]})]}),!v&&jsxs("button",{onClick:pe,disabled:T,className:"px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 disabled:opacity-50 transition-colors",children:[jsx(RefreshCw,{className:`w-4 h-4 mr-2 inline ${T?"animate-spin":""}`}),u.idioma==="es"?"Actualizar":"Refresh"]})]}),jsxs("div",{className:"flex items-end justify-between",children:[jsxs("div",{children:[jsx("p",{className:"text-sm font-medium text-gray-600 mb-1",children:u.idioma==="es"?"Balance Total":"Total Balance"}),jsx("p",{className:`text-3xl font-bold ${R(a.balanceTotal)}`,children:c(a.balanceTotal)})]}),jsx("div",{className:`p-3 rounded-lg ${de==="success"?"bg-green-100 text-green-600":de==="info"?"bg-blue-100 text-blue-600":de==="warning"?"bg-amber-100 text-amber-600":"bg-red-100 text-red-600"}`,children:jsx(le,{className:"w-6 h-6"})})]})]}),jsx("div",{className:"p-6",children:jsxs("div",{className:"grid grid-cols-4 gap-4",children:[jsxs("div",{className:"text-center",children:[jsxs("div",{className:"flex items-center justify-center mb-2",children:[jsx(Banknote,{className:"w-4 h-4 text-green-500 mr-1"}),jsx("p",{className:"text-sm font-medium text-gray-500",children:u.idioma==="es"?"Efectivo":"Cash"})]}),jsx("p",{className:"text-lg font-semibold text-gray-900",children:c(a.cuentas.efectivo)})]}),jsxs("div",{className:"text-center border-x border-gray-200",children:[jsxs("div",{className:"flex items-center justify-center mb-2",children:[jsx(Building,{className:"w-4 h-4 text-blue-500 mr-1"}),jsx("p",{className:"text-sm font-medium text-gray-500",children:u.idioma==="es"?"Banco":"Bank"})]}),jsx("p",{className:"text-lg font-semibold text-gray-900",children:c(a.cuentas.banco)})]}),jsxs("div",{className:"text-center border-r border-gray-200",children:[jsxs("div",{className:"flex items-center justify-center mb-2",children:[jsx(Clock,{className:"w-4 h-4 text-amber-500 mr-1"}),jsx("p",{className:"text-sm font-medium text-gray-500",children:u.idioma==="es"?"Pendiente":"Pending"})]}),jsx("p",{className:"text-lg font-semibold text-amber-600",children:c(a.cuentas.pendiente)})]}),jsxs("div",{className:"text-center",children:[jsxs("div",{className:"flex items-center justify-center mb-2",children:[jsx(CreditCard,{className:"w-4 h-4 text-purple-500 mr-1"}),jsx("p",{className:"text-sm font-medium text-gray-500",children:u.idioma==="es"?"Otros":"Others"})]}),jsx("p",{className:"text-lg font-semibold text-gray-900",children:c(a.cuentas.otros)})]})]})})]}),M!=="metricas-solo"&&jsx("div",{className:`grid gap-6 ${n?"grid-cols-1 md:grid-cols-2":"grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}`,children:O.map(g=>jsx(ct,{metrica:g,configuracion:u,compacto:n,mostrarGrafico:u.mostrarGraficos,alSeleccionar:y,alMostrarDetalles:N?A=>N("metrica",A):void 0},g.id))}),u.mostrarProyecciones&&r.length>0&&M==="completo"&&jsx("div",{className:"bg-white rounded-xl shadow-sm border border-gray-200",children:jsxs("div",{className:"p-6",children:[jsxs("div",{className:"flex items-center justify-between mb-6",children:[jsxs("div",{className:"flex items-center space-x-3",children:[jsx("div",{className:"p-2 bg-gray-100 rounded-lg",children:jsx(Calendar,{className:"w-5 h-5 text-gray-600"})}),jsx("h3",{className:"text-lg font-semibold text-gray-900",children:u.idioma==="es"?`Proyecci\xF3n de Flujo - Pr\xF3ximos ${u.diasProyeccion} D\xEDas`:`Cash Flow Projection - Next ${u.diasProyeccion} Days`})]}),jsx("button",{onClick:()=>I(!S),className:"text-sm text-blue-600 hover:text-blue-700 font-medium transition-colors",children:S?u.idioma==="es"?"Ocultar detalles":"Hide details":u.idioma==="es"?"Ver detalles":"Show details"})]}),jsx("div",{className:"space-y-3",children:r.slice(0,u.diasProyeccion).map((g,A)=>{let we=A===0,ce=g.ingresosEsperados-g.gastosEsperados;return jsx("div",{className:`p-4 rounded-lg border ${we?"border-blue-200 bg-blue-50":"border-gray-200 bg-gray-50"}`,children:jsxs("div",{className:"flex items-center justify-between",children:[jsxs("div",{className:"flex-1",children:[jsxs("div",{className:"flex items-center space-x-2 mb-2",children:[jsx("p",{className:"font-medium text-gray-900",children:new Date(g.fecha).toLocaleDateString(u.formatoNumero,{weekday:"long",day:"numeric"})}),we&&jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-blue-100 text-blue-700 rounded-full",children:u.idioma==="es"?"Hoy":"Today"}),jsxs("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${g.confianza==="alta"?"bg-green-100 text-green-700":g.confianza==="media"?"bg-amber-100 text-amber-700":"bg-gray-100 text-gray-700"}`,children:[u.idioma==="es"?g.confianza==="alta"?"Alta":g.confianza==="media"?"Media":"Baja":g.confianza==="alta"?"High":g.confianza==="media"?"Medium":"Low"," ",u.idioma==="es"?"certeza":"confidence"]})]}),S&&jsxs("div",{className:"grid grid-cols-3 gap-4 mb-2 text-sm",children:[jsxs("div",{className:"flex items-center space-x-1",children:[jsx(ArrowUpRight,{className:"w-4 h-4 text-green-500"}),jsx("span",{className:"text-gray-600",children:u.idioma==="es"?"Ingresos:":"Income:"}),jsx("span",{className:"font-medium text-green-600",children:c(g.ingresosEsperados)})]}),jsxs("div",{className:"flex items-center space-x-1",children:[jsx(ArrowDownRight,{className:"w-4 h-4 text-red-500"}),jsx("span",{className:"text-gray-600",children:u.idioma==="es"?"Gastos:":"Expenses:"}),jsx("span",{className:"font-medium text-red-600",children:c(g.gastosEsperados)})]}),jsxs("div",{className:"flex items-center space-x-1",children:[jsx("span",{className:"text-gray-600",children:u.idioma==="es"?"Neto:":"Net:"}),jsxs("span",{className:`font-medium ${ce>=0?"text-green-600":"text-red-600"}`,children:[ce>=0?"+":"",c(ce)]})]})]})]}),jsxs("div",{className:"text-right",children:[jsx("p",{className:"text-sm text-gray-500 mb-1",children:u.idioma==="es"?"Balance proyectado":"Projected balance"}),jsx("p",{className:`text-lg font-semibold ${R(g.balanceProyectado)}`,children:c(g.balanceProyectado)})]})]})},A)})}),r.some(g=>g.balanceProyectado<1e7)&&jsx("div",{className:"mt-4 p-4 bg-amber-50 border border-amber-200 rounded-lg",children:jsxs("div",{className:"flex items-start space-x-3",children:[jsx(AlertCircle,{className:"w-5 h-5 text-amber-600 mt-0.5"}),jsxs("div",{className:"flex-1",children:[jsx("p",{className:"text-sm font-medium text-amber-800",children:u.idioma==="es"?"Alerta de Flujo de Caja":"Cash Flow Alert"}),jsx("p",{className:"text-sm text-amber-700 mt-1",children:u.idioma==="es"?"Se proyecta un balance bajo en los pr\xF3ximos d\xEDas. Considere acelerar cobros o postergar pagos no cr\xEDticos.":"A low balance is projected in the coming days. Consider accelerating collections or deferring non-critical payments."})]})]})})]})}),!v&&p&&M==="completo"&&jsxs("div",{className:"flex items-center justify-end space-x-2 pt-4 border-t border-gray-200",children:[jsxs("button",{onClick:()=>p("json"),className:"px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors",children:[jsx(Download,{className:"w-4 h-4 mr-2 inline"}),"JSON"]}),jsxs("button",{onClick:()=>p("csv"),className:"px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors",children:[jsx(Download,{className:"w-4 h-4 mr-2 inline"}),"CSV"]}),jsxs("button",{onClick:()=>p("pdf"),className:"px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors",children:[jsx(Download,{className:"w-4 h-4 mr-2 inline"}),"PDF"]})]})]})}function ut({glassVariant:e="medium",floatingCards:a=true,magneticInteractions:r=true,enableGlass:s=true,reducedMotion:d=false,themeName:l="financial",glowAlerts:n=true,className:v,configuracion:i={idioma:"es",moneda:"USD",formatoNumero:"es-PY",mostrarGraficos:true,mostrarObjetivos:true,mostrarProyecciones:true,diasProyeccion:30,actualizacionAutomatica:true,intervaloActualizacion:5},...h}){useBirhausThemeV3(l);let p={...i},y=["birhaus-financial-dashboard-v3","transition-all duration-500 ease-smooth",s?"backdrop-blur-lg bg-white/70 border-white/30":"",a?"p-8 space-y-8":"p-6 space-y-6",v||""].filter(Boolean).join(" ");return jsxs("div",{className:y,"data-birhaus-component":"financial-dashboard-v3","data-birhaus-version":"3.0","data-birhaus-theme":l,children:[jsx(ra,{...h,configuracion:p,className:"space-y-6"}),s&&jsx("div",{className:"absolute inset-0 pointer-events-none rounded-3xl",style:{background:`linear-gradient(135deg,
rgba(255, 255, 255, 0.1) 0%,
rgba(255, 255, 255, 0.05) 100%)`,backdropFilter:"blur(16px) saturate(180%)",border:"1px solid rgba(255, 255, 255, 0.2)",zIndex:-1}})]})}function gt({glass:e=true,generousSpacing:a=true,radicalBorderRadius:r=true,magnetic:s=true,glow:d=false,estado:l,...n}){return jsxs("div",{className:(()=>{let i=["transition-all duration-300 ease-smooth","border hover:shadow-xl"];return e?i.push("backdrop-blur-md bg-white/80 border-white/30"):i.push("bg-white border-gray-200"),a?i.push("p-8"):i.push("p-6"),r?i.push("rounded-3xl"):i.push("rounded-lg"),s&&i.push("hover:scale-105 hover:-translate-y-1 cursor-pointer"),d&&l==="critico"&&i.push("shadow-2xl shadow-red-500/20 animate-pulse"),i.join(" ")})(),children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("h3",{className:"text-lg font-semibold text-gray-900",children:n.nombreEs}),jsx("div",{className:`px-3 py-1 rounded-full text-xs font-medium ${l==="saludable"?"bg-green-100 text-green-800":l==="precaucion"?"bg-yellow-100 text-yellow-800":"bg-red-100 text-red-800"}`,children:l==="saludable"?"Saludable":l==="precaucion"?"Precauci\xF3n":"Cr\xEDtico"})]}),jsxs("div",{className:"space-y-4",children:[jsx("div",{className:"text-3xl font-bold text-gray-900",children:n.unidad==="moneda"?`$${n.valor.toLocaleString()}`:n.unidad==="porcentaje"?`${n.valor}%`:n.valor.toLocaleString()}),jsxs("div",{className:"flex items-center space-x-2",children:[jsx("div",{className:`flex items-center text-sm ${n.tendencia.direccion==="subida"?"text-green-600":n.tendencia.direccion==="bajada"?"text-red-600":"text-gray-600"}`,children:jsxs("span",{children:[n.tendencia.porcentaje>0?"+":"",n.tendencia.porcentaje,"%"]})}),jsxs("span",{className:"text-sm text-gray-500",children:["vs ",n.tendencia.periodo]})]}),jsx("p",{className:"text-sm text-gray-600",children:n.descripcionEs})]})]})}function pt(e){let[a,r]=ha.useState(e||{}),s=ha.useCallback(d=>{r(l=>({...l,...d}));},[]);return {configuration:a,updateConfiguration:s,enableGlassMorphism:()=>s({enableGlass:true,glassVariant:"medium"}),enableFloatingCards:()=>s({floatingCards:true}),enableMagneticInteractions:()=>s({magneticInteractions:true}),setTheme:d=>s({themeName:d}),enablePerformanceMode:()=>s({reducedMotion:true,enableGlass:false,magneticInteractions:false}),isV3Enabled:true}}function ye(...e){return e.flat().filter(Boolean).join(" ")}var Ca=forwardRef(({item:e,renderItem:a,actions:r=[],onAction:s,onCancel:d,titleEs:l="Revisar Elemento",titleEn:n="Review Item",reasonLabelEs:v="Comentarios",reasonLabelEn:i="Comments",reasonPlaceholderEs:h="Agregar comentarios...",reasonPlaceholderEn:f="Add comments...",cancelButtonEs:p="Cancelar",cancelButtonEn:y="Cancel",confirmButtonEs:N="Confirmar",confirmButtonEn:k="Confirm",loading:M=false,error:u,locale:T="es",className:C,itemClassName:S,actionsClassName:I,...pe},c)=>{let[R,L]=useState(null),[O,_]=useState(""),[le,de]=useState(false),g=useCallback((B,me)=>T==="es"?B:me||B,[T]);r.length>4&&console.warn(`BIRHAUS ApprovalWorkflow: ${r.length} actions exceed 4-3-1 cognitive rule recommendation of 4. Consider consolidating actions or using progressive disclosure.`);let A=R?r.find(B=>B.key===R):null,we=useCallback(B=>{L(B),_("");},[]),ce=useCallback(async()=>{if(!(!R||!A)&&!(A.requiresReason&&!O.trim()))try{de(!0),await s(R,e,O.trim()||void 0);}catch(B){console.error("Approval action failed:",B);}finally{de(false);}},[R,A,O,s,e]),be=useCallback(()=>{L(null),_(""),d?.();},[d]),fe=useCallback(()=>{L(null),_("");},[]),G=g(l,n);return jsxs("div",{ref:c,className:ye("birhaus-approval-workflow space-y-6",C),...pe,children:[jsx("div",{className:"flex items-center justify-between",children:jsx("h2",{className:"text-xl font-semibold text-gray-900",children:G})}),u&&jsx("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertTriangle,{className:"w-5 h-5 text-red-600 mt-0.5 flex-shrink-0"}),jsx("p",{className:"text-sm text-red-800",children:u})]})}),jsx("div",{className:ye("bg-gray-50 border border-gray-200 rounded-lg p-6",S),children:a(e)}),R?jsxs("div",{className:"space-y-4",children:[A&&jsx("div",{className:"p-4 bg-amber-50 border border-amber-200 rounded-lg",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertTriangle,{className:"w-5 h-5 text-amber-600 mt-0.5 flex-shrink-0"}),jsx("div",{className:"flex-1",children:jsx("p",{className:"text-sm font-medium text-amber-900",children:g(A.confirmationMessageEs||`Confirmar: ${A.labelEs}`,A.confirmationMessageEn||`Confirm: ${A.labelEn||A.labelEs}`)})})]})}),jsxs("div",{children:[jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:[g(v,i),A?.requiresReason&&jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),jsx("textarea",{value:O,onChange:B=>_(B.target.value),placeholder:g(h,f),rows:3,className:ye("w-full px-3 py-2 border border-gray-300 rounded-lg","focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent","disabled:opacity-50 disabled:cursor-not-allowed","resize-none"),disabled:le}),A?.requiresReason&&!O.trim()&&jsx("p",{className:"text-xs text-red-600 mt-1",children:T==="es"?"Este campo es requerido":"This field is required"})]}),jsxs("div",{className:"flex gap-3",children:[jsxs("button",{type:"button",onClick:fe,disabled:le,className:ye("inline-flex items-center px-4 py-2 text-sm font-medium","text-gray-700 bg-white border border-gray-300 rounded-lg","hover:bg-gray-50 hover:border-gray-400","focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-1","disabled:opacity-50 disabled:cursor-not-allowed","transition-all duration-200"),children:[jsx(RotateCcw,{className:"w-4 h-4 mr-2"}),T==="es"?"Volver":"Back"]}),jsx("button",{type:"button",onClick:ce,disabled:le||A?.requiresReason&&!O.trim(),className:ye("inline-flex items-center px-4 py-2 text-sm font-medium rounded-lg","focus:outline-none focus:ring-2 focus:ring-offset-1","disabled:opacity-50 disabled:cursor-not-allowed","transition-all duration-200 flex-1 justify-center",A?.variant==="primary"&&["bg-blue-600 text-white","hover:bg-blue-700 focus:ring-blue-500"],A?.variant==="danger"&&["bg-red-600 text-white","hover:bg-red-700 focus:ring-red-500"],(!A?.variant||A?.variant==="secondary")&&["bg-gray-600 text-white","hover:bg-gray-700 focus:ring-gray-500"]),children:le?jsxs(Fragment,{children:[jsx("div",{className:"animate-spin w-4 h-4 border-2 border-current border-t-transparent rounded-full mr-2"}),T==="es"?"Procesando...":"Processing..."]}):jsxs(Fragment,{children:[A?.icon&&jsx(A.icon,{className:"w-4 h-4 mr-2"}),g(N,k)]})})]})]}):jsxs("div",{className:ye("space-y-4",I),children:[jsx("div",{className:"flex flex-wrap gap-3",children:r.map(B=>{let me=B.icon,q=g(B.labelEs,B.labelEn);return jsxs("button",{type:"button",onClick:()=>we(B.key),disabled:M,className:ye("inline-flex items-center px-4 py-2 text-sm font-medium rounded-lg","border transition-all duration-200 flex-1 md:flex-none","focus:outline-none focus:ring-2 focus:ring-offset-1","disabled:opacity-50 disabled:cursor-not-allowed",B.variant==="primary"&&["bg-blue-600 text-white border-blue-600","hover:bg-blue-700 hover:border-blue-700","focus:ring-blue-500"],B.variant==="secondary"&&["bg-white text-gray-700 border-gray-300","hover:bg-gray-50 hover:border-gray-400","focus:ring-gray-500"],B.variant==="danger"&&["bg-red-600 text-white border-red-600","hover:bg-red-700 hover:border-red-700","focus:ring-red-500"]),children:[me&&jsx(me,{className:"w-4 h-4 mr-2"}),q]},B.key)})}),d&&jsx("div",{className:"flex justify-end",children:jsx("button",{type:"button",onClick:be,disabled:M,className:ye("text-sm text-gray-500 hover:text-gray-700","disabled:opacity-50 disabled:cursor-not-allowed"),children:g(p,y)})})]})]})});Ca.displayName="BirhausApprovalWorkflow";function ht(){let[e,a]=useState(null),[r,s]=useState(false),[d,l]=useState(null),n=useCallback(h=>{a(h),l(null);},[]),v=useCallback(()=>{a(null),l(null);},[]),i=useCallback(async(h,f,p,y)=>{if(y)try{s(!0),l(null),await y(h,f,p),v();}catch(N){throw l(N instanceof Error?N.message:"An error occurred"),N}finally{s(false);}},[v]);return {item:e,loading:r,error:d,startApproval:n,clearApproval:v,handleAction:i,setError:l}}var vt={approveReject:[{key:"approve",labelEs:"Aprobar",labelEn:"Approve",variant:"primary",icon:CheckCircle,confirmationMessageEs:"Esta acci\xF3n aprobar\xE1 el elemento.",confirmationMessageEn:"This action will approve the item."},{key:"reject",labelEs:"Rechazar",labelEn:"Reject",variant:"danger",icon:XCircle,requiresReason:true,confirmationMessageEs:"Esta acci\xF3n rechazar\xE1 el elemento.",confirmationMessageEn:"This action will reject the item."}],financialApproval:[{key:"approve",labelEs:"Aprobar Transacci\xF3n",labelEn:"Approve Transaction",variant:"primary",icon:CheckCircle,confirmationMessageEs:"Esta acci\xF3n procesar\xE1 la transacci\xF3n y actualizar\xE1 los registros financieros.",confirmationMessageEn:"This action will process the transaction and update financial records."},{key:"reject",labelEs:"Rechazar Transacci\xF3n",labelEn:"Reject Transaction",variant:"danger",icon:XCircle,requiresReason:true,confirmationMessageEs:"Esta acci\xF3n cancelar\xE1 la transacci\xF3n y notificar\xE1 al solicitante.",confirmationMessageEn:"This action will cancel the transaction and notify the requester."}],documentApproval:[{key:"approve",labelEs:"Aprobar Documento",labelEn:"Approve Document",variant:"primary",icon:CheckCircle,confirmationMessageEs:"Esta acci\xF3n marcar\xE1 el documento como aprobado.",confirmationMessageEn:"This action will mark the document as approved."},{key:"request_changes",labelEs:"Solicitar Cambios",labelEn:"Request Changes",variant:"secondary",requiresReason:true,confirmationMessageEs:"Esta acci\xF3n solicitar\xE1 cambios en el documento.",confirmationMessageEn:"This action will request changes to the document."},{key:"reject",labelEs:"Rechazar Documento",labelEn:"Reject Document",variant:"danger",icon:XCircle,requiresReason:true,confirmationMessageEs:"Esta acci\xF3n rechazar\xE1 permanentemente el documento.",confirmationMessageEn:"This action will permanently reject the document."}]};function ae(...e){return e.flat().filter(Boolean).join(" ")}var Ba={general:Settings,academic:GraduationCap,financial:DollarSign,administrative:Building},Ta={general:"bg-purple-100 text-purple-700 border-purple-200",academic:"bg-blue-100 text-blue-700 border-blue-200",financial:"bg-green-100 text-green-700 border-green-200",administrative:"bg-amber-100 text-amber-700 border-amber-200"},Pa=forwardRef(({user:e,availableRoles:a,onRoleChange:r,onClose:s,onSuccess:d,titleEs:l="Gesti\xF3n de Roles de Usuario",titleEn:n="User Role Management",primaryRoleLabelEs:v="Rol Principal",primaryRoleLabelEn:i="Primary Role",additionalRolesLabelEs:h="Roles Adicionales",additionalRolesLabelEn:f="Additional Roles",assignPrimaryRoleLabelEs:p="Asignar rol principal",assignPrimaryRoleLabelEn:y="Assign primary role",addAdditionalRoleLabelEs:N="Agregar rol adicional",addAdditionalRoleLabelEn:k="Add additional role",changeLabelEs:M="Cambiar",changeLabelEn:u="Change",removeLabelEs:T="Remover",removeLabelEn:C="Remove",showAdvancedLabelEs:S="Mostrar",showAdvancedLabelEn:I="Show",hideAdvancedLabelEs:pe="Ocultar",hideAdvancedLabelEn:c="Hide",cancelLabelEs:R="Cancelar",cancelLabelEn:L="Cancel",saveLabelEs:O="Guardar Cambios",saveLabelEn:_="Save Changes",warningTitleEs:le="Importante sobre los cambios de roles",warningTitleEn:de="Important about role changes",warningMessageEs:g="Los cambios en los roles afectar\xE1n inmediatamente los permisos del usuario. Se recomienda notificar al usuario sobre estos cambios.",warningMessageEn:A="Role changes will immediately affect user permissions. It is recommended to notify the user about these changes.",loading:we=false,error:ce=null,locale:be="es",showAdvancedByDefault:fe=false,maxAdditionalRoles:G=5,allowPrimaryRoleChange:B=true,allowMultipleRoles:me=true,renderUserInfo:q,renderRoleMetadata:he,getRoleIcon:Ie,getRoleColor:X$1,className:Pe,headerClassName:ze,contentClassName:Z,actionsClassName:Ee,...H},qe)=>{let[D,ue]=useState(e.primaryRole||null),[z,je]=useState(e.additionalRoles||[]),[re,_e]=useState(fe),[Ue,ve]=useState(false),[se,De]=useState("primary"),[W,Oe]=useState(false),[J,xe]=useState([]),Y=useCallback((b,ne)=>be==="es"?b:ne||b,[be]),ke=useCallback(b=>Ie?.(b)||Ba[b]||Settings,[Ie]),Fe=useCallback(b=>X$1?.(b)||Ta[b]||"bg-gray-100 text-gray-700 border-gray-200",[X$1]);useEffect(()=>{z.length>G&&console.warn(`BIRHAUS RoleManager: ${z.length} additional roles exceed Miller's Law limit of ${G}. Consider reducing role count or implementing progressive disclosure.`);},[z.length,G]);let Je=useCallback(()=>{let b=[];return B&&b.push(D?"change_primary":"assign_primary"),me&&z.length<G&&b.push("add_additional"),z.length>0&&b.push("manage_additional"),b},[B,me,D,z.length,G]),Ke=useCallback(async b=>{let ne=D;ue(b);let Le={type:"primary_role_assigned",userId:e.id,roleId:b.id,role:b,oldValue:ne,newValue:b,timestamp:new Date().toISOString()};xe(Ce=>[...Ce,Le]),ve(false);},[D,e.id]),Qe=useCallback(async b=>{if(z.some(Ce=>Ce.id===b.id)){ve(false);return}if(z.length>=G){console.warn(`BIRHAUS RoleManager: Cannot add more than ${G} additional roles (Miller's Law compliance)`),ve(false);return}let ne=[...z,b];je(ne);let Le={type:"additional_role_added",userId:e.id,roleId:b.id,role:b,newValue:b,timestamp:new Date().toISOString()};xe(Ce=>[...Ce,Le]),ve(false);},[z,G,e.id]),w=useCallback(b=>{let ne=z.find($e=>$e.id===b);if(!ne)return;let Le=z.filter($e=>$e.id!==b);je(Le);let Ce={type:"additional_role_removed",userId:e.id,roleId:b,role:ne,oldValue:ne,timestamp:new Date().toISOString()};xe($e=>[...$e,Ce]);},[z,e.id]),P=useCallback(async()=>{if(J.length===0){d?.();return}Oe(true);try{for(let b of J)await r(b);xe([]),d?.();}catch(b){console.error("Error processing role changes:",b);}finally{Oe(false);}},[J,r,d]),V=useCallback(()=>{ue(e.primaryRole||null),je(e.additionalRoles||[]),xe([]),_e(fe),s?.();},[e.primaryRole,e.additionalRoles,fe,s]),ie=useCallback(b=>{De(b),ve(true);},[]),Ge=Je();Ge.length>4&&console.warn(`BIRHAUS RoleManager: ${Ge.length} actions exceed 4-3-1 cognitive rule recommendation of 4. Consider consolidating actions or using progressive disclosure.`);let Xe=Y(l,n);return jsxs("div",{ref:qe,className:ae("birhaus-role-manager space-y-6",Pe),...H,children:[jsxs("div",{className:ae("flex items-center justify-between",ze),children:[jsx("h2",{className:"text-xl font-semibold text-gray-900",children:Xe}),s&&jsx("button",{onClick:V,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",disabled:W,children:jsx(X,{className:"w-5 h-5 text-gray-500"})})]}),ce&&jsx("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:jsxs("div",{className:"flex items-start gap-3",children:[jsx(AlertCircle,{className:"w-5 h-5 text-red-600 mt-0.5 flex-shrink-0"}),jsx("p",{className:"text-sm text-red-800",children:ce})]})}),jsxs("div",{className:ae("space-y-6",Z),children:[jsx("div",{className:"bg-gray-50 rounded-lg p-4 border border-gray-200",children:q?q(e):jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"w-12 h-12 rounded-full bg-gradient-to-br from-blue-600 to-blue-700 flex items-center justify-center text-white font-medium",children:e.fullName.split(" ").map(b=>b[0]).join("").slice(0,2).toUpperCase()}),jsxs("div",{children:[jsx("h3",{className:"font-medium text-gray-900",children:e.fullName}),jsx("p",{className:"text-sm text-gray-600",children:e.email})]})]})}),jsxs("div",{children:[jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:Y(v,i)}),jsx("div",{className:"space-y-2",children:D?jsx("div",{className:"bg-white border border-gray-200 rounded-lg p-4",children:jsxs("div",{className:"flex items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:ae("p-2 rounded-lg",Fe(D.module)),children:(()=>{let b=ke(D.module);return jsx(b,{className:"h-4 w-4"})})()}),jsxs("div",{children:[jsx("h4",{className:"font-medium text-gray-900",children:D.name}),D.description&&jsx("p",{className:"text-sm text-gray-500",children:D.description}),he&&D.metadata&&jsx("div",{className:"mt-2",children:he(D,D.metadata)})]})]}),B&&jsx("button",{onClick:()=>ie("primary"),className:"text-blue-600 hover:text-blue-700 text-sm font-medium transition-colors",disabled:W,children:Y(M,u)})]})}):B&&jsx("button",{onClick:()=>ie("primary"),className:"w-full p-4 border-2 border-dashed border-gray-300 rounded-lg hover:border-gray-400 transition-colors",disabled:W,children:jsxs("div",{className:"flex items-center justify-center gap-2 text-gray-600",children:[jsx(Plus,{className:"w-5 h-5"}),jsx("span",{children:Y(p,y)})]})})})]}),me&&jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("label",{className:"text-sm font-medium text-gray-700",children:[Y(h,f),z.length>0&&jsxs("span",{className:"ml-2 text-xs text-gray-500",children:["(",z.length,"/",G,")"]})]}),jsxs("button",{onClick:()=>_e(!re),className:"text-sm text-gray-600 hover:text-gray-900 flex items-center gap-1 transition-colors",children:[re?jsx(ChevronUp,{className:"w-4 h-4"}):jsx(ChevronDown,{className:"w-4 h-4"}),re?Y(pe,c):Y(S,I)]})]}),re&&jsxs("div",{className:"space-y-2",children:[z.map(b=>jsx("div",{className:"bg-white border border-gray-200 rounded-lg p-3",children:jsxs("div",{className:"flex items-center justify-between",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{cla