@libxai/board 0.17.174 → 0.17.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -339,7 +339,7 @@ import {createRoot}from'react-dom/client';import {dragStore,BaseViewAdapter,sele
339
339
  </Calendars>
340
340
  <Tasks>${p}
341
341
  </Tasks>
342
- </Project>`,m=new Blob([n],{type:"application/xml;charset=utf-8;"}),d=document.createElement("a");d.href=URL.createObjectURL(m),d.download=a,d.click(),URL.revokeObjectURL(d.href);},calculateCriticalPath:e=>{let t=ne.flattenTasks(e),a=t.filter(n=>n.startDate&&n.endDate);if(a.length===0)return [];let r=new Map,o=n=>{if(r.has(n.id))return;let m=n.startDate&&n.endDate?ne.calculateDuration(n.startDate,n.endDate):0,d=0;if(n.dependencies&&n.dependencies.length>0)for(let u of n.dependencies){let y=t.find(f=>f.id===u);if(y){o(y);let f=r.get(u)?.ef||0;d=Math.max(d,f);}}let i=d+m;r.set(n.id,{es:d,ef:i});};a.forEach(o);let s=Math.max(...Array.from(r.values()).map(n=>n.ef)),l=new Map,c=n=>{if(l.has(n.id))return;let m=n.startDate&&n.endDate?ne.calculateDuration(n.startDate,n.endDate):0,d=t.filter(y=>y.dependencies&&y.dependencies.includes(n.id)),i=s;if(d.length>0)for(let y of d){c(y);let f=l.get(y.id)?.ls||0;i=Math.min(i,f);}let u=i-m;l.set(n.id,{ls:u,lf:i});};a.forEach(c);let p=[];for(let n of a){let m=r.get(n.id),d=l.get(n.id);if(m&&d){let i=d.ls-m.es;Math.abs(i)<.01&&p.push(n.id);}}return p},calculateSlack:(e,t)=>{let a=ne.findTaskById(e,t);if(!a||!a.startDate||!a.endDate)return null;if(ne.calculateCriticalPath(e).includes(t))return 0;let o=ne.getDependentTasks(e,t);if(o.length===0){let c=ne.getLatestEndDate(e);if(!c)return null;let p=ne.calculateDuration(a.endDate,c);return Math.max(0,p)}let s=o.filter(c=>c.startDate).map(c=>c.startDate.getTime()).sort((c,p)=>c-p)[0];if(!s)return null;let l=ne.calculateDuration(a.endDate,new Date(s));return Math.max(0,l)},isOnCriticalPath:(e,t)=>ne.calculateCriticalPath(e).includes(t),autoScheduleDependents:(e,t,a)=>{let r=ne.findTaskById(e,t);if(!r||!r.endDate)return e;let o=ne.getDependentTasks(e,t);if(o.length===0)return e;let s=[...e];for(let l of o){if(!l.startDate||!l.endDate)continue;let c=ne.calculateDuration(l.startDate,l.endDate),p;a!==void 0?(p=new Date(l.startDate),p.setDate(p.getDate()+a)):(p=new Date(r.endDate),p.setDate(p.getDate()+1));let n=ne.calculateEndDate(p,c),m=d=>d.map(i=>i.id===l.id?{...i,startDate:p,endDate:n}:i.subtasks?{...i,subtasks:m(i.subtasks)}:i);s=m(s),s=ne.autoScheduleDependents(s,l.id,a);}return s},calculateCascadePreview:(e,t,a,r,o,s,l,c)=>{if(a===0)return [];let p=[],n=o.getTime(),m=1e3*60*60*24,d=ne.findTaskById(e,t);if(!d||!d.endDate)return [];let i=(u,y,f=new Set)=>{if(f.has(u))return;f.add(u);let g=ne.getDependentTasks(e,u);for(let x of g){if(!x.startDate||!x.endDate)continue;let b=r.findIndex(k=>k.id===x.id);if(b===-1)continue;let h=x.startDate.getTime(),D=(x.endDate.getTime()-h)/m,M=(h-n)/m*s,v=M+y*s,L=Math.max(D*s,s),T=c+b*l+12;p.push({taskId:x.id,taskName:x.name,originalX:M,previewX:v,width:L,y:T,rowIndex:b,daysDelta:y,color:x.color}),i(x.id,y,f);}};return i(t,a),p},splitTask:(e,t,a,r=3)=>{let o=ne.findTaskById(e,t);if(!o||!o.startDate||!o.endDate)return e;if(a<=o.startDate||a>=o.endDate)return console.warn("Split date must be between task start and end dates"),e;let s=new Date(a);s.setDate(s.getDate()-1);let l=new Date(a);l.setDate(l.getDate()+r);let c=new Date(o.endDate);c.setDate(c.getDate()+r);let p=[{startDate:new Date(o.startDate),endDate:s},{startDate:l,endDate:c}],n=m=>m.map(d=>d.id===o.id?{...d,endDate:c,segments:p}:d.subtasks?{...d,subtasks:n(d.subtasks)}:d);return n(e)}};function ln({tasks:e,theme:t,rowHeight:a,timeScale:r,startDate:o,endDate:s,zoom:l,templates:c,onTaskClick:p,onTaskDblClick:n,onTaskContextMenu:m,onTaskDateChange:d,onDependencyCreate:i,onDependencyDelete:u}){let[f,g]=useState([]),[x,b]=useState(null),[h,w]=useState(null),D=useCallback(O=>{b(O);},[]),N=Math.ceil((s.getTime()-o.getTime())/(1e3*60*60*24)),M=r==="day"?60:r==="week"?20:8,v=N*M*l,L=O=>{let B=new Date(Date.UTC(O.getFullYear(),O.getMonth(),O.getDate())),W=B.getUTCDay()||7;B.setUTCDate(B.getUTCDate()+4-W);let S=new Date(Date.UTC(B.getUTCFullYear(),0,1));return Math.ceil(((B.getTime()-S.getTime())/864e5+1)/7)},T=O=>{let B=O.getDay();return B===0||B===6},k=useCallback(O=>{let B=Math.round(O/(M*l)),W=new Date(o);return W.setDate(W.getDate()+B),W},[o,M,l]),F=useCallback((O,B)=>{if(B.startDate&&B.endDate)return;let W=O.currentTarget.ownerSVGElement;if(!W)return;let S=W.createSVGPoint();S.x=O.clientX,S.y=O.clientY;let q=S.matrixTransform(W.getScreenCTM()?.inverse()),ee=k(q.x),$=new Date(ee);$.setDate($.getDate()+1),d?.(B,ee,$);},[k,d]),P=useMemo(()=>{let O=q=>q.map(ee=>{if(ee.subtasks&&ee.subtasks.length>0){let $=O(ee.subtasks),Me=$.filter(be=>be.startDate&&be.endDate);if(Me.length>0){let be=Me.map(Te=>Te.startDate.getTime()),qe=Me.map(Te=>Te.endDate.getTime()),ue=new Date(Math.min(...be)),Qe=new Date(Math.max(...qe));return {...ee,subtasks:$,startDate:ue,endDate:Qe}}return {...ee,subtasks:$}}return ee}),B=(q,ee=[])=>{for(let $ of q)ee.push($),$.subtasks&&$.subtasks.length>0&&($.isExpanded===void 0||$.isExpanded)&&B($.subtasks,ee);return ee},W=O(e);return B(W)},[e]),H=useCallback(O=>{if(!O.startDate||!O.endDate)return {x:0,width:0};let B=O.startDate.getTime(),W=O.endDate.getTime(),S=o.getTime(),q=(B-S)/(1e3*60*60*24),ee=(W-B)/(1e3*60*60*24),$=q*M*l,Me=Math.max(M*l,40),be=Math.max(ee*M*l,Me);return {x:$,width:be}},[o,M,l]),X=useMemo(()=>P.filter(O=>O.startDate&&O.endDate).map(O=>{let{x:B,width:W}=H(O),q=P.findIndex(ee=>ee.id===O.id)*a+12;return {id:O.id,x:B,y:q,width:W,height:32}}),[P,H]),ye=useCallback((O,B,W)=>{if(!W||B===0){g([]);return}let S=ne.calculateCascadePreview(e,O,B,P,o,M*l,a,48);g(S);},[e,P,o,M,l,a,48]),we=useMemo(()=>{let O=[],B=new Date(o);for(;B<=s;){let q=(B.getTime()-o.getTime())/864e5*M*l;if(r==="day")O.push({date:new Date(B),label:B.toLocaleDateString("en-US",{day:"numeric",month:"short"}),x:q}),B.setDate(B.getDate()+1);else if(r==="week"){let ee=L(B);O.push({date:new Date(B),label:`Week ${ee}`,x:q}),B.setDate(B.getDate()+7);}else O.push({date:new Date(B),label:B.toLocaleDateString("en-US",{month:"short",year:"numeric"}),x:q}),B.setMonth(B.getMonth()+1);}return O},[o,s,r,M,l]),Ie=useMemo(()=>(new Date().getTime()-o.getTime())/(1e3*60*60*24)*M*l,[o,M,l]),Le=Math.max(P.length*a,552);return jsxs("div",{className:"w-full h-full flex flex-col","data-gantt-chart":true,style:{backgroundColor:t.bgPrimary,overflow:"visible"},children:[jsx("div",{style:{position:"sticky",top:0,zIndex:10,backgroundColor:t.bgGrid,flexShrink:0,height:"48px",borderBottom:`1px solid ${t.border}`,boxSizing:"border-box"},children:jsxs("svg",{width:Math.max(v,1e3),height:47,style:{display:"block"},children:[jsx("rect",{x:0,y:0,width:Math.max(v,1e3),height:48,fill:t.bgGrid}),we.map((O,B)=>jsxs("g",{children:[B>0&&jsx("line",{x1:O.x,y1:0,x2:O.x,y2:48,stroke:t.border,strokeWidth:1,opacity:.1}),jsx("text",{x:O.x+8,y:48/2,fill:t.textTertiary,fontSize:"11",fontFamily:"'JetBrains Mono', ui-monospace, monospace",fontWeight:"500",dominantBaseline:"middle",children:O.label})]},`header-${B}`)),Ie>=0&&Ie<=v&&jsx("circle",{cx:Ie,cy:38,r:6,fill:t.today,opacity:1})]})}),jsxs("svg",{width:Math.max(v,1e3),height:Le,style:{display:"block",flexShrink:0,overflow:"visible"},children:[jsxs("defs",{children:[jsx("filter",{id:"shadow",children:jsx("feDropShadow",{dx:"0",dy:"1",stdDeviation:"2",floodOpacity:"0.1"})}),jsx("pattern",{id:"diagonal-stripes",width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)",children:jsx("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:t.border,strokeWidth:"2"})})]}),jsx("rect",{x:0,y:0,width:Math.max(v,1e3),height:Le,fill:t.bgPrimary}),we.map((O,B)=>{let W=we[B+1]?.x||v,S=T(O.date);return jsxs("g",{children:[S&&jsx("rect",{x:O.x,y:0,width:W-O.x,height:P.length*a,fill:t.bgWeekend,opacity:1}),B>0&&jsx("line",{x1:O.x,y1:0,x2:O.x,y2:P.length*a,stroke:t.border,strokeWidth:1,opacity:.1})]},B)}),Ie>=0&&Ie<=v&&jsx("line",{x1:Ie,y1:0,x2:Ie,y2:P.length*a,stroke:t.today,strokeWidth:2,opacity:1}),P.map((O,B)=>{let W=O.startDate&&O.endDate;return jsxs("g",{children:[jsx("rect",{x:0,y:B*a,width:v,height:a,fill:B%2===0?"transparent":t.bgSecondary,opacity:1,style:{pointerEvents:"none"}},`row-${O.id}`),!W&&jsxs(Fragment,{children:[jsx("rect",{x:0,y:B*a,width:v,height:a,fill:"transparent",style:{cursor:"pointer",pointerEvents:"all"},onClick:S=>F(S,O),onMouseEnter:S=>{S.currentTarget.setAttribute("fill",t.accentLight),S.currentTarget.setAttribute("opacity","0.5");},onMouseLeave:S=>{S.currentTarget.setAttribute("fill","transparent"),S.currentTarget.setAttribute("opacity","1");}},`clickable-${O.id}`),jsx("text",{x:Ie>0?Ie:100,y:B*a+a/2,fill:t.textTertiary,fontSize:"12",fontFamily:"Inter, sans-serif",fontStyle:"italic",dominantBaseline:"middle",opacity:.4,style:{pointerEvents:"none",userSelect:"none"},children:"Click to set dates..."},`placeholder-${O.id}`)]})]},`row-group-${O.id}`)}),P.map((O,B)=>!O.dependencies||O.dependencies.length===0||!O.startDate||!O.endDate?null:O.dependencies.map(W=>{let S=P.find(Me=>Me.id===W);if(!S||!S.startDate||!S.endDate)return null;let q=P.findIndex(Me=>Me.id===W),ee=H(S),$=H(O);return jsx(rn,{x1:ee.x+ee.width,y1:q*a+a/2,x2:$.x,y2:B*a+a/2,theme:t},`dep-${W}-${O.id}`)})),P.map((O,B)=>{if(!O.startDate||!O.endDate)return null;let{x:W,width:S}=H(O),q=B*a+12,ee=O.subtasks&&O.subtasks.length>0&&!O.isMilestone;return O.isMilestone?jsx(nn,{task:O,x:W+S/2,y:q+16,theme:t,onClick:p},O.id):ee?jsxs("g",{onClick:()=>p?.(O),onContextMenu:$=>{$.preventDefault(),$.stopPropagation(),m?.(O,$);},style:{cursor:"default"},children:[jsx("rect",{x:W,y:q,width:S,height:32,fill:t.primary,opacity:.25,rx:6}),jsx("line",{x1:W,y1:q,x2:W+S,y2:q,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),jsx("line",{x1:W,y1:q,x2:W,y2:q+32,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),jsx("line",{x1:W+S,y1:q,x2:W+S,y2:q+32,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),jsx("line",{x1:W,y1:q+32,x2:W+S,y2:q+32,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),S>60&&jsx("text",{x:W+12,y:q+16,dominantBaseline:"middle",fill:"#FFFFFF",fontSize:"13",fontWeight:"500",fontFamily:"Inter, sans-serif",style:{pointerEvents:"none",userSelect:"none"},children:O.name})]},O.id):jsx(en,{task:O,x:W,y:q,width:S,theme:t,dayWidth:M*l,startDate:o,templates:c,onClick:p,onDoubleClick:n,onContextMenu:m,onDateChange:d,onDependencyCreate:i,allTaskPositions:X,onDragMove:ye,onHoverChange:D},O.id)}),P.map((O,B)=>!O.dependencies||O.dependencies.length===0||!O.startDate||!O.endDate?null:O.dependencies.map(W=>{let S=P.find(ve=>ve.id===W);if(!S||!S.startDate||!S.endDate)return null;let q=P.findIndex(ve=>ve.id===W),ee=H(S),$=H(O),Me=ee.x+ee.width,be=q*a+a/2,qe=$.x,ue=B*a+a/2,Qe=qe-Me,Te=Me+Qe/2,rt=ve=>{let De=1-ve,Ee=De*De,Ve=Ee*De,Ct=ve*ve,Y=Ct*ve,z=Ve*Me+3*Ee*ve*Te+3*De*Ct*Te+Y*qe,ke=Ve*be+3*Ee*ve*be+3*De*Ct*ue+Y*ue;return {x:z,y:ke}},gt=20,ft=[];for(let ve=0;ve<=gt;ve++){let De=.1+ve/gt*.8;ft.push(rt(De));}let et=ft[0],R=`M ${et.x} ${et.y} `+ft.slice(1).map(ve=>`L ${ve.x} ${ve.y}`).join(" ");return h&&h.x1===Me&&h.y1===be&&h.x2===qe&&h.y2===ue?null:jsx("path",{d:R,fill:"none",stroke:"transparent",strokeWidth:12,strokeLinecap:"round",style:{cursor:"pointer"},onMouseEnter:()=>{w({x1:Me,y1:be,x2:qe,y2:ue,onDelete:()=>u?.(O.id,W)});}},`dep-hover-${W}-${O.id}`)})),f.map(O=>jsxs("g",{style:{pointerEvents:"none"},children:[jsx("rect",{x:O.previewX,y:O.y-48,width:O.width,height:32,rx:8,fill:O.color||t.accent,opacity:.3,stroke:t.accent,strokeWidth:2,strokeDasharray:"4 2"}),Math.abs(O.daysDelta)>0&&jsx("text",{x:O.previewX+O.width/2,y:O.y-48+16,textAnchor:"middle",dominantBaseline:"middle",fill:t.accent,fontSize:"10",fontWeight:"600",fontFamily:"Inter, sans-serif",style:{userSelect:"none"},children:O.daysDelta>0?`+${O.daysDelta}d`:`${O.daysDelta}d`})]},`cascade-preview-${O.taskId}`)),h&&(()=>{let{x1:O,y1:B,x2:W,y2:S,onDelete:q}=h,ee=W-O,$=S-B,Me=O+ee/2,be=(B+S)/2,qe=`M ${O} ${B} C ${Me} ${B}, ${Me} ${S}, ${W} ${S}`,ue=6,Qe=Math.atan2($,ee),Te=W-ue*Math.cos(Qe-Math.PI/6),rt=S-ue*Math.sin(Qe-Math.PI/6),gt=W-ue*Math.cos(Qe+Math.PI/6),ft=S-ue*Math.sin(Qe+Math.PI/6),et=t.dependency,R="#f87171";return jsxs("g",{onMouseLeave:()=>w(null),children:[jsx("path",{d:qe,fill:"none",stroke:"transparent",strokeWidth:50,strokeLinecap:"round",style:{cursor:"pointer"}}),jsx("circle",{cx:Me,cy:be,r:25,fill:"transparent",style:{cursor:"pointer"}}),jsx("path",{d:qe,fill:"none",stroke:et,strokeWidth:8,strokeLinecap:"round",opacity:.15,style:{pointerEvents:"none",filter:"blur(4px)"}}),jsx("path",{d:qe,fill:"none",stroke:et,strokeWidth:2.5,strokeLinecap:"round",opacity:.9,style:{pointerEvents:"none"}}),jsx("path",{d:`M ${W} ${S} L ${Te} ${rt} M ${W} ${S} L ${gt} ${ft}`,fill:"none",stroke:et,strokeWidth:2.5,strokeLinecap:"round",opacity:.9,style:{pointerEvents:"none"}}),jsx("circle",{cx:W,cy:S,r:4,fill:et,opacity:.9,style:{pointerEvents:"none"}}),jsxs(motion.g,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{duration:.15,ease:"easeOut"},onClick:ve=>{ve.stopPropagation(),w(null),q();},style:{cursor:"pointer"},children:[jsx("circle",{cx:Me,cy:be,r:9,fill:"rgba(248, 113, 113, 0.15)",stroke:R,strokeWidth:1.5,style:{transition:"all 0.15s ease"}}),jsx("line",{x1:Me-3,y1:be-3,x2:Me+3,y2:be+3,stroke:R,strokeWidth:1.5,strokeLinecap:"round"}),jsx("line",{x1:Me+3,y1:be-3,x2:Me-3,y2:be+3,stroke:R,strokeWidth:1.5,strokeLinecap:"round"})]})]})})(),x&&jsx(wd,{tooltipData:x,theme:t})]})]})}var dn=[{name:"Azul",value:"#6366F1",light:"#818CF8"},{name:"P\xFArpura",value:"#A855F7",light:"#C084FC"},{name:"Rosa",value:"#EC4899",light:"#F472B6"},{name:"Rojo",value:"#EF4444",light:"#F87171"},{name:"Naranja",value:"#F59E0B",light:"#FBBF24"},{name:"Amarillo",value:"#EAB308",light:"#FACC15"},{name:"Lima",value:"#84CC16",light:"#A3E635"},{name:"Verde",value:"#10B981",light:"#34D399"},{name:"Esmeralda",value:"#059669",light:"#10B981"},{name:"Cyan",value:"#06B6D4",light:"#22D3EE"},{name:"Azul Cielo",value:"#0EA5E9",light:"#38BDF8"},{name:"\xCDndigo",value:"#4F46E5",light:"#6366F1"},{name:"Violeta",value:"#8B5CF6",light:"#A78BFA"},{name:"Fucsia",value:"#D946EF",light:"#E879F9"},{name:"Coral",value:"#F97316",light:"#FB923C"},{name:"Magenta",value:"#E11D48",light:"#FB7185"}];var Ws=[{id:"todo",title:"Por Hacer",color:"#6B7280"},{id:"in-progress",title:"En Progreso",color:"#F59E0B"},{id:"completed",title:"Completada",color:"#10B981"}],Hs=[{id:"low",label:"Baja",color:"#10B981",icon:"\u{1F7E2}"},{id:"medium",label:"Media",color:"#F59E0B",icon:"\u{1F7E1}"},{id:"high",label:"Alta",color:"#F97316",icon:"\u{1F7E0}"},{id:"urgent",label:"Urgente",color:"#EF4444",icon:"\u{1F534}"}];function cn({isOpen:e,onClose:t,task:a,availableTasks:r=[],availableUsers:o=[],onSubmit:s,isLoading:l=false,mode:c=a?"edit":"create",theme:p="dark",customStatuses:n=[],availableTags:m=[],onCreateTag:d,attachments:i=[],onUploadAttachments:u,onDeleteAttachment:y}){let f=[...Ws,...n.filter(R=>!Ws.some(se=>se.id===R.id))],g=Ge[p]||Ge.dark,[x,b]=useState(false),[h,w]=useState(false),[D,N]=useState(false),[M,v]=useState(false),[L,T]=useState({top:0,left:0}),[k,F]=useState(null),[P,H]=useState(new Date),[X$1,ye]=useState({top:0,left:0}),[we,Ie]=useState(false),[Le,O]=useState([]),B=useRef(null),W=useRef(null),S=useRef(null),q=useRef(null),ee=useRef(null),[$,Me]=useState({name:"",description:"",progress:0,status:"todo",priority:"medium",isMilestone:false,color:"#6366F1",assignees:[],dependencies:[],tags:[]}),[be,qe]=useState({});useEffect(()=>{a?(Me({name:a.name,description:a.description||"",startDate:a.startDate,endDate:a.endDate,progress:a.progress,status:a.status||"todo",priority:a.priority||"medium",isMilestone:a.isMilestone||false,color:a.color||"#6366F1",assignees:a.assignees||[],dependencies:a.dependencies||[],tags:a.tags||[]}),(a.dependencies&&a.dependencies.length>0||a.isMilestone)&&Ie(true)):(Me({name:"",description:"",progress:0,status:"todo",priority:"medium",isMilestone:false,color:"#6366F1",assignees:[],dependencies:[],pendingFiles:[],tags:[]}),Ie(false),O([]));},[a,e]),useEffect(()=>{let R=se=>{B.current&&!B.current.contains(se.target)&&b(false),W.current&&!W.current.contains(se.target)&&w(false),S.current&&!S.current.contains(se.target)&&N(false),q.current&&!q.current.contains(se.target)&&v(false);};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);let ue=()=>{let R={};return $.name.trim()||(R.name="El nombre es requerido"),$.startDate&&$.endDate&&$.startDate>$.endDate&&(R.endDate="La fecha de fin debe ser posterior a la de inicio"),qe(R),Object.keys(R).length===0},Qe=async R=>{if(R.preventDefault(),!!ue())try{let se=c==="create"&&Le.length>0?{...$,pendingFiles:Le}:$;await s(se),O([]),t();}catch(se){console.error("Error submitting task:",se);}},Te=(R,se)=>{Me(ve=>{let De={...ve,[R]:se};if(R==="status"){let Ee=se;Ee==="todo"?De.progress=0:Ee==="in-progress"?(ve.progress===0||ve.progress===100)&&(De.progress=50):Ee==="completed"||Ee==="closed"?De.progress=100:(Ee==="in-review"||Ee==="review")&&(De.progress=75);}if(R==="progress"){let Ee=typeof se=="number"?se:parseInt(se,10);Ee===100&&ve.status!=="completed"?De.status="completed":Ee>0&&Ee<100&&ve.status==="todo"?De.status="in-progress":Ee===0&&ve.status!=="todo"&&(De.status="todo");}return De}),be[R]&&qe(ve=>{let De={...ve};return delete De[R],De});},rt=f.find(R=>R.id===$.status)??Ws[0],gt=Hs.find(R=>R.id===$.priority)??Hs[1],ft=dn.find(R=>R.value===$.color)??dn[0],et={backgroundColor:g.bgSecondary,border:`1px solid ${g.borderLight}`,color:g.textPrimary};return jsx(AnimatePresence,{children:e&&jsxs(Fragment,{children:[jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 z-50",onClick:t}),jsx(motion.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.15,ease:[.4,0,.2,1]},className:"fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none",children:jsxs("div",{className:"w-full max-w-xl rounded-xl shadow-2xl pointer-events-auto overflow-hidden",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},onClick:R=>R.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between px-5 py-3",style:{borderBottom:`1px solid ${g.border}`},children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:rt.color||g.accent}}),jsx("span",{className:"text-sm font-medium",style:{color:g.textSecondary},children:c==="create"?"Nueva tarea":"Editar tarea"})]}),jsx("button",{onClick:t,className:"p-1.5 rounded-lg transition-colors",style:{color:g.textTertiary},onMouseEnter:R=>{R.currentTarget.style.backgroundColor=g.hoverBg,R.currentTarget.style.color=g.textPrimary;},onMouseLeave:R=>{R.currentTarget.style.backgroundColor="transparent",R.currentTarget.style.color=g.textTertiary;},disabled:l,children:jsx(X,{className:"w-4 h-4"})})]}),jsxs("form",{onSubmit:Qe,className:"max-h-[calc(100vh-200px)] overflow-y-auto",children:[jsxs("div",{className:"p-5 space-y-4",children:[jsxs("div",{children:[jsx("input",{type:"text",value:$.name,onChange:R=>Te("name",R.target.value),className:"w-full text-lg font-medium bg-transparent border-none focus:outline-none focus:ring-0 placeholder:opacity-50",style:{color:g.textPrimary},placeholder:"Nombre de la tarea",disabled:l,autoFocus:true}),be.name&&jsxs("p",{className:"mt-1 text-xs text-red-400 flex items-center gap-1",children:[jsx(AlertCircle,{className:"w-3 h-3"}),be.name]})]}),jsx("div",{children:jsx("textarea",{value:$.description||"",onChange:R=>Te("description",R.target.value),className:"w-full text-sm bg-transparent border-none focus:outline-none focus:ring-0 resize-none placeholder:opacity-40",style:{color:g.textSecondary},placeholder:"Agregar descripci\xF3n...",rows:2,disabled:l})}),jsx("div",{style:{borderTop:`1px solid ${g.borderLight}`}}),jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[jsxs("div",{ref:B,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>!l&&b(!x),className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:{...et,borderColor:rt.color,backgroundColor:`${rt.color}15`},disabled:l,children:[jsx(CircleDot,{className:"w-3.5 h-3.5",style:{color:rt.color}}),jsx("span",{style:{color:rt.color},children:rt.title}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:rt.color}})]}),jsx(AnimatePresence,{children:x&&jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:"absolute left-0 top-full mt-1 z-50 min-w-[140px] rounded-lg shadow-xl overflow-hidden",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},children:f.map(R=>jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors",style:{color:g.textPrimary},onMouseEnter:se=>se.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:se=>se.currentTarget.style.backgroundColor="transparent",onClick:()=>{Te("status",R.id),b(false);},children:[jsx(CircleDot,{className:"w-3.5 h-3.5",style:{color:R.color}}),R.title,$.status===R.id&&jsx(Check,{className:"w-3.5 h-3.5 ml-auto",style:{color:g.accent}})]},R.id))})})]}),jsxs("div",{ref:W,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>!l&&w(!h),className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:et,disabled:l,children:[jsx(Flag,{className:"w-3.5 h-3.5",style:{color:gt.color}}),jsx("span",{children:gt.label}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:g.textTertiary}})]}),jsx(AnimatePresence,{children:h&&jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:"absolute left-0 top-full mt-1 z-50 min-w-[130px] rounded-lg shadow-xl overflow-hidden",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},children:Hs.map(R=>jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors",style:{color:g.textPrimary},onMouseEnter:se=>se.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:se=>se.currentTarget.style.backgroundColor="transparent",onClick:()=>{Te("priority",R.id),w(false);},children:[jsx("span",{children:R.icon}),R.label,$.priority===R.id&&jsx(Check,{className:"w-3.5 h-3.5 ml-auto",style:{color:g.accent}})]},R.id))})})]}),o.length>0&&jsxs("div",{ref:S,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>!l&&N(!D),className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:et,disabled:l,children:[$.assignees&&$.assignees.length>0?jsxs(Fragment,{children:[jsx("div",{className:"flex -space-x-1",children:$.assignees.slice(0,3).map((R,se)=>jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] text-white font-medium border-2",style:{backgroundColor:R.color||g.accent,borderColor:g.bgSecondary},children:R.initials},se))}),$.assignees.length>3&&jsxs("span",{style:{color:g.textTertiary},children:["+",$.assignees.length-3]})]}):jsxs(Fragment,{children:[jsx(Users,{className:"w-3.5 h-3.5",style:{color:g.textTertiary}}),jsx("span",{style:{color:g.textTertiary},children:"Asignar"})]}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:g.textTertiary}})]}),jsx(AnimatePresence,{children:D&&jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:"absolute left-0 top-full mt-1 z-50 min-w-[180px] max-h-[200px] overflow-y-auto rounded-lg shadow-xl",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},children:o.map(R=>{let se=$.assignees?.some(ve=>ve.name===R.name);return jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors",style:{color:g.textPrimary},onMouseEnter:ve=>ve.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:ve=>ve.currentTarget.style.backgroundColor="transparent",onClick:()=>{let ve=se?($.assignees||[]).filter(De=>De.name!==R.name):[...$.assignees||[],{name:R.name,avatar:R.avatar,initials:R.name.split(" ").map(De=>De[0]).join("").toUpperCase().slice(0,2),color:g.accent}];Te("assignees",ve);},children:[jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs text-white font-medium flex-shrink-0",style:{backgroundColor:g.accent},children:R.name.charAt(0).toUpperCase()}),jsx("span",{className:"truncate flex-1 text-left",children:R.name}),jsx("div",{className:"w-4 flex-shrink-0 flex justify-end",children:se&&jsx(Check,{className:"w-3.5 h-3.5",style:{color:g.accent}})})]},R.id)})})})]}),jsxs("div",{ref:q,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>{if(!l)if(M)v(false);else {if(q.current){let R=q.current.getBoundingClientRect(),se=window.innerHeight,ve=120,Ee=se-R.bottom<ve?R.top-ve-8:R.bottom+8;T({top:Ee,left:R.left});}v(true);}},className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:et,disabled:l,children:[jsx("div",{className:"w-3.5 h-3.5 rounded-full",style:{backgroundColor:$.color}}),jsx("span",{children:ft.name}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:g.textTertiary}})]}),jsx(AnimatePresence,{children:M&&jsxs(tt,{children:[jsx("div",{className:"fixed inset-0",style:{zIndex:99998},onClick:()=>v(false)}),jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},transition:{duration:.12},className:"rounded-lg",style:{position:"fixed",top:`${L.top}px`,left:`${L.left}px`,zIndex:99999,backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`,boxShadow:"0 4px 20px rgba(0, 0, 0, 0.25)"},onClick:R=>R.stopPropagation(),children:jsx("div",{style:{padding:"14px 18px"},children:jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(6, 16px)",gap:"14px"},children:dn.slice(0,18).map(R=>{let se=$.color===R.value;return jsx(motion.button,{type:"button",onClick:()=>{Te("color",R.value),v(false);},style:{width:"16px",height:"16px",borderRadius:"50%",backgroundColor:R.value,outline:se?`2px solid ${R.value}`:"none",outlineOffset:"3px",cursor:"pointer",border:"none"},whileHover:{scale:1.2},whileTap:{scale:.95},title:R.name},R.value)})})})})]})})]}),m.length>0||d?jsx(Rr,{selectedTags:$.tags||[],availableTags:m,onChange:R=>Te("tags",R),onCreateTag:d,theme:g,disabled:l}):null]}),jsxs("div",{className:"flex items-center gap-3",children:[jsx(Calendar,{className:"w-4 h-4",style:{color:g.textTertiary}}),jsxs("div",{ref:ee,className:"flex items-center gap-2 flex-1 relative",children:[jsx("button",{type:"button",onClick:()=>{if(!l&&!$.isMilestone)if(k==="start")F(null);else {if(ee.current){let R=ee.current.getBoundingClientRect(),se=window.innerHeight,ve=320,Ee=se-R.bottom<ve?R.top-ve-8:R.bottom+8;ye({top:Ee,left:R.left});}F("start"),H($.startDate||new Date);}},className:"px-3 py-1.5 rounded-lg text-sm transition-colors",style:{...et,opacity:$.isMilestone?.5:1,cursor:$.isMilestone?"not-allowed":"pointer"},disabled:l||$.isMilestone,children:$.startDate?$.startDate.toLocaleDateString("es-ES",{day:"numeric",month:"short"}):"Inicio"}),jsx("span",{style:{color:g.textTertiary},children:"\u2192"}),jsx("button",{type:"button",onClick:()=>{if(!l&&!$.isMilestone)if(k==="end")F(null);else {if(ee.current){let R=ee.current.getBoundingClientRect(),se=window.innerHeight,ve=320,Ee=se-R.bottom<ve?R.top-ve-8:R.bottom+8;ye({top:Ee,left:R.left});}F("end"),H($.endDate||$.startDate||new Date);}},className:"px-3 py-1.5 rounded-lg text-sm transition-colors",style:{...et,opacity:$.isMilestone?.5:1,cursor:$.isMilestone?"not-allowed":"pointer"},disabled:l||$.isMilestone,children:$.endDate?$.endDate.toLocaleDateString("es-ES",{day:"numeric",month:"short"}):"Fin"}),jsx(AnimatePresence,{children:k&&jsxs(tt,{children:[jsx("div",{className:"fixed inset-0",style:{zIndex:99998},onClick:()=>F(null)}),jsxs(motion.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"rounded-xl shadow-2xl overflow-hidden flex",style:{position:"fixed",top:`${X$1.top}px`,left:`${X$1.left}px`,zIndex:99999,backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},onClick:R=>R.stopPropagation(),children:[jsxs("div",{className:"w-40 py-2",style:{borderRight:`1px solid ${g.border}`},children:[(()=>{let R=new Date,se=new Date(R);se.setDate(R.getDate()+1);let ve=new Date(R);ve.setDate(R.getDate()+7);let De=new Date(R);return De.setDate(R.getDate()+14),[{label:"Hoy",date:R},{label:"Ma\xF1ana",date:se},{label:"Pr\xF3xima semana",date:ve},{label:"2 semanas",date:De}].map((Ve,Ct)=>jsx("button",{type:"button",className:"w-full px-3 py-2 text-sm text-left transition-colors",style:{color:g.textPrimary},onMouseEnter:Y=>Y.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:Y=>Y.currentTarget.style.backgroundColor="transparent",onClick:()=>{k==="start"?(Te("startDate",Ve.date),(!$.endDate||Ve.date>$.endDate)&&Te("endDate",Ve.date),F("end")):(Te("endDate",Ve.date),(!$.startDate||Ve.date<$.startDate)&&Te("startDate",Ve.date),F(null));},children:Ve.label},Ct))})(),jsx("div",{style:{borderTop:`1px solid ${g.border}`,margin:"0.5rem 0"}}),jsx("button",{type:"button",className:"w-full px-3 py-2 text-sm text-left transition-colors",style:{color:"#EF4444"},onMouseEnter:R=>R.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:R=>R.currentTarget.style.backgroundColor="transparent",onClick:()=>{Te("startDate",void 0),Te("endDate",void 0),F(null);},children:"Borrar fechas"})]}),jsxs("div",{className:"p-3",children:[jsxs("div",{className:"flex items-center justify-between mb-3",children:[jsx("button",{type:"button",onClick:()=>H(new Date(P.getFullYear(),P.getMonth()-1)),className:"p-1 rounded hover:bg-white/10",children:jsx(ChevronLeft,{className:"w-4 h-4",style:{color:g.textSecondary}})}),jsx("span",{className:"text-sm font-medium",style:{color:g.textPrimary},children:P.toLocaleDateString("es-ES",{month:"long",year:"numeric"})}),jsx("button",{type:"button",onClick:()=>H(new Date(P.getFullYear(),P.getMonth()+1)),className:"p-1 rounded hover:bg-white/10",children:jsx(ChevronRight,{className:"w-4 h-4",style:{color:g.textSecondary}})})]}),jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:["D","L","M","M","J","V","S"].map((R,se)=>jsx("div",{className:"w-7 h-7 flex items-center justify-center text-xs",style:{color:g.textTertiary},children:R},se))}),jsx("div",{className:"grid grid-cols-7 gap-1",children:(()=>{let R=P.getFullYear(),se=P.getMonth(),ve=new Date(R,se,1).getDay(),De=new Date(R,se+1,0).getDate(),Ee=new Date,Ve=[];for(let Y=ve-1;Y>=0;Y--)Ve.push({day:new Date(R,se,-Y).getDate(),date:new Date(R,se-1,new Date(R,se,-Y).getDate()),isCurrentMonth:false});for(let Y=1;Y<=De;Y++)Ve.push({day:Y,date:new Date(R,se,Y),isCurrentMonth:true});let Ct=42-Ve.length;for(let Y=1;Y<=Ct;Y++)Ve.push({day:Y,date:new Date(R,se+1,Y),isCurrentMonth:false});return Ve.map((Y,z)=>{let ke=Y.date.toDateString()===Ee.toDateString(),We=$.startDate?.toDateString()===Y.date.toDateString(),Ue=$.endDate?.toDateString()===Y.date.toDateString(),ht=$.startDate&&$.endDate&&Y.date>=$.startDate&&Y.date<=$.endDate;return jsx("button",{type:"button",className:"w-7 h-7 rounded-full flex items-center justify-center text-xs transition-colors",style:{color:Y.isCurrentMonth?We||Ue?"#FFF":g.textPrimary:g.textTertiary,backgroundColor:We?"#3B82F6":Ue?"#7C3AED":ht?"rgba(124, 58, 237, 0.2)":"transparent",boxShadow:ke&&!We&&!Ue?"inset 0 0 0 1px #3B82F6":"none"},onClick:()=>{k==="start"?(Te("startDate",Y.date),$.endDate&&Y.date>$.endDate&&Te("endDate",Y.date),F("end")):(Te("endDate",Y.date),$.startDate&&Y.date<$.startDate&&Te("startDate",Y.date),F(null));},children:Y.day},z)})})()})]})]})]})})]}),be.endDate&&jsx("span",{className:"text-xs text-red-400",children:be.endDate})]}),jsxs("div",{className:"flex items-center gap-3",children:[jsx(Clock,{className:"w-4 h-4",style:{color:g.textTertiary}}),jsxs("div",{className:"flex items-center gap-3 flex-1",children:[jsx("input",{type:"range",min:"0",max:"100",step:"5",value:$.progress,onChange:R=>Te("progress",parseInt(R.target.value)),className:"flex-1 h-1.5 rounded-full appearance-none cursor-pointer",style:{backgroundColor:g.bgSecondary,accentColor:$.progress<30?"#EF4444":$.progress<70?"#F59E0B":"#10B981"},disabled:l}),jsxs("span",{className:"text-xs font-medium px-2 py-0.5 rounded-full min-w-[45px] text-center",style:{backgroundColor:`${$.progress<30?"#EF4444":$.progress<70?"#F59E0B":"#10B981"}20`,color:$.progress<30?"#EF4444":$.progress<70?"#F59E0B":"#10B981"},children:[$.progress,"%"]})]})]}),(u||i.length>0||c==="create")&&jsxs("div",{className:"pt-2",children:[jsxs("div",{className:"flex items-center gap-2 mb-2",children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:g.textTertiary},children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})}),jsxs("span",{className:"text-xs",style:{color:g.textTertiary},children:["Adjuntos ",c==="create"?Le.length>0&&`(${Le.length})`:i.length>0&&`(${i.length})`]})]}),c==="create"?jsx(za,{cardId:"pending",attachments:Le.map((R,se)=>({id:`pending-${se}`,cardId:"pending",name:R.name,size:R.size,type:R.type,url:URL.createObjectURL(R),uploadedAt:new Date().toISOString(),uploadedBy:"current-user"})),onUpload:R=>O(se=>[...se,...R]),onDelete:R=>{let se=parseInt(R.replace("pending-",""),10);O(ve=>ve.filter((De,Ee)=>Ee!==se));},maxSizeMB:10,maxFiles:20}):jsx(za,{cardId:a?.id||"new",attachments:i,onUpload:u&&a?.id?R=>u(a.id,R):void 0,onDelete:y,maxSizeMB:10,maxFiles:20}),c==="create"&&Le.length>0&&jsxs("p",{className:"text-xs mt-1",style:{color:g.textTertiary},children:[Le.length," archivo(s) se subir\xE1n al crear la tarea"]})]}),jsxs("div",{children:[jsxs("button",{type:"button",onClick:()=>Ie(!we),className:"flex items-center gap-2 text-xs w-full py-2 transition-colors",style:{color:g.textTertiary},children:[jsx(ChevronDown,{className:`w-3 h-3 transition-transform ${we?"rotate-180":""}`}),"Opciones avanzadas"]}),jsx(AnimatePresence,{children:we&&jsx(motion.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:jsxs("div",{className:"pt-3 space-y-3",children:[jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-2 rounded-lg transition-colors hover:bg-white/5",children:[jsx("input",{type:"checkbox",checked:$.isMilestone,onChange:R=>Te("isMilestone",R.target.checked),className:"w-4 h-4 rounded",style:{accentColor:g.accent},disabled:l}),jsx(Milestone,{className:"w-4 h-4 text-yellow-500"}),jsx("span",{className:"text-sm",style:{color:g.textPrimary},children:"Marcar como hito"})]}),r.length>0&&jsxs("div",{children:[jsxs("label",{className:"flex items-center gap-2 text-xs mb-2",style:{color:g.textTertiary},children:[jsx(Link2,{className:"w-3.5 h-3.5"}),"Dependencias"]}),jsx("div",{className:"flex flex-wrap gap-1.5 max-h-24 overflow-y-auto p-2 rounded-lg",style:{backgroundColor:g.bgSecondary},children:r.filter(R=>R.id!==a?.id).map(R=>{let se=$.dependencies?.includes(R.id);return jsx("button",{type:"button",onClick:()=>{let ve=se?($.dependencies||[]).filter(De=>De!==R.id):[...$.dependencies||[],R.id];Te("dependencies",ve);},className:"px-2 py-1 rounded-full text-xs transition-colors",style:{backgroundColor:se?`${g.accent}30`:g.bgPrimary,color:se?g.accent:g.textSecondary,border:`1px solid ${se?g.accent:g.borderLight}`},disabled:l,children:R.name},R.id)})})]})]})})})]})]}),jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3",style:{borderTop:`1px solid ${g.border}`},children:[jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm rounded-lg transition-colors",style:{color:g.textSecondary},onMouseEnter:R=>R.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:R=>R.currentTarget.style.backgroundColor="transparent",disabled:l,children:"Cancelar"}),jsx("button",{type:"submit",disabled:l,className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors flex items-center gap-2",style:{backgroundColor:g.accent,color:"#FFF"},onMouseEnter:R=>!l&&(R.currentTarget.style.opacity="0.9"),onMouseLeave:R=>!l&&(R.currentTarget.style.opacity="1"),children:l?jsxs(Fragment,{children:[jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Guardando..."]}):jsx(Fragment,{children:c==="create"?"Crear tarea":"Guardar"})})]})]})]})})]})})}var rf=['Move "Task Name" to next Monday','Extend "Task Name" by 3 days','Rename "Old Name" to "New Name"','Set "Task Name" progress to 50%','Link "Task A" to "Task B"','Create a new task called "New Task"','Delete "Task Name"','Assign John to "Task Name"'],Sd=()=>jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("path",{d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707"}),jsx("circle",{cx:"12",cy:"12",r:"4"})]}),of=()=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"})}),nf=()=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M18 6L6 18M6 6L18 18"})}),sf=()=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M5 12h14"})}),lf=()=>jsx("div",{className:"flex gap-1 items-center",children:[0,1,2].map(e=>jsx(motion.div,{className:"w-2 h-2 rounded-full bg-current",animate:{scale:[1,1.2,1],opacity:[.5,1,.5]},transition:{duration:.8,repeat:1/0,delay:e*.15}},e))});function pn({tasks:e,theme:t,config:a,onTasksUpdate:r,onTaskUpdate:o,onTaskCreate:s,onTaskDelete:l,onDependencyCreate:c,onDependencyDelete:p}){let[n,m]=useState(false),[d,i]=useState(false),[u,y]=useState([]),[f,g]=useState(""),[x,b]=useState(false),[h,w]=useState(true),D=useRef(null),N=useRef(null),M=useRef(null),{enabled:v=true,placeholder:L='Ask AI to edit tasks... (e.g., "Move Design to next week")',position:T="bottom-right",onCommand:k,suggestions:F=rf,maxHistory:P=50,persistHistory:H}=a,X=H?.storageKey||"gantt-ai-history",ye=H?.maxMessages??5;useEffect(()=>{if(H?.enabled)try{let W=localStorage.getItem(X);if(W){let q=JSON.parse(W).map(ee=>({...ee,timestamp:new Date(ee.timestamp)}));y(q.slice(-ye));}}catch(W){console.warn("[GanttAIAssistant] Failed to load persisted history:",W);}},[H?.enabled,X,ye]),useEffect(()=>{if(H?.enabled&&u.length>0)try{let W=u.filter(S=>!S.isLoading).slice(-ye);localStorage.setItem(X,JSON.stringify(W));}catch(W){console.warn("[GanttAIAssistant] Failed to persist history:",W);}},[u,H?.enabled,X,ye]),useEffect(()=>{N.current&&N.current.scrollIntoView({behavior:"smooth"});},[u]),useEffect(()=>{n&&!d&&D.current&&setTimeout(()=>D.current?.focus(),100);},[n,d]);let we=useCallback(W=>{if(W.success)switch(W.type){case "move_task":case "resize_task":case "rename_task":case "set_progress":case "set_status":case "assign_task":W.taskId&&W.updates&&o?.(W.taskId,W.updates);break;case "create_task":W.newTask&&s?.(W.newTask);break;case "delete_task":W.taskId&&l?.(W.taskId);break;case "link_tasks":W.dependencyFrom&&W.dependencyTo&&c?.(W.dependencyFrom,W.dependencyTo);break;case "unlink_tasks":W.taskId&&W.dependencyFrom&&p?.(W.taskId,W.dependencyFrom);break}},[o,s,l,c,p]),Ie=useCallback(async W=>{if(!W.trim()||x)return;let S={id:`user-${Date.now()}`,role:"user",content:W,timestamp:new Date};y(ee=>[...ee.slice(-(P-1)),S]),g(""),w(false),b(true);let q={id:`loading-${Date.now()}`,role:"assistant",content:"",timestamp:new Date,isLoading:true};y(ee=>[...ee,q]);try{if(k){let ee=await k(W,e);y($=>{let Me=$.filter(qe=>!qe.isLoading),be={id:`assistant-${Date.now()}`,role:"assistant",content:ee.message,timestamp:new Date,command:ee};return [...Me,be]}),we(ee);}else y(ee=>[...ee.filter(Me=>!Me.isLoading),{id:`assistant-${Date.now()}`,role:"assistant",content:"AI handler not configured. Please provide an onCommand handler in the aiAssistant config.",timestamp:new Date}]);}catch(ee){y($=>[...$.filter(be=>!be.isLoading),{id:`error-${Date.now()}`,role:"assistant",content:`Sorry, I encountered an error: ${ee instanceof Error?ee.message:"Unknown error"}`,timestamp:new Date}]);}finally{b(false);}},[x,P,k,e,we]),Le=W=>{W.preventDefault(),Ie(f);},O=W=>{g(W),D.current?.focus();};if(useEffect(()=>{let W=S=>{(S.metaKey||S.ctrlKey)&&S.key==="k"&&(S.preventDefault(),m(q=>!q),n||i(false)),S.key==="Escape"&&n&&m(false);};return document.addEventListener("keydown",W),()=>document.removeEventListener("keydown",W)},[n]),useEffect(()=>{if(!n)return;let W=q=>{let ee=q.target;M.current&&!M.current.contains(ee)&&m(false);},S=setTimeout(()=>{document.addEventListener("mousedown",W);},100);return ()=>{clearTimeout(S),document.removeEventListener("mousedown",W);}},[n]),!v)return null;let B={"bottom-right":"bottom-4 right-4","bottom-left":"bottom-4 left-4","top-right":"top-4 right-4","top-left":"top-4 left-4"};return jsxs(tt,{children:[jsx(AnimatePresence,{children:!n&&jsxs(motion.button,{initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},whileHover:{scale:1.05},whileTap:{scale:.95},className:`fixed ${B[T]} z-[99999] flex items-center gap-2 px-4 py-3 rounded-full shadow-lg transition-colors`,style:{background:"linear-gradient(135deg, #3B82F6 0%, #2563EB 100%)",color:"white",boxShadow:"0 4px 20px rgba(59, 130, 246, 0.4)"},onClick:()=>m(true),children:[jsx(Sd,{}),jsx("span",{className:"text-sm font-medium",children:"AI Assistant"}),jsx("kbd",{className:"hidden sm:inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-mono rounded bg-white/20",children:"\u2318K"})]})}),jsx(AnimatePresence,{children:n&&jsxs(motion.div,{ref:M,initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1,height:d?"auto":500},exit:{opacity:0,y:20,scale:.95},transition:{type:"spring",damping:25,stiffness:300},className:`fixed ${B[T]} z-[99999] w-96 rounded-2xl overflow-hidden shadow-2xl flex flex-col`,style:{background:t.bgPrimary,border:`1px solid ${t.border}`,boxShadow:`0 20px 60px rgba(0, 0, 0, 0.3), 0 0 0 1px ${t.border}`},children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:{background:"linear-gradient(135deg, #3B82F6 0%, #2563EB 100%)"},children:[jsxs("div",{className:"flex items-center gap-2 text-white",children:[jsx(Sd,{}),jsx("span",{className:"font-semibold",children:"Gantt AI Assistant"})]}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{onClick:()=>i(W=>!W),className:"p-1.5 rounded-lg hover:bg-white/20 text-white/80 hover:text-white transition-colors",children:jsx(sf,{})}),jsx("button",{onClick:()=>m(false),className:"p-1.5 rounded-lg hover:bg-white/20 text-white/80 hover:text-white transition-colors",children:jsx(nf,{})})]})]}),jsx(AnimatePresence,{children:!d&&jsxs(motion.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"flex flex-col flex-1 min-h-0",children:[jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",style:{maxHeight:350},children:[u.length===0&&h&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-sm text-center",style:{color:t.textSecondary},children:"Try asking me to edit your Gantt chart:"}),jsx("div",{className:"flex flex-wrap gap-2",children:F.slice(0,4).map((W,S)=>jsx("button",{onClick:()=>O(W),className:"text-xs px-3 py-1.5 rounded-full transition-colors",style:{background:t.bgSecondary,color:t.textSecondary,border:`1px solid ${t.border}`},children:W.length>30?W.slice(0,30)+"...":W},S))})]}),u.map(W=>jsx(motion.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex ${W.role==="user"?"justify-end":"justify-start"}`,children:jsxs("div",{className:`max-w-[85%] rounded-2xl px-4 py-2.5 ${W.role==="user"?"rounded-br-md":"rounded-bl-md"}`,style:{background:W.role==="user"?"linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%)":t.bgSecondary,color:W.role==="user"?"white":t.textPrimary},children:[W.isLoading?jsx(lf,{}):jsx("p",{className:"text-sm whitespace-pre-wrap",children:W.content}),W.command&&jsxs("div",{className:"mt-2 text-xs px-2 py-1 rounded-md inline-flex items-center gap-1",style:{background:W.command.success?"rgba(16, 185, 129, 0.2)":"rgba(239, 68, 68, 0.2)",color:W.command.success?"#10B981":"#EF4444"},children:[W.command.success?"\u2713":"\u2717",jsx("span",{className:"capitalize",children:W.command.type.replace(/_/g," ")})]})]})},W.id)),jsx("div",{ref:N})]}),jsxs("form",{onSubmit:Le,className:"p-3 border-t",style:{borderColor:t.border},children:[jsxs("div",{className:"flex items-center gap-2 rounded-xl px-4 py-2",style:{background:t.bgSecondary,border:`1px solid ${t.border}`},children:[jsx("input",{ref:D,type:"text",value:f,onChange:W=>g(W.target.value),placeholder:L,disabled:x,className:"flex-1 bg-transparent text-sm outline-none",style:{color:t.textPrimary}}),jsx("button",{type:"submit",disabled:!f.trim()||x,className:"p-2 rounded-lg transition-all disabled:opacity-50",style:{background:f.trim()?"linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%)":"transparent",color:f.trim()?"white":t.textSecondary},children:jsx(of,{})})]}),jsx("p",{className:"text-[10px] text-center mt-2",style:{color:t.textTertiary},children:"Press Enter to send \u2022 Esc to close"})]})]})})]})})]})}function Ed(e,t=50){let[a,r]=useState({past:[],present:e,future:[]}),o=useRef(false),s=useCallback((n,m=true)=>{r(d=>{let i=typeof n=="function"?n(d.present):n;if(o.current)return {...d,present:i};if(!m)return {...d,present:i};let u=[...d.past,d.present];return u.length>t&&u.shift(),{past:u,present:i,future:[]}});},[t]),l=useCallback(()=>{r(n=>{if(n.past.length===0)return n;let m=n.past[n.past.length-1],d=n.past.slice(0,n.past.length-1);return o.current=true,setTimeout(()=>{o.current=false;},0),{past:d,present:m,future:[n.present,...n.future]}});},[]),c=useCallback(()=>{r(n=>{if(n.future.length===0)return n;let m=n.future[0],d=n.future.slice(1);return o.current=true,setTimeout(()=>{o.current=false;},0),{past:[...n.past,n.present],present:m,future:d}});},[]),p=useCallback(()=>{r(n=>({past:[],present:n.present,future:[]}));},[]);return {state:a.present,setState:s,undo:l,redo:c,canUndo:a.past.length>0,canRedo:a.future.length>0,clearHistory:p}}function Pd({undo:e,redo:t,canUndo:a,canRedo:r,enabled:o=true}){useEffect(()=>{if(!o)return;let s=l=>{let c=navigator.platform.toUpperCase().indexOf("MAC")>=0,p=c?l.metaKey:l.ctrlKey;if(p&&l.key==="z"&&!l.shiftKey&&a){l.preventDefault(),e();return}if(r){if(!c&&p&&l.key==="y"){l.preventDefault(),t();return}if(c&&p&&l.shiftKey&&l.key==="z"){l.preventDefault(),t();return}}};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s);}},[e,t,a,r,o]);}var mf={taskTooltip:e=>{let t=[`<strong>${e.name}</strong>`];if(e.startDate&&e.endDate){t.push(`${ne.formatDate(e.startDate)} - ${ne.formatDate(e.endDate)}`);let a=ne.calculateDuration(e.startDate,e.endDate);t.push(`Duration: ${a} days`);}if(e.progress!==void 0&&t.push(`Progress: ${e.progress}%`),e.status&&t.push(`Status: ${e.status}`),e.assignees&&e.assignees.length>0){let a=e.assignees.map(r=>r.name).join(", ");t.push(`Assigned: ${a}`);}return e.dependencies&&e.dependencies.length>0&&t.push(`Dependencies: ${e.dependencies.length}`),t.join("<br/>")},taskLabel:e=>e.name,gridCell:(e,t,a)=>a,taskClass:e=>{let t=[];return e.isCriticalPath&&t.push("critical-path"),e.status==="completed"?t.push("completed"):e.status==="in-progress"?t.push("in-progress"):e.status==="todo"&&t.push("todo"),e.isMilestone&&t.push("milestone"),t.join(" ")},milestoneContent:e=>`\u25C6 ${e.name}`,dateFormat:e=>ne.formatDate(e),durationFormat:e=>e===1?"1 day":`${e} days`,progressFormat:e=>`${e}%`};function Md(e){return {...mf,...e}}var vf=e=>{switch(e){case "compact":return 44;case "comfortable":return 52;case "spacious":return 60;default:return 52}},Ld=forwardRef(function({tasks:t,config:a={},onTasksChange:r},o){let{theme:s,timeScale:l="week",rowDensity:c="comfortable",showThemeSelector:p=true,showExportButton:n=true,availableUsers:m=[],templates:d,enableAutoCriticalPath:i=true,aiAssistant:u,locale:y="en",customTranslations:f,showCreateTaskButton:g=false,createTaskLabel:x,onCreateTask:b,onThemeChange:h,onTaskClick:w,onTaskDblClick:D,onTaskContextMenu:N,onTaskUpdate:M,onProgressChange:v,onTaskEdit:L,onTaskAddSubtask:T,onTaskMarkIncomplete:k,onTaskSetInProgress:F,onDependencyCreate:P,onDependencyDelete:H,onBeforeTaskAdd:X,onAfterTaskAdd:ye,onBeforeTaskUpdate:we,onAfterTaskUpdate:Ie,onBeforeTaskDelete:Le,onAfterTaskDelete:O}=a,W=useContext(Ko)?.theme,[S,q]=useState(W||s||"dark"),[ee,$]=useState(l),[Me,be]=useState(c),[qe,ue]=useState(1),[Qe,Te]=useState(0),[rt,gt]=useState(false),[ft,et]=useState(null),[R,se]=useState({isOpen:false,x:0,y:0,task:null}),[ve,De]=useState(null),[Ee,Ve]=useState(null);useEffect(()=>{W&&W!==S&&q(W);},[W]),useEffect(()=>{s&&s!==S&&q(s);},[s]);let Ct=useCallback(E=>{q(E),h?.(E);},[h]),{state:Y,setState:z,undo:ke,redo:We,canUndo:Ue,canRedo:ht,clearHistory:Z}=Ed(t,50),te=useRef(new Map);useEffect(()=>{let E=A=>A.map(K=>{let ae=te.current.get(K.id),le=ae!==void 0?{...K,isExpanded:ae}:K;return le.subtasks?.length?{...le,subtasks:E(le.subtasks)}:le});te.current.size>0?z(E(t)):z(t);},[t,z]);let xe=useRef(t),Pe=useRef(true);useEffect(()=>{if(Pe.current){Pe.current=false,xe.current=Y;return}if(!r)return;let E=JSON.stringify(xe.current),A=JSON.stringify(Y);E!==A&&(xe.current=Y,r(Y));},[Y,r]);let J=useMemo(()=>Ds(y,f),[y,f]),Ae=useCallback(E=>[{id:"name",label:E.columns.taskName,width:400,minWidth:200,maxWidth:2e3,visible:true,sortable:true,resizable:true},{id:"startDate",label:E.columns.startDate,width:110,minWidth:80,maxWidth:200,visible:false,sortable:true,resizable:true},{id:"endDate",label:E.columns.endDate,width:110,minWidth:80,maxWidth:200,visible:false,sortable:true,resizable:true},{id:"duration",label:E.columns.duration,width:80,minWidth:60,maxWidth:150,visible:false,sortable:true,resizable:true},{id:"assignees",label:E.columns.assignees,width:120,minWidth:80,maxWidth:300,visible:false,sortable:false,resizable:true},{id:"status",label:E.columns.status,width:100,minWidth:70,maxWidth:180,visible:false,sortable:true,resizable:true},{id:"progress",label:E.columns.progress,width:120,minWidth:80,maxWidth:200,visible:false,sortable:true,resizable:true},{id:"priority",label:E.columns.priority,width:90,minWidth:70,maxWidth:150,visible:false,sortable:true,resizable:true}],[]),[he,Ne]=useState(()=>Ae(J));useEffect(()=>{Ne(E=>E.map(A=>({...A,label:J.columns[A.id==="name"?"taskName":A.id]||A.label})));},[J]);let de=useMemo(()=>{let E=he.filter(ae=>ae.visible),A=E.some(ae=>ae.id!=="name");return E.reduce((ae,le)=>ae+le.width,0)+(A?20:0)},[he]);useEffect(()=>{ft!==null&&ft>de&&(he.filter(K=>K.visible).some(K=>K.id!=="name")||et(null));},[he,de,ft]);let Re=useMemo(()=>ft!==null?Math.max(280,ft,de):Math.max(280,de),[ft,de]),Fe=useRef(null),Oe=useRef(null),_=useRef(null),j=useMemo(()=>Yl(S),[S]),nt=useMemo(()=>({theme:j,themeName:S}),[j,S]),He=useMemo(()=>Md(d),[d]),ge=useMemo(()=>{if(!i)return Y;let E=ne.calculateCriticalPath(Y),A=K=>K.map(ae=>({...ae,isCriticalPath:E.includes(ae.id),subtasks:ae.subtasks?A(ae.subtasks):void 0}));return A(Y)},[Y,i]),Vt=vf(Me);Pd({undo:ke,redo:We,canUndo:Ue,canRedo:ht,enabled:true}),useImperativeHandle(o,()=>({getTask:E=>ne.findTaskById(Y,E),addTask:(E,A)=>{z(K=>{if(!A)return [...K,{...E,level:0}];let ae=le=>le.map(Se=>Se.id===A?{...Se,subtasks:[...Se.subtasks||[],{...E,parentId:A,level:(Se.level||0)+1}],isExpanded:true}:Se.subtasks?{...Se,subtasks:ae(Se.subtasks)}:Se);return ae(K)});},updateTask:(E,A)=>{z(K=>{let ae=le=>le.map(Se=>Se.id===E?{...Se,...A}:Se.subtasks?{...Se,subtasks:ae(Se.subtasks)}:Se);return ae(K)});},deleteTask:E=>{z(A=>{let K=ae=>ae.filter(le=>le.id===E?false:(le.subtasks&&(le.subtasks=K(le.subtasks)),true));return K(A)});},deleteTasks:E=>{z(A=>Is(A,E));},duplicateTask:E=>{z(A=>Ls(A,[E]));},splitTask:(E,A,K=3)=>{z(ae=>ne.splitTask(ae,E,A,K));},calculateEndDate:ne.calculateEndDate,calculateDuration:ne.calculateDuration,validateDependency:(E,A)=>!ne.validateDependencies(Y,E,A),getAllTasks:()=>ne.flattenTasks(Y),getTasksByStatus:E=>ne.flattenTasks(Y).filter(A=>A.status===E),getTasksByParent:E=>E?ne.findTaskById(Y,E)?.subtasks||[]:Y.filter(K=>!K.parentId),getCriticalPath:()=>ne.flattenTasks(Y).filter(E=>E.isCriticalPath),indentTask:E=>{z(A=>Ps(A,[E]));},outdentTask:E=>{z(A=>Ms(A,[E]));},moveTask:(E,A)=>{z(K=>As(K,[E],A));},createSubtask:async E=>{let{tasks:A,newTask:K}=Rs(Y,E);if(X){let ae=X({...K,parentId:E});if((ae instanceof Promise?await ae:ae)===false)return}z(A),ye&&ye({...K,parentId:E});},scrollToTask:E=>{let K=ne.flattenTasks(Y).findIndex(ae=>ae.id===E);if(K!==-1&&Fe.current){let ae=K*Vt;Fe.current.scrollTo({top:ae,behavior:"smooth"}),Oe.current&&Oe.current.scrollTo({top:ae,behavior:"smooth"});}},highlightTask:(E,A=2e3)=>{},expandTask:E=>{z(A=>{let K=ae=>ae.map(le=>le.id===E?{...le,isExpanded:true}:le.subtasks?{...le,subtasks:K(le.subtasks)}:le);return K(A)});},collapseTask:E=>{z(A=>{let K=ae=>ae.map(le=>le.id===E?{...le,isExpanded:false}:le.subtasks?{...le,subtasks:K(le.subtasks)}:le);return K(A)});},expandAll:()=>{z(E=>{let A=K=>K.map(ae=>({...ae,isExpanded:true,subtasks:ae.subtasks?A(ae.subtasks):void 0}));return A(E)});},collapseAll:()=>{z(E=>{let A=K=>K.map(ae=>({...ae,isExpanded:false,subtasks:ae.subtasks?A(ae.subtasks):void 0}));return A(E)});},undo:ke,redo:We,canUndo:()=>Ue,canRedo:()=>ht,clearHistory:Z,exportToPNG:async()=>{if(!_.current)throw new Error("Gantt container not found");let E=await Id(_.current,{backgroundColor:j.bgPrimary,scale:2});return new Promise((A,K)=>{E.toBlob(ae=>{ae?A(ae):K(new Error("Failed to create blob from canvas"));},"image/png");})},exportToPDF:async E=>{await ne.exportToPDF(Y,E);},exportToExcel:async E=>{await ne.exportToExcel(Y,E);},exportToJSON:()=>ne.exportToJSON(Y),exportToCSV:()=>ne.exportToCSV(Y),importFromJSON:E=>{let A=ne.importFromJSON(E);z(A);},getTasks:()=>Y,refresh:()=>{z(E=>[...E]);},clearAll:()=>{z([]);}}),[Y,ke,We,Ue,ht,Z,j,Vt]);let Tt=useCallback(E=>{Ne(A=>A.map(K=>K.id===E?{...K,visible:!K.visible}:K));},[]),U=useCallback((E,A)=>{Ne(K=>K.map(ae=>{if(ae.id!==E)return ae;let le=ae.minWidth??100,Se=ae.maxWidth??800,Bt=Math.max(le,Math.min(Se,A));return {...ae,width:Bt}}));},[]),ce=useCallback(E=>{z(A=>{let K=Bs(A,E),ae=le=>{for(let Se of le){if(Se.id===E){te.current.set(E,Se.isExpanded??true);return}Se.subtasks?.length&&ae(Se.subtasks);}};return ae(K),K}),a.onTaskToggleExpand?.(E);},[a]),Ce=useCallback((E,A)=>{if(we&&we(E,A)===false)return;let ae=ne.findTaskById(Y,E)?.progress,le=Bt=>Bt.map(Ht=>Ht.id===E?{...Ht,...A}:Ht.subtasks?{...Ht,subtasks:le(Ht.subtasks)}:Ht);z(le(Y));let Se=ne.findTaskById(le(Y),E);Se&&(M?.(Se),Ie?.(Se),A.progress!==void 0&&ae!==void 0&&A.progress!==ae&&v?.(E,ae,A.progress));},[Y,M,we,Ie,v]),zt=useCallback(E=>{E.length!==0&&(z(A=>Ps(A,E)),a.onTaskIndent?.(E[0]));},[a]),ea=useCallback(E=>{E.length!==0&&(z(A=>Ms(A,E)),a.onTaskOutdent?.(E[0]));},[a]),qa=useCallback((E,A,K)=>{z(ae=>gd(ae,E,A,K)),a.onTaskReparent?.(E,A,K);},[a]),Xr=useCallback((E,A)=>{E.length!==0&&(z(K=>As(K,E,A)),a.onTaskMove?.(E[0],A));},[a]),ie=useCallback(async E=>{let A=[];for(let K of E)Le&&await Promise.resolve(Le(K))===false||A.push(K);A.length!==0&&(a.onMultiTaskDelete?a.onMultiTaskDelete(A):(z(K=>Is(K,A)),A.forEach(K=>a.onTaskDelete?.(K))),O&&A.forEach(K=>O(K)));},[a,Le,O]),Dt=useCallback(E=>{z(A=>Ls(A,E)),E.forEach(A=>a.onTaskDuplicate?.(A));},[a]),Jt=useCallback((E,A)=>{z(K=>{let{tasks:ae,newTask:le}=ud(K,E,A);return X&&X(le)===false?K:(a.onTaskCreate?.(le.parentId,le.position||0),ye?.(le),ae)});},[a,X,ye]),Sr=useCallback((E,A)=>{z(K=>Fs(K,E,A)),a.onTaskRename?.(E,A);},[a]),Er=useCallback(E=>{z(A=>{let{tasks:K}=Rs(A,E);return a.onTaskCreate?.(E,0),K});},[a]),Pr=useCallback((E,A,K)=>{let ae=E.startDate?Math.round((A.getTime()-E.startDate.getTime())/864e5):0,le=Ht=>Ht.map(Zt=>Zt.id===E.id?{...Zt,startDate:A,endDate:K,...E.segments&&{segments:E.segments}}:Zt.subtasks?{...Zt,subtasks:le(Zt.subtasks)}:Zt),Se=le(Y);Se=ne.autoScheduleDependents(Se,E.id,ae),z(Se);let Bt={...E,startDate:A,endDate:K};M?.(Bt);},[Y,M]),Wa=useCallback((E,A)=>{N?.(E,A),se({isOpen:true,x:A.clientX,y:A.clientY,task:E});},[N]),ir=useCallback((E,A)=>{let K=ne.splitTask(Y,E.id,A);z(K),se({isOpen:false,x:0,y:0,task:null});},[Y]),Et=useCallback(E=>{let A=ne.findTaskById(Y,E.id)||E;D?.(A),L||De(A);},[Y,D,L]),So=useCallback((E,A,K)=>{let ae=new Map,le=Da=>{Da.forEach(Ha=>{Ha.dependencies&&ae.set(Ha.id,Ha.dependencies),Ha.subtasks&&le(Ha.subtasks);});};le(K);let Se=ae.get(A)||[];ae.set(A,[...Se,E]);let Bt=new Set,Ht=new Set,Zt=Da=>{if(!Bt.has(Da)){Bt.add(Da),Ht.add(Da);let Ha=ae.get(Da)||[];for(let lr of Ha){if(!Bt.has(lr)&&Zt(lr))return true;if(Ht.has(lr))return true}}return Ht.delete(Da),false};return Zt(A)},[]),Eo=useCallback((E,A)=>{if(So(E.id,A,Y)){console.warn("Cannot create dependency: would create a circular dependency"),alert(`Cannot create this dependency: it would create a circular dependency chain.
342
+ </Project>`,m=new Blob([n],{type:"application/xml;charset=utf-8;"}),d=document.createElement("a");d.href=URL.createObjectURL(m),d.download=a,d.click(),URL.revokeObjectURL(d.href);},calculateCriticalPath:e=>{let t=ne.flattenTasks(e),a=t.filter(n=>n.startDate&&n.endDate);if(a.length===0)return [];let r=new Map,o=n=>{if(r.has(n.id))return;let m=n.startDate&&n.endDate?ne.calculateDuration(n.startDate,n.endDate):0,d=0;if(n.dependencies&&n.dependencies.length>0)for(let u of n.dependencies){let y=t.find(f=>f.id===u);if(y){o(y);let f=r.get(u)?.ef||0;d=Math.max(d,f);}}let i=d+m;r.set(n.id,{es:d,ef:i});};a.forEach(o);let s=Math.max(...Array.from(r.values()).map(n=>n.ef)),l=new Map,c=n=>{if(l.has(n.id))return;let m=n.startDate&&n.endDate?ne.calculateDuration(n.startDate,n.endDate):0,d=t.filter(y=>y.dependencies&&y.dependencies.includes(n.id)),i=s;if(d.length>0)for(let y of d){c(y);let f=l.get(y.id)?.ls||0;i=Math.min(i,f);}let u=i-m;l.set(n.id,{ls:u,lf:i});};a.forEach(c);let p=[];for(let n of a){let m=r.get(n.id),d=l.get(n.id);if(m&&d){let i=d.ls-m.es;Math.abs(i)<.01&&p.push(n.id);}}return p},calculateSlack:(e,t)=>{let a=ne.findTaskById(e,t);if(!a||!a.startDate||!a.endDate)return null;if(ne.calculateCriticalPath(e).includes(t))return 0;let o=ne.getDependentTasks(e,t);if(o.length===0){let c=ne.getLatestEndDate(e);if(!c)return null;let p=ne.calculateDuration(a.endDate,c);return Math.max(0,p)}let s=o.filter(c=>c.startDate).map(c=>c.startDate.getTime()).sort((c,p)=>c-p)[0];if(!s)return null;let l=ne.calculateDuration(a.endDate,new Date(s));return Math.max(0,l)},isOnCriticalPath:(e,t)=>ne.calculateCriticalPath(e).includes(t),autoScheduleDependents:(e,t,a)=>{let r=ne.findTaskById(e,t);if(!r||!r.endDate)return e;let o=ne.getDependentTasks(e,t);if(o.length===0)return e;let s=[...e];for(let l of o){if(!l.startDate||!l.endDate)continue;let c=ne.calculateDuration(l.startDate,l.endDate),p;a!==void 0?(p=new Date(l.startDate),p.setDate(p.getDate()+a)):(p=new Date(r.endDate),p.setDate(p.getDate()+1));let n=ne.calculateEndDate(p,c),m=d=>d.map(i=>i.id===l.id?{...i,startDate:p,endDate:n}:i.subtasks?{...i,subtasks:m(i.subtasks)}:i);s=m(s),s=ne.autoScheduleDependents(s,l.id,a);}return s},calculateCascadePreview:(e,t,a,r,o,s,l,c)=>{if(a===0)return [];let p=[],n=o.getTime(),m=1e3*60*60*24,d=ne.findTaskById(e,t);if(!d||!d.endDate)return [];let i=(u,y,f=new Set)=>{if(f.has(u))return;f.add(u);let g=ne.getDependentTasks(e,u);for(let x of g){if(!x.startDate||!x.endDate)continue;let b=r.findIndex(k=>k.id===x.id);if(b===-1)continue;let h=x.startDate.getTime(),D=(x.endDate.getTime()-h)/m,M=(h-n)/m*s,v=M+y*s,L=Math.max(D*s,s),T=c+b*l+12;p.push({taskId:x.id,taskName:x.name,originalX:M,previewX:v,width:L,y:T,rowIndex:b,daysDelta:y,color:x.color}),i(x.id,y,f);}};return i(t,a),p},splitTask:(e,t,a,r=3)=>{let o=ne.findTaskById(e,t);if(!o||!o.startDate||!o.endDate)return e;if(a<=o.startDate||a>=o.endDate)return console.warn("Split date must be between task start and end dates"),e;let s=new Date(a);s.setDate(s.getDate()-1);let l=new Date(a);l.setDate(l.getDate()+r);let c=new Date(o.endDate);c.setDate(c.getDate()+r);let p=[{startDate:new Date(o.startDate),endDate:s},{startDate:l,endDate:c}],n=m=>m.map(d=>d.id===o.id?{...d,endDate:c,segments:p}:d.subtasks?{...d,subtasks:n(d.subtasks)}:d);return n(e)}};function ln({tasks:e,theme:t,rowHeight:a,timeScale:r,startDate:o,endDate:s,zoom:l,templates:c,onTaskClick:p,onTaskDblClick:n,onTaskContextMenu:m,onTaskDateChange:d,onDependencyCreate:i,onDependencyDelete:u}){let[f,g]=useState([]),[x,b]=useState(null),[h,w]=useState(null),D=useCallback(O=>{b(O);},[]),N=Math.ceil((s.getTime()-o.getTime())/(1e3*60*60*24)),M=r==="day"?60:r==="week"?20:8,v=N*M*l,L=O=>{let B=new Date(Date.UTC(O.getFullYear(),O.getMonth(),O.getDate())),W=B.getUTCDay()||7;B.setUTCDate(B.getUTCDate()+4-W);let S=new Date(Date.UTC(B.getUTCFullYear(),0,1));return Math.ceil(((B.getTime()-S.getTime())/864e5+1)/7)},T=O=>{let B=O.getDay();return B===0||B===6},k=useCallback(O=>{let B=Math.round(O/(M*l)),W=new Date(o);return W.setDate(W.getDate()+B),W},[o,M,l]),F=useCallback((O,B)=>{if(B.startDate&&B.endDate)return;let W=O.currentTarget.ownerSVGElement;if(!W)return;let S=W.createSVGPoint();S.x=O.clientX,S.y=O.clientY;let q=S.matrixTransform(W.getScreenCTM()?.inverse()),ee=k(q.x),$=new Date(ee);$.setDate($.getDate()+1),d?.(B,ee,$);},[k,d]),P=useMemo(()=>{let O=q=>q.map(ee=>{if(ee.subtasks&&ee.subtasks.length>0){let $=O(ee.subtasks),Me=$.filter(be=>be.startDate&&be.endDate);if(Me.length>0){let be=Me.map(Te=>Te.startDate.getTime()),qe=Me.map(Te=>Te.endDate.getTime()),ue=new Date(Math.min(...be)),Qe=new Date(Math.max(...qe));return {...ee,subtasks:$,startDate:ue,endDate:Qe}}return {...ee,subtasks:$}}return ee}),B=(q,ee=[])=>{for(let $ of q)ee.push($),$.subtasks&&$.subtasks.length>0&&($.isExpanded===void 0||$.isExpanded)&&B($.subtasks,ee);return ee},W=O(e);return B(W)},[e]),H=useCallback(O=>{if(!O.startDate||!O.endDate)return {x:0,width:0};let B=O.startDate.getTime(),W=O.endDate.getTime(),S=o.getTime(),q=(B-S)/(1e3*60*60*24),ee=(W-B)/(1e3*60*60*24),$=q*M*l,Me=Math.max(M*l,40),be=Math.max(ee*M*l,Me);return {x:$,width:be}},[o,M,l]),X=useMemo(()=>P.filter(O=>O.startDate&&O.endDate).map(O=>{let{x:B,width:W}=H(O),q=P.findIndex(ee=>ee.id===O.id)*a+12;return {id:O.id,x:B,y:q,width:W,height:32}}),[P,H]),ye=useCallback((O,B,W)=>{if(!W||B===0){g([]);return}let S=ne.calculateCascadePreview(e,O,B,P,o,M*l,a,48);g(S);},[e,P,o,M,l,a,48]),we=useMemo(()=>{let O=[],B=new Date(o);for(;B<=s;){let q=(B.getTime()-o.getTime())/864e5*M*l;if(r==="day")O.push({date:new Date(B),label:B.toLocaleDateString("en-US",{day:"numeric",month:"short"}),x:q}),B.setDate(B.getDate()+1);else if(r==="week"){let ee=L(B);O.push({date:new Date(B),label:`Week ${ee}`,x:q}),B.setDate(B.getDate()+7);}else O.push({date:new Date(B),label:B.toLocaleDateString("en-US",{month:"short",year:"numeric"}),x:q}),B.setMonth(B.getMonth()+1);}return O},[o,s,r,M,l]),Ie=useMemo(()=>(new Date().getTime()-o.getTime())/(1e3*60*60*24)*M*l,[o,M,l]),Le=Math.max(P.length*a,552);return jsxs("div",{className:"w-full h-full flex flex-col","data-gantt-chart":true,style:{backgroundColor:t.bgPrimary,overflow:"visible"},children:[jsx("div",{style:{position:"sticky",top:0,zIndex:10,backgroundColor:t.bgGrid,flexShrink:0,height:"48px",borderBottom:`1px solid ${t.border}`,boxSizing:"border-box"},children:jsxs("svg",{width:Math.max(v,1e3),height:47,style:{display:"block"},children:[jsx("rect",{x:0,y:0,width:Math.max(v,1e3),height:48,fill:t.bgGrid}),we.map((O,B)=>jsxs("g",{children:[B>0&&jsx("line",{x1:O.x,y1:0,x2:O.x,y2:48,stroke:t.border,strokeWidth:1,opacity:.1}),jsx("text",{x:O.x+8,y:48/2,fill:t.textTertiary,fontSize:"11",fontFamily:"'JetBrains Mono', ui-monospace, monospace",fontWeight:"500",dominantBaseline:"middle",children:O.label})]},`header-${B}`)),Ie>=0&&Ie<=v&&jsx("circle",{cx:Ie,cy:38,r:6,fill:t.today,opacity:1})]})}),jsxs("svg",{width:Math.max(v,1e3),height:Le,style:{display:"block",flexShrink:0,overflow:"visible"},children:[jsxs("defs",{children:[jsx("filter",{id:"shadow",children:jsx("feDropShadow",{dx:"0",dy:"1",stdDeviation:"2",floodOpacity:"0.1"})}),jsx("pattern",{id:"diagonal-stripes",width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)",children:jsx("line",{x1:"0",y1:"0",x2:"0",y2:"8",stroke:t.border,strokeWidth:"2"})})]}),jsx("rect",{x:0,y:0,width:Math.max(v,1e3),height:Le,fill:t.bgPrimary}),we.map((O,B)=>{let W=we[B+1]?.x||v,S=T(O.date);return jsxs("g",{children:[S&&jsx("rect",{x:O.x,y:0,width:W-O.x,height:P.length*a,fill:t.bgWeekend,opacity:1}),B>0&&jsx("line",{x1:O.x,y1:0,x2:O.x,y2:P.length*a,stroke:t.border,strokeWidth:1,opacity:.1})]},B)}),Ie>=0&&Ie<=v&&jsx("line",{x1:Ie,y1:0,x2:Ie,y2:P.length*a,stroke:t.today,strokeWidth:2,opacity:1}),P.map((O,B)=>{let W=O.startDate&&O.endDate;return jsxs("g",{children:[jsx("rect",{x:0,y:B*a,width:v,height:a,fill:B%2===0?"transparent":t.bgSecondary,opacity:1,style:{pointerEvents:"none"}},`row-${O.id}`),!W&&jsxs(Fragment,{children:[jsx("rect",{x:0,y:B*a,width:v,height:a,fill:"transparent",style:{cursor:"pointer",pointerEvents:"all"},onClick:S=>F(S,O),onMouseEnter:S=>{S.currentTarget.setAttribute("fill",t.accentLight),S.currentTarget.setAttribute("opacity","0.5");},onMouseLeave:S=>{S.currentTarget.setAttribute("fill","transparent"),S.currentTarget.setAttribute("opacity","1");}},`clickable-${O.id}`),jsx("text",{x:Ie>0?Ie:100,y:B*a+a/2,fill:t.textTertiary,fontSize:"12",fontFamily:"Inter, sans-serif",fontStyle:"italic",dominantBaseline:"middle",opacity:.4,style:{pointerEvents:"none",userSelect:"none"},children:"Click to set dates..."},`placeholder-${O.id}`)]})]},`row-group-${O.id}`)}),P.map((O,B)=>!O.dependencies||O.dependencies.length===0||!O.startDate||!O.endDate?null:O.dependencies.map(W=>{let S=P.find(Me=>Me.id===W);if(!S||!S.startDate||!S.endDate)return null;let q=P.findIndex(Me=>Me.id===W),ee=H(S),$=H(O);return jsx(rn,{x1:ee.x+ee.width,y1:q*a+a/2,x2:$.x,y2:B*a+a/2,theme:t},`dep-${W}-${O.id}`)})),P.map((O,B)=>{if(!O.startDate||!O.endDate)return null;let{x:W,width:S}=H(O),q=B*a+12,ee=O.subtasks&&O.subtasks.length>0&&!O.isMilestone;return O.isMilestone?jsx(nn,{task:O,x:W+S/2,y:q+16,theme:t,onClick:p},O.id):ee?jsxs("g",{onClick:()=>p?.(O),onContextMenu:$=>{$.preventDefault(),$.stopPropagation(),m?.(O,$);},style:{cursor:"default"},children:[jsx("rect",{x:W,y:q,width:S,height:32,fill:t.primary,opacity:.25,rx:6}),jsx("line",{x1:W,y1:q,x2:W+S,y2:q,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),jsx("line",{x1:W,y1:q,x2:W,y2:q+32,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),jsx("line",{x1:W+S,y1:q,x2:W+S,y2:q+32,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),jsx("line",{x1:W,y1:q+32,x2:W+S,y2:q+32,stroke:t.primary,strokeWidth:3,opacity:.9,strokeLinecap:"round"}),S>60&&jsx("text",{x:W+12,y:q+16,dominantBaseline:"middle",fill:"#FFFFFF",fontSize:"13",fontWeight:"500",fontFamily:"Inter, sans-serif",style:{pointerEvents:"none",userSelect:"none"},children:O.name})]},O.id):jsx(en,{task:O,x:W,y:q,width:S,theme:t,dayWidth:M*l,startDate:o,templates:c,onClick:p,onDoubleClick:n,onContextMenu:m,onDateChange:d,onDependencyCreate:i,allTaskPositions:X,onDragMove:ye,onHoverChange:D},O.id)}),P.map((O,B)=>!O.dependencies||O.dependencies.length===0||!O.startDate||!O.endDate?null:O.dependencies.map(W=>{let S=P.find(ve=>ve.id===W);if(!S||!S.startDate||!S.endDate)return null;let q=P.findIndex(ve=>ve.id===W),ee=H(S),$=H(O),Me=ee.x+ee.width,be=q*a+a/2,qe=$.x,ue=B*a+a/2,Qe=qe-Me,Te=Me+Qe/2,rt=ve=>{let De=1-ve,Ee=De*De,Ve=Ee*De,Ct=ve*ve,Y=Ct*ve,z=Ve*Me+3*Ee*ve*Te+3*De*Ct*Te+Y*qe,ke=Ve*be+3*Ee*ve*be+3*De*Ct*ue+Y*ue;return {x:z,y:ke}},gt=20,ft=[];for(let ve=0;ve<=gt;ve++){let De=.1+ve/gt*.8;ft.push(rt(De));}let et=ft[0],R=`M ${et.x} ${et.y} `+ft.slice(1).map(ve=>`L ${ve.x} ${ve.y}`).join(" ");return h&&h.x1===Me&&h.y1===be&&h.x2===qe&&h.y2===ue?null:jsx("path",{d:R,fill:"none",stroke:"transparent",strokeWidth:12,strokeLinecap:"round",style:{cursor:"pointer"},onMouseEnter:()=>{w({x1:Me,y1:be,x2:qe,y2:ue,onDelete:()=>u?.(O.id,W)});}},`dep-hover-${W}-${O.id}`)})),f.map(O=>jsxs("g",{style:{pointerEvents:"none"},children:[jsx("rect",{x:O.previewX,y:O.y-48,width:O.width,height:32,rx:8,fill:O.color||t.accent,opacity:.3,stroke:t.accent,strokeWidth:2,strokeDasharray:"4 2"}),Math.abs(O.daysDelta)>0&&jsx("text",{x:O.previewX+O.width/2,y:O.y-48+16,textAnchor:"middle",dominantBaseline:"middle",fill:t.accent,fontSize:"10",fontWeight:"600",fontFamily:"Inter, sans-serif",style:{userSelect:"none"},children:O.daysDelta>0?`+${O.daysDelta}d`:`${O.daysDelta}d`})]},`cascade-preview-${O.taskId}`)),h&&(()=>{let{x1:O,y1:B,x2:W,y2:S,onDelete:q}=h,ee=W-O,$=S-B,Me=O+ee/2,be=(B+S)/2,qe=`M ${O} ${B} C ${Me} ${B}, ${Me} ${S}, ${W} ${S}`,ue=6,Qe=Math.atan2($,ee),Te=W-ue*Math.cos(Qe-Math.PI/6),rt=S-ue*Math.sin(Qe-Math.PI/6),gt=W-ue*Math.cos(Qe+Math.PI/6),ft=S-ue*Math.sin(Qe+Math.PI/6),et=t.dependency,R="#f87171";return jsxs("g",{onMouseLeave:()=>w(null),children:[jsx("path",{d:qe,fill:"none",stroke:"transparent",strokeWidth:50,strokeLinecap:"round",style:{cursor:"pointer"}}),jsx("circle",{cx:Me,cy:be,r:25,fill:"transparent",style:{cursor:"pointer"}}),jsx("path",{d:qe,fill:"none",stroke:et,strokeWidth:8,strokeLinecap:"round",opacity:.15,style:{pointerEvents:"none",filter:"blur(4px)"}}),jsx("path",{d:qe,fill:"none",stroke:et,strokeWidth:2.5,strokeLinecap:"round",opacity:.9,style:{pointerEvents:"none"}}),jsx("path",{d:`M ${W} ${S} L ${Te} ${rt} M ${W} ${S} L ${gt} ${ft}`,fill:"none",stroke:et,strokeWidth:2.5,strokeLinecap:"round",opacity:.9,style:{pointerEvents:"none"}}),jsx("circle",{cx:W,cy:S,r:4,fill:et,opacity:.9,style:{pointerEvents:"none"}}),jsxs(motion.g,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{duration:.15,ease:"easeOut"},onClick:ve=>{ve.stopPropagation(),w(null),q();},style:{cursor:"pointer"},children:[jsx("circle",{cx:Me,cy:be,r:9,fill:"rgba(248, 113, 113, 0.15)",stroke:R,strokeWidth:1.5,style:{transition:"all 0.15s ease"}}),jsx("line",{x1:Me-3,y1:be-3,x2:Me+3,y2:be+3,stroke:R,strokeWidth:1.5,strokeLinecap:"round"}),jsx("line",{x1:Me+3,y1:be-3,x2:Me-3,y2:be+3,stroke:R,strokeWidth:1.5,strokeLinecap:"round"})]})]})})(),x&&jsx(wd,{tooltipData:x,theme:t})]})]})}var dn=[{name:"Azul",value:"#6366F1",light:"#818CF8"},{name:"P\xFArpura",value:"#A855F7",light:"#C084FC"},{name:"Rosa",value:"#EC4899",light:"#F472B6"},{name:"Rojo",value:"#EF4444",light:"#F87171"},{name:"Naranja",value:"#F59E0B",light:"#FBBF24"},{name:"Amarillo",value:"#EAB308",light:"#FACC15"},{name:"Lima",value:"#84CC16",light:"#A3E635"},{name:"Verde",value:"#10B981",light:"#34D399"},{name:"Esmeralda",value:"#059669",light:"#10B981"},{name:"Cyan",value:"#06B6D4",light:"#22D3EE"},{name:"Azul Cielo",value:"#0EA5E9",light:"#38BDF8"},{name:"\xCDndigo",value:"#4F46E5",light:"#6366F1"},{name:"Violeta",value:"#8B5CF6",light:"#A78BFA"},{name:"Fucsia",value:"#D946EF",light:"#E879F9"},{name:"Coral",value:"#F97316",light:"#FB923C"},{name:"Magenta",value:"#E11D48",light:"#FB7185"}];var Ws=[{id:"todo",title:"Por Hacer",color:"#6B7280"},{id:"in-progress",title:"En Progreso",color:"#F59E0B"},{id:"completed",title:"Completada",color:"#10B981"}],Hs=[{id:"low",label:"Baja",color:"#10B981",icon:"\u{1F7E2}"},{id:"medium",label:"Media",color:"#F59E0B",icon:"\u{1F7E1}"},{id:"high",label:"Alta",color:"#F97316",icon:"\u{1F7E0}"},{id:"urgent",label:"Urgente",color:"#EF4444",icon:"\u{1F534}"}];function cn({isOpen:e,onClose:t,task:a,availableTasks:r=[],availableUsers:o=[],onSubmit:s,isLoading:l=false,mode:c=a?"edit":"create",theme:p="dark",customStatuses:n=[],availableTags:m=[],onCreateTag:d,attachments:i=[],onUploadAttachments:u,onDeleteAttachment:y}){let f=[...Ws,...n.filter(R=>!Ws.some(se=>se.id===R.id))],g=Ge[p]||Ge.dark,[x,b]=useState(false),[h,w]=useState(false),[D,N]=useState(false),[M,v]=useState(false),[L,T]=useState({top:0,left:0}),[k,F]=useState(null),[P,H]=useState(new Date),[X$1,ye]=useState({top:0,left:0}),[we,Ie]=useState(false),[Le,O]=useState([]),B=useRef(null),W=useRef(null),S=useRef(null),q=useRef(null),ee=useRef(null),[$,Me]=useState({name:"",description:"",progress:0,status:"todo",priority:"medium",isMilestone:false,color:"#6366F1",assignees:[],dependencies:[],tags:[]}),[be,qe]=useState({});useEffect(()=>{a?(Me({name:a.name,description:a.description||"",startDate:a.startDate,endDate:a.endDate,progress:a.progress,status:a.status||"todo",priority:a.priority||"medium",isMilestone:a.isMilestone||false,color:a.color||"#6366F1",assignees:a.assignees||[],dependencies:a.dependencies||[],tags:a.tags||[]}),(a.dependencies&&a.dependencies.length>0||a.isMilestone)&&Ie(true)):(Me({name:"",description:"",progress:0,status:"todo",priority:"medium",isMilestone:false,color:"#6366F1",assignees:[],dependencies:[],pendingFiles:[],tags:[]}),Ie(false),O([]));},[a,e]),useEffect(()=>{let R=se=>{B.current&&!B.current.contains(se.target)&&b(false),W.current&&!W.current.contains(se.target)&&w(false),S.current&&!S.current.contains(se.target)&&N(false),q.current&&!q.current.contains(se.target)&&v(false);};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);let ue=()=>{let R={};return $.name.trim()||(R.name="El nombre es requerido"),$.startDate&&$.endDate&&$.startDate>$.endDate&&(R.endDate="La fecha de fin debe ser posterior a la de inicio"),qe(R),Object.keys(R).length===0},Qe=async R=>{if(R.preventDefault(),!!ue())try{let se=c==="create"&&Le.length>0?{...$,pendingFiles:Le}:$;await s(se),O([]),t();}catch(se){console.error("Error submitting task:",se);}},Te=(R,se)=>{Me(ve=>{let De={...ve,[R]:se};if(R==="status"){let Ee=se;Ee==="todo"?De.progress=0:Ee==="in-progress"?(ve.progress===0||ve.progress===100)&&(De.progress=50):Ee==="completed"||Ee==="closed"?De.progress=100:(Ee==="in-review"||Ee==="review")&&(De.progress=75);}if(R==="progress"){let Ee=typeof se=="number"?se:parseInt(se,10);Ee===100&&ve.status!=="completed"?De.status="completed":Ee>0&&Ee<100&&ve.status==="todo"?De.status="in-progress":Ee===0&&ve.status!=="todo"&&(De.status="todo");}return De}),be[R]&&qe(ve=>{let De={...ve};return delete De[R],De});},rt=f.find(R=>R.id===$.status)??Ws[0],gt=Hs.find(R=>R.id===$.priority)??Hs[1],ft=dn.find(R=>R.value===$.color)??dn[0],et={backgroundColor:g.bgSecondary,border:`1px solid ${g.borderLight}`,color:g.textPrimary};return jsx(AnimatePresence,{children:e&&jsxs(Fragment,{children:[jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 z-50",onClick:t}),jsx(motion.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.15,ease:[.4,0,.2,1]},className:"fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none",children:jsxs("div",{className:"w-full max-w-xl rounded-xl shadow-2xl pointer-events-auto overflow-hidden","data-theme":p,style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},onClick:R=>R.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between px-5 py-3",style:{borderBottom:`1px solid ${g.border}`},children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:rt.color||g.accent}}),jsx("span",{className:"text-sm font-medium",style:{color:g.textSecondary},children:c==="create"?"Nueva tarea":"Editar tarea"})]}),jsx("button",{onClick:t,className:"p-1.5 rounded-lg transition-colors",style:{color:g.textTertiary},onMouseEnter:R=>{R.currentTarget.style.backgroundColor=g.hoverBg,R.currentTarget.style.color=g.textPrimary;},onMouseLeave:R=>{R.currentTarget.style.backgroundColor="transparent",R.currentTarget.style.color=g.textTertiary;},disabled:l,children:jsx(X,{className:"w-4 h-4"})})]}),jsxs("form",{onSubmit:Qe,className:"max-h-[calc(100vh-200px)] overflow-y-auto",children:[jsxs("div",{className:"p-5 space-y-4",children:[jsxs("div",{children:[jsx("input",{type:"text",value:$.name,onChange:R=>Te("name",R.target.value),className:"w-full text-lg font-medium bg-transparent border-none focus:outline-none focus:ring-0 placeholder:opacity-50",style:{color:g.textPrimary},placeholder:"Nombre de la tarea",disabled:l,autoFocus:true}),be.name&&jsxs("p",{className:"mt-1 text-xs text-red-400 flex items-center gap-1",children:[jsx(AlertCircle,{className:"w-3 h-3"}),be.name]})]}),jsx("div",{children:jsx("textarea",{value:$.description||"",onChange:R=>Te("description",R.target.value),className:"w-full text-sm bg-transparent border-none focus:outline-none focus:ring-0 resize-none placeholder:opacity-40",style:{color:g.textSecondary},placeholder:"Agregar descripci\xF3n...",rows:2,disabled:l})}),jsx("div",{style:{borderTop:`1px solid ${g.borderLight}`}}),jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[jsxs("div",{ref:B,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>!l&&b(!x),className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:{...et,borderColor:rt.color,backgroundColor:`${rt.color}15`},disabled:l,children:[jsx(CircleDot,{className:"w-3.5 h-3.5",style:{color:rt.color}}),jsx("span",{style:{color:rt.color},children:rt.title}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:rt.color}})]}),jsx(AnimatePresence,{children:x&&jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:"absolute left-0 top-full mt-1 z-50 min-w-[140px] rounded-lg shadow-xl overflow-hidden",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},children:f.map(R=>jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors",style:{color:g.textPrimary},onMouseEnter:se=>se.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:se=>se.currentTarget.style.backgroundColor="transparent",onClick:()=>{Te("status",R.id),b(false);},children:[jsx(CircleDot,{className:"w-3.5 h-3.5",style:{color:R.color}}),R.title,$.status===R.id&&jsx(Check,{className:"w-3.5 h-3.5 ml-auto",style:{color:g.accent}})]},R.id))})})]}),jsxs("div",{ref:W,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>!l&&w(!h),className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:et,disabled:l,children:[jsx(Flag,{className:"w-3.5 h-3.5",style:{color:gt.color}}),jsx("span",{children:gt.label}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:g.textTertiary}})]}),jsx(AnimatePresence,{children:h&&jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:"absolute left-0 top-full mt-1 z-50 min-w-[130px] rounded-lg shadow-xl overflow-hidden",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},children:Hs.map(R=>jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors",style:{color:g.textPrimary},onMouseEnter:se=>se.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:se=>se.currentTarget.style.backgroundColor="transparent",onClick:()=>{Te("priority",R.id),w(false);},children:[jsx("span",{children:R.icon}),R.label,$.priority===R.id&&jsx(Check,{className:"w-3.5 h-3.5 ml-auto",style:{color:g.accent}})]},R.id))})})]}),o.length>0&&jsxs("div",{ref:S,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>!l&&N(!D),className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:et,disabled:l,children:[$.assignees&&$.assignees.length>0?jsxs(Fragment,{children:[jsx("div",{className:"flex -space-x-1",children:$.assignees.slice(0,3).map((R,se)=>jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center text-[10px] text-white font-medium border-2",style:{backgroundColor:R.color||g.accent,borderColor:g.bgSecondary},children:R.initials},se))}),$.assignees.length>3&&jsxs("span",{style:{color:g.textTertiary},children:["+",$.assignees.length-3]})]}):jsxs(Fragment,{children:[jsx(Users,{className:"w-3.5 h-3.5",style:{color:g.textTertiary}}),jsx("span",{style:{color:g.textTertiary},children:"Asignar"})]}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:g.textTertiary}})]}),jsx(AnimatePresence,{children:D&&jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:"absolute left-0 top-full mt-1 z-50 min-w-[180px] max-h-[200px] overflow-y-auto rounded-lg shadow-xl",style:{backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},children:o.map(R=>{let se=$.assignees?.some(ve=>ve.name===R.name);return jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors",style:{color:g.textPrimary},onMouseEnter:ve=>ve.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:ve=>ve.currentTarget.style.backgroundColor="transparent",onClick:()=>{let ve=se?($.assignees||[]).filter(De=>De.name!==R.name):[...$.assignees||[],{name:R.name,avatar:R.avatar,initials:R.name.split(" ").map(De=>De[0]).join("").toUpperCase().slice(0,2),color:g.accent}];Te("assignees",ve);},children:[jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center text-xs text-white font-medium flex-shrink-0",style:{backgroundColor:g.accent},children:R.name.charAt(0).toUpperCase()}),jsx("span",{className:"truncate flex-1 text-left",children:R.name}),jsx("div",{className:"w-4 flex-shrink-0 flex justify-end",children:se&&jsx(Check,{className:"w-3.5 h-3.5",style:{color:g.accent}})})]},R.id)})})})]}),jsxs("div",{ref:q,className:"relative",children:[jsxs("button",{type:"button",onClick:()=>{if(!l)if(M)v(false);else {if(q.current){let R=q.current.getBoundingClientRect(),se=window.innerHeight,ve=120,Ee=se-R.bottom<ve?R.top-ve-8:R.bottom+8;T({top:Ee,left:R.left});}v(true);}},className:"flex items-center gap-2 px-3 py-1.5 rounded-full text-sm transition-all hover:opacity-80",style:et,disabled:l,children:[jsx("div",{className:"w-3.5 h-3.5 rounded-full",style:{backgroundColor:$.color}}),jsx("span",{children:ft.name}),jsx(ChevronDown,{className:"w-3 h-3",style:{color:g.textTertiary}})]}),jsx(AnimatePresence,{children:M&&jsxs(tt,{children:[jsx("div",{className:"fixed inset-0",style:{zIndex:99998},onClick:()=>v(false)}),jsx(motion.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},transition:{duration:.12},className:"rounded-lg",style:{position:"fixed",top:`${L.top}px`,left:`${L.left}px`,zIndex:99999,backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`,boxShadow:"0 4px 20px rgba(0, 0, 0, 0.25)"},onClick:R=>R.stopPropagation(),children:jsx("div",{style:{padding:"14px 18px"},children:jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(6, 16px)",gap:"14px"},children:dn.slice(0,18).map(R=>{let se=$.color===R.value;return jsx(motion.button,{type:"button",onClick:()=>{Te("color",R.value),v(false);},style:{width:"16px",height:"16px",borderRadius:"50%",backgroundColor:R.value,outline:se?`2px solid ${R.value}`:"none",outlineOffset:"3px",cursor:"pointer",border:"none"},whileHover:{scale:1.2},whileTap:{scale:.95},title:R.name},R.value)})})})})]})})]}),m.length>0||d?jsx(Rr,{selectedTags:$.tags||[],availableTags:m,onChange:R=>Te("tags",R),onCreateTag:d,theme:g,disabled:l}):null]}),jsxs("div",{className:"flex items-center gap-3",children:[jsx(Calendar,{className:"w-4 h-4",style:{color:g.textTertiary}}),jsxs("div",{ref:ee,className:"flex items-center gap-2 flex-1 relative",children:[jsx("button",{type:"button",onClick:()=>{if(!l&&!$.isMilestone)if(k==="start")F(null);else {if(ee.current){let R=ee.current.getBoundingClientRect(),se=window.innerHeight,ve=320,Ee=se-R.bottom<ve?R.top-ve-8:R.bottom+8;ye({top:Ee,left:R.left});}F("start"),H($.startDate||new Date);}},className:"px-3 py-1.5 rounded-lg text-sm transition-colors",style:{...et,opacity:$.isMilestone?.5:1,cursor:$.isMilestone?"not-allowed":"pointer"},disabled:l||$.isMilestone,children:$.startDate?$.startDate.toLocaleDateString("es-ES",{day:"numeric",month:"short"}):"Inicio"}),jsx("span",{style:{color:g.textTertiary},children:"\u2192"}),jsx("button",{type:"button",onClick:()=>{if(!l&&!$.isMilestone)if(k==="end")F(null);else {if(ee.current){let R=ee.current.getBoundingClientRect(),se=window.innerHeight,ve=320,Ee=se-R.bottom<ve?R.top-ve-8:R.bottom+8;ye({top:Ee,left:R.left});}F("end"),H($.endDate||$.startDate||new Date);}},className:"px-3 py-1.5 rounded-lg text-sm transition-colors",style:{...et,opacity:$.isMilestone?.5:1,cursor:$.isMilestone?"not-allowed":"pointer"},disabled:l||$.isMilestone,children:$.endDate?$.endDate.toLocaleDateString("es-ES",{day:"numeric",month:"short"}):"Fin"}),jsx(AnimatePresence,{children:k&&jsxs(tt,{children:[jsx("div",{className:"fixed inset-0",style:{zIndex:99998},onClick:()=>F(null)}),jsxs(motion.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"rounded-xl shadow-2xl overflow-hidden flex",style:{position:"fixed",top:`${X$1.top}px`,left:`${X$1.left}px`,zIndex:99999,backgroundColor:g.bgPrimary,border:`1px solid ${g.border}`},onClick:R=>R.stopPropagation(),children:[jsxs("div",{className:"w-40 py-2",style:{borderRight:`1px solid ${g.border}`},children:[(()=>{let R=new Date,se=new Date(R);se.setDate(R.getDate()+1);let ve=new Date(R);ve.setDate(R.getDate()+7);let De=new Date(R);return De.setDate(R.getDate()+14),[{label:"Hoy",date:R},{label:"Ma\xF1ana",date:se},{label:"Pr\xF3xima semana",date:ve},{label:"2 semanas",date:De}].map((Ve,Ct)=>jsx("button",{type:"button",className:"w-full px-3 py-2 text-sm text-left transition-colors",style:{color:g.textPrimary},onMouseEnter:Y=>Y.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:Y=>Y.currentTarget.style.backgroundColor="transparent",onClick:()=>{k==="start"?(Te("startDate",Ve.date),(!$.endDate||Ve.date>$.endDate)&&Te("endDate",Ve.date),F("end")):(Te("endDate",Ve.date),(!$.startDate||Ve.date<$.startDate)&&Te("startDate",Ve.date),F(null));},children:Ve.label},Ct))})(),jsx("div",{style:{borderTop:`1px solid ${g.border}`,margin:"0.5rem 0"}}),jsx("button",{type:"button",className:"w-full px-3 py-2 text-sm text-left transition-colors",style:{color:"#EF4444"},onMouseEnter:R=>R.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:R=>R.currentTarget.style.backgroundColor="transparent",onClick:()=>{Te("startDate",void 0),Te("endDate",void 0),F(null);},children:"Borrar fechas"})]}),jsxs("div",{className:"p-3",children:[jsxs("div",{className:"flex items-center justify-between mb-3",children:[jsx("button",{type:"button",onClick:()=>H(new Date(P.getFullYear(),P.getMonth()-1)),className:"p-1 rounded hover:bg-white/10",children:jsx(ChevronLeft,{className:"w-4 h-4",style:{color:g.textSecondary}})}),jsx("span",{className:"text-sm font-medium",style:{color:g.textPrimary},children:P.toLocaleDateString("es-ES",{month:"long",year:"numeric"})}),jsx("button",{type:"button",onClick:()=>H(new Date(P.getFullYear(),P.getMonth()+1)),className:"p-1 rounded hover:bg-white/10",children:jsx(ChevronRight,{className:"w-4 h-4",style:{color:g.textSecondary}})})]}),jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:["D","L","M","M","J","V","S"].map((R,se)=>jsx("div",{className:"w-7 h-7 flex items-center justify-center text-xs",style:{color:g.textTertiary},children:R},se))}),jsx("div",{className:"grid grid-cols-7 gap-1",children:(()=>{let R=P.getFullYear(),se=P.getMonth(),ve=new Date(R,se,1).getDay(),De=new Date(R,se+1,0).getDate(),Ee=new Date,Ve=[];for(let Y=ve-1;Y>=0;Y--)Ve.push({day:new Date(R,se,-Y).getDate(),date:new Date(R,se-1,new Date(R,se,-Y).getDate()),isCurrentMonth:false});for(let Y=1;Y<=De;Y++)Ve.push({day:Y,date:new Date(R,se,Y),isCurrentMonth:true});let Ct=42-Ve.length;for(let Y=1;Y<=Ct;Y++)Ve.push({day:Y,date:new Date(R,se+1,Y),isCurrentMonth:false});return Ve.map((Y,z)=>{let ke=Y.date.toDateString()===Ee.toDateString(),We=$.startDate?.toDateString()===Y.date.toDateString(),Ue=$.endDate?.toDateString()===Y.date.toDateString(),ht=$.startDate&&$.endDate&&Y.date>=$.startDate&&Y.date<=$.endDate;return jsx("button",{type:"button",className:"w-7 h-7 rounded-full flex items-center justify-center text-xs transition-colors",style:{color:Y.isCurrentMonth?We||Ue?"#FFF":g.textPrimary:g.textTertiary,backgroundColor:We?"#3B82F6":Ue?"#7C3AED":ht?"rgba(124, 58, 237, 0.2)":"transparent",boxShadow:ke&&!We&&!Ue?"inset 0 0 0 1px #3B82F6":"none"},onClick:()=>{k==="start"?(Te("startDate",Y.date),$.endDate&&Y.date>$.endDate&&Te("endDate",Y.date),F("end")):(Te("endDate",Y.date),$.startDate&&Y.date<$.startDate&&Te("startDate",Y.date),F(null));},children:Y.day},z)})})()})]})]})]})})]}),be.endDate&&jsx("span",{className:"text-xs text-red-400",children:be.endDate})]}),jsxs("div",{className:"flex items-center gap-3",children:[jsx(Clock,{className:"w-4 h-4",style:{color:g.textTertiary}}),jsxs("div",{className:"flex items-center gap-3 flex-1",children:[jsx("input",{type:"range",min:"0",max:"100",step:"5",value:$.progress,onChange:R=>Te("progress",parseInt(R.target.value)),className:"flex-1 h-1.5 rounded-full appearance-none cursor-pointer",style:{backgroundColor:g.bgSecondary,accentColor:$.progress<30?"#EF4444":$.progress<70?"#F59E0B":"#10B981"},disabled:l}),jsxs("span",{className:"text-xs font-medium px-2 py-0.5 rounded-full min-w-[45px] text-center",style:{backgroundColor:`${$.progress<30?"#EF4444":$.progress<70?"#F59E0B":"#10B981"}20`,color:$.progress<30?"#EF4444":$.progress<70?"#F59E0B":"#10B981"},children:[$.progress,"%"]})]})]}),(u||i.length>0||c==="create")&&jsxs("div",{className:"pt-2",children:[jsxs("div",{className:"flex items-center gap-2 mb-2",children:[jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{color:g.textTertiary},children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})}),jsxs("span",{className:"text-xs",style:{color:g.textTertiary},children:["Adjuntos ",c==="create"?Le.length>0&&`(${Le.length})`:i.length>0&&`(${i.length})`]})]}),c==="create"?jsx(za,{cardId:"pending",attachments:Le.map((R,se)=>({id:`pending-${se}`,cardId:"pending",name:R.name,size:R.size,type:R.type,url:URL.createObjectURL(R),uploadedAt:new Date().toISOString(),uploadedBy:"current-user"})),onUpload:R=>O(se=>[...se,...R]),onDelete:R=>{let se=parseInt(R.replace("pending-",""),10);O(ve=>ve.filter((De,Ee)=>Ee!==se));},maxSizeMB:10,maxFiles:20}):jsx(za,{cardId:a?.id||"new",attachments:i,onUpload:u&&a?.id?R=>u(a.id,R):void 0,onDelete:y,maxSizeMB:10,maxFiles:20}),c==="create"&&Le.length>0&&jsxs("p",{className:"text-xs mt-1",style:{color:g.textTertiary},children:[Le.length," archivo(s) se subir\xE1n al crear la tarea"]})]}),jsxs("div",{children:[jsxs("button",{type:"button",onClick:()=>Ie(!we),className:"flex items-center gap-2 text-xs w-full py-2 transition-colors",style:{color:g.textTertiary},children:[jsx(ChevronDown,{className:`w-3 h-3 transition-transform ${we?"rotate-180":""}`}),"Opciones avanzadas"]}),jsx(AnimatePresence,{children:we&&jsx(motion.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:jsxs("div",{className:"pt-3 space-y-3",children:[jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-2 rounded-lg transition-colors hover:bg-white/5",children:[jsx("input",{type:"checkbox",checked:$.isMilestone,onChange:R=>Te("isMilestone",R.target.checked),className:"w-4 h-4 rounded",style:{accentColor:g.accent},disabled:l}),jsx(Milestone,{className:"w-4 h-4 text-yellow-500"}),jsx("span",{className:"text-sm",style:{color:g.textPrimary},children:"Marcar como hito"})]}),r.length>0&&jsxs("div",{children:[jsxs("label",{className:"flex items-center gap-2 text-xs mb-2",style:{color:g.textTertiary},children:[jsx(Link2,{className:"w-3.5 h-3.5"}),"Dependencias"]}),jsx("div",{className:"flex flex-wrap gap-1.5 max-h-24 overflow-y-auto p-2 rounded-lg",style:{backgroundColor:g.bgSecondary},children:r.filter(R=>R.id!==a?.id).map(R=>{let se=$.dependencies?.includes(R.id);return jsx("button",{type:"button",onClick:()=>{let ve=se?($.dependencies||[]).filter(De=>De!==R.id):[...$.dependencies||[],R.id];Te("dependencies",ve);},className:"px-2 py-1 rounded-full text-xs transition-colors",style:{backgroundColor:se?`${g.accent}30`:g.bgPrimary,color:se?g.accent:g.textSecondary,border:`1px solid ${se?g.accent:g.borderLight}`},disabled:l,children:R.name},R.id)})})]})]})})})]})]}),jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3",style:{borderTop:`1px solid ${g.border}`},children:[jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-sm rounded-lg transition-colors",style:{color:g.textSecondary},onMouseEnter:R=>R.currentTarget.style.backgroundColor=g.hoverBg,onMouseLeave:R=>R.currentTarget.style.backgroundColor="transparent",disabled:l,children:"Cancelar"}),jsx("button",{type:"submit",disabled:l,className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors flex items-center gap-2",style:{backgroundColor:g.accent,color:"#FFF"},onMouseEnter:R=>!l&&(R.currentTarget.style.opacity="0.9"),onMouseLeave:R=>!l&&(R.currentTarget.style.opacity="1"),children:l?jsxs(Fragment,{children:[jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}),"Guardando..."]}):jsx(Fragment,{children:c==="create"?"Crear tarea":"Guardar"})})]})]})]})})]})})}var rf=['Move "Task Name" to next Monday','Extend "Task Name" by 3 days','Rename "Old Name" to "New Name"','Set "Task Name" progress to 50%','Link "Task A" to "Task B"','Create a new task called "New Task"','Delete "Task Name"','Assign John to "Task Name"'],Sd=()=>jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("path",{d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707"}),jsx("circle",{cx:"12",cy:"12",r:"4"})]}),of=()=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13"})}),nf=()=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M18 6L6 18M6 6L18 18"})}),sf=()=>jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M5 12h14"})}),lf=()=>jsx("div",{className:"flex gap-1 items-center",children:[0,1,2].map(e=>jsx(motion.div,{className:"w-2 h-2 rounded-full bg-current",animate:{scale:[1,1.2,1],opacity:[.5,1,.5]},transition:{duration:.8,repeat:1/0,delay:e*.15}},e))});function pn({tasks:e,theme:t,config:a,onTasksUpdate:r,onTaskUpdate:o,onTaskCreate:s,onTaskDelete:l,onDependencyCreate:c,onDependencyDelete:p}){let[n,m]=useState(false),[d,i]=useState(false),[u,y]=useState([]),[f,g]=useState(""),[x,b]=useState(false),[h,w]=useState(true),D=useRef(null),N=useRef(null),M=useRef(null),{enabled:v=true,placeholder:L='Ask AI to edit tasks... (e.g., "Move Design to next week")',position:T="bottom-right",onCommand:k,suggestions:F=rf,maxHistory:P=50,persistHistory:H}=a,X=H?.storageKey||"gantt-ai-history",ye=H?.maxMessages??5;useEffect(()=>{if(H?.enabled)try{let W=localStorage.getItem(X);if(W){let q=JSON.parse(W).map(ee=>({...ee,timestamp:new Date(ee.timestamp)}));y(q.slice(-ye));}}catch(W){console.warn("[GanttAIAssistant] Failed to load persisted history:",W);}},[H?.enabled,X,ye]),useEffect(()=>{if(H?.enabled&&u.length>0)try{let W=u.filter(S=>!S.isLoading).slice(-ye);localStorage.setItem(X,JSON.stringify(W));}catch(W){console.warn("[GanttAIAssistant] Failed to persist history:",W);}},[u,H?.enabled,X,ye]),useEffect(()=>{N.current&&N.current.scrollIntoView({behavior:"smooth"});},[u]),useEffect(()=>{n&&!d&&D.current&&setTimeout(()=>D.current?.focus(),100);},[n,d]);let we=useCallback(W=>{if(W.success)switch(W.type){case "move_task":case "resize_task":case "rename_task":case "set_progress":case "set_status":case "assign_task":W.taskId&&W.updates&&o?.(W.taskId,W.updates);break;case "create_task":W.newTask&&s?.(W.newTask);break;case "delete_task":W.taskId&&l?.(W.taskId);break;case "link_tasks":W.dependencyFrom&&W.dependencyTo&&c?.(W.dependencyFrom,W.dependencyTo);break;case "unlink_tasks":W.taskId&&W.dependencyFrom&&p?.(W.taskId,W.dependencyFrom);break}},[o,s,l,c,p]),Ie=useCallback(async W=>{if(!W.trim()||x)return;let S={id:`user-${Date.now()}`,role:"user",content:W,timestamp:new Date};y(ee=>[...ee.slice(-(P-1)),S]),g(""),w(false),b(true);let q={id:`loading-${Date.now()}`,role:"assistant",content:"",timestamp:new Date,isLoading:true};y(ee=>[...ee,q]);try{if(k){let ee=await k(W,e);y($=>{let Me=$.filter(qe=>!qe.isLoading),be={id:`assistant-${Date.now()}`,role:"assistant",content:ee.message,timestamp:new Date,command:ee};return [...Me,be]}),we(ee);}else y(ee=>[...ee.filter(Me=>!Me.isLoading),{id:`assistant-${Date.now()}`,role:"assistant",content:"AI handler not configured. Please provide an onCommand handler in the aiAssistant config.",timestamp:new Date}]);}catch(ee){y($=>[...$.filter(be=>!be.isLoading),{id:`error-${Date.now()}`,role:"assistant",content:`Sorry, I encountered an error: ${ee instanceof Error?ee.message:"Unknown error"}`,timestamp:new Date}]);}finally{b(false);}},[x,P,k,e,we]),Le=W=>{W.preventDefault(),Ie(f);},O=W=>{g(W),D.current?.focus();};if(useEffect(()=>{let W=S=>{(S.metaKey||S.ctrlKey)&&S.key==="k"&&(S.preventDefault(),m(q=>!q),n||i(false)),S.key==="Escape"&&n&&m(false);};return document.addEventListener("keydown",W),()=>document.removeEventListener("keydown",W)},[n]),useEffect(()=>{if(!n)return;let W=q=>{let ee=q.target;M.current&&!M.current.contains(ee)&&m(false);},S=setTimeout(()=>{document.addEventListener("mousedown",W);},100);return ()=>{clearTimeout(S),document.removeEventListener("mousedown",W);}},[n]),!v)return null;let B={"bottom-right":"bottom-4 right-4","bottom-left":"bottom-4 left-4","top-right":"top-4 right-4","top-left":"top-4 left-4"};return jsxs(tt,{children:[jsx(AnimatePresence,{children:!n&&jsxs(motion.button,{initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},whileHover:{scale:1.05},whileTap:{scale:.95},className:`fixed ${B[T]} z-[99999] flex items-center gap-2 px-4 py-3 rounded-full shadow-lg transition-colors`,style:{background:"linear-gradient(135deg, #3B82F6 0%, #2563EB 100%)",color:"white",boxShadow:"0 4px 20px rgba(59, 130, 246, 0.4)"},onClick:()=>m(true),children:[jsx(Sd,{}),jsx("span",{className:"text-sm font-medium",children:"AI Assistant"}),jsx("kbd",{className:"hidden sm:inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] font-mono rounded bg-white/20",children:"\u2318K"})]})}),jsx(AnimatePresence,{children:n&&jsxs(motion.div,{ref:M,initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1,height:d?"auto":500},exit:{opacity:0,y:20,scale:.95},transition:{type:"spring",damping:25,stiffness:300},className:`fixed ${B[T]} z-[99999] w-96 rounded-2xl overflow-hidden shadow-2xl flex flex-col`,style:{background:t.bgPrimary,border:`1px solid ${t.border}`,boxShadow:`0 20px 60px rgba(0, 0, 0, 0.3), 0 0 0 1px ${t.border}`},children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:{background:"linear-gradient(135deg, #3B82F6 0%, #2563EB 100%)"},children:[jsxs("div",{className:"flex items-center gap-2 text-white",children:[jsx(Sd,{}),jsx("span",{className:"font-semibold",children:"Gantt AI Assistant"})]}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{onClick:()=>i(W=>!W),className:"p-1.5 rounded-lg hover:bg-white/20 text-white/80 hover:text-white transition-colors",children:jsx(sf,{})}),jsx("button",{onClick:()=>m(false),className:"p-1.5 rounded-lg hover:bg-white/20 text-white/80 hover:text-white transition-colors",children:jsx(nf,{})})]})]}),jsx(AnimatePresence,{children:!d&&jsxs(motion.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"flex flex-col flex-1 min-h-0",children:[jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4",style:{maxHeight:350},children:[u.length===0&&h&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-sm text-center",style:{color:t.textSecondary},children:"Try asking me to edit your Gantt chart:"}),jsx("div",{className:"flex flex-wrap gap-2",children:F.slice(0,4).map((W,S)=>jsx("button",{onClick:()=>O(W),className:"text-xs px-3 py-1.5 rounded-full transition-colors",style:{background:t.bgSecondary,color:t.textSecondary,border:`1px solid ${t.border}`},children:W.length>30?W.slice(0,30)+"...":W},S))})]}),u.map(W=>jsx(motion.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex ${W.role==="user"?"justify-end":"justify-start"}`,children:jsxs("div",{className:`max-w-[85%] rounded-2xl px-4 py-2.5 ${W.role==="user"?"rounded-br-md":"rounded-bl-md"}`,style:{background:W.role==="user"?"linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%)":t.bgSecondary,color:W.role==="user"?"white":t.textPrimary},children:[W.isLoading?jsx(lf,{}):jsx("p",{className:"text-sm whitespace-pre-wrap",children:W.content}),W.command&&jsxs("div",{className:"mt-2 text-xs px-2 py-1 rounded-md inline-flex items-center gap-1",style:{background:W.command.success?"rgba(16, 185, 129, 0.2)":"rgba(239, 68, 68, 0.2)",color:W.command.success?"#10B981":"#EF4444"},children:[W.command.success?"\u2713":"\u2717",jsx("span",{className:"capitalize",children:W.command.type.replace(/_/g," ")})]})]})},W.id)),jsx("div",{ref:N})]}),jsxs("form",{onSubmit:Le,className:"p-3 border-t",style:{borderColor:t.border},children:[jsxs("div",{className:"flex items-center gap-2 rounded-xl px-4 py-2",style:{background:t.bgSecondary,border:`1px solid ${t.border}`},children:[jsx("input",{ref:D,type:"text",value:f,onChange:W=>g(W.target.value),placeholder:L,disabled:x,className:"flex-1 bg-transparent text-sm outline-none",style:{color:t.textPrimary}}),jsx("button",{type:"submit",disabled:!f.trim()||x,className:"p-2 rounded-lg transition-all disabled:opacity-50",style:{background:f.trim()?"linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%)":"transparent",color:f.trim()?"white":t.textSecondary},children:jsx(of,{})})]}),jsx("p",{className:"text-[10px] text-center mt-2",style:{color:t.textTertiary},children:"Press Enter to send \u2022 Esc to close"})]})]})})]})})]})}function Ed(e,t=50){let[a,r]=useState({past:[],present:e,future:[]}),o=useRef(false),s=useCallback((n,m=true)=>{r(d=>{let i=typeof n=="function"?n(d.present):n;if(o.current)return {...d,present:i};if(!m)return {...d,present:i};let u=[...d.past,d.present];return u.length>t&&u.shift(),{past:u,present:i,future:[]}});},[t]),l=useCallback(()=>{r(n=>{if(n.past.length===0)return n;let m=n.past[n.past.length-1],d=n.past.slice(0,n.past.length-1);return o.current=true,setTimeout(()=>{o.current=false;},0),{past:d,present:m,future:[n.present,...n.future]}});},[]),c=useCallback(()=>{r(n=>{if(n.future.length===0)return n;let m=n.future[0],d=n.future.slice(1);return o.current=true,setTimeout(()=>{o.current=false;},0),{past:[...n.past,n.present],present:m,future:d}});},[]),p=useCallback(()=>{r(n=>({past:[],present:n.present,future:[]}));},[]);return {state:a.present,setState:s,undo:l,redo:c,canUndo:a.past.length>0,canRedo:a.future.length>0,clearHistory:p}}function Pd({undo:e,redo:t,canUndo:a,canRedo:r,enabled:o=true}){useEffect(()=>{if(!o)return;let s=l=>{let c=navigator.platform.toUpperCase().indexOf("MAC")>=0,p=c?l.metaKey:l.ctrlKey;if(p&&l.key==="z"&&!l.shiftKey&&a){l.preventDefault(),e();return}if(r){if(!c&&p&&l.key==="y"){l.preventDefault(),t();return}if(c&&p&&l.shiftKey&&l.key==="z"){l.preventDefault(),t();return}}};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s);}},[e,t,a,r,o]);}var mf={taskTooltip:e=>{let t=[`<strong>${e.name}</strong>`];if(e.startDate&&e.endDate){t.push(`${ne.formatDate(e.startDate)} - ${ne.formatDate(e.endDate)}`);let a=ne.calculateDuration(e.startDate,e.endDate);t.push(`Duration: ${a} days`);}if(e.progress!==void 0&&t.push(`Progress: ${e.progress}%`),e.status&&t.push(`Status: ${e.status}`),e.assignees&&e.assignees.length>0){let a=e.assignees.map(r=>r.name).join(", ");t.push(`Assigned: ${a}`);}return e.dependencies&&e.dependencies.length>0&&t.push(`Dependencies: ${e.dependencies.length}`),t.join("<br/>")},taskLabel:e=>e.name,gridCell:(e,t,a)=>a,taskClass:e=>{let t=[];return e.isCriticalPath&&t.push("critical-path"),e.status==="completed"?t.push("completed"):e.status==="in-progress"?t.push("in-progress"):e.status==="todo"&&t.push("todo"),e.isMilestone&&t.push("milestone"),t.join(" ")},milestoneContent:e=>`\u25C6 ${e.name}`,dateFormat:e=>ne.formatDate(e),durationFormat:e=>e===1?"1 day":`${e} days`,progressFormat:e=>`${e}%`};function Md(e){return {...mf,...e}}var vf=e=>{switch(e){case "compact":return 44;case "comfortable":return 52;case "spacious":return 60;default:return 52}},Ld=forwardRef(function({tasks:t,config:a={},onTasksChange:r},o){let{theme:s,timeScale:l="week",rowDensity:c="comfortable",showThemeSelector:p=true,showExportButton:n=true,availableUsers:m=[],templates:d,enableAutoCriticalPath:i=true,aiAssistant:u,locale:y="en",customTranslations:f,showCreateTaskButton:g=false,createTaskLabel:x,onCreateTask:b,onThemeChange:h,onTaskClick:w,onTaskDblClick:D,onTaskContextMenu:N,onTaskUpdate:M,onProgressChange:v,onTaskEdit:L,onTaskAddSubtask:T,onTaskMarkIncomplete:k,onTaskSetInProgress:F,onDependencyCreate:P,onDependencyDelete:H,onBeforeTaskAdd:X,onAfterTaskAdd:ye,onBeforeTaskUpdate:we,onAfterTaskUpdate:Ie,onBeforeTaskDelete:Le,onAfterTaskDelete:O}=a,W=useContext(Ko)?.theme,[S,q]=useState(W||s||"dark"),[ee,$]=useState(l),[Me,be]=useState(c),[qe,ue]=useState(1),[Qe,Te]=useState(0),[rt,gt]=useState(false),[ft,et]=useState(null),[R,se]=useState({isOpen:false,x:0,y:0,task:null}),[ve,De]=useState(null),[Ee,Ve]=useState(null);useEffect(()=>{W&&W!==S&&q(W);},[W]),useEffect(()=>{s&&s!==S&&q(s);},[s]);let Ct=useCallback(E=>{q(E),h?.(E);},[h]),{state:Y,setState:z,undo:ke,redo:We,canUndo:Ue,canRedo:ht,clearHistory:Z}=Ed(t,50),te=useRef(new Map);useEffect(()=>{let E=A=>A.map(K=>{let ae=te.current.get(K.id),le=ae!==void 0?{...K,isExpanded:ae}:K;return le.subtasks?.length?{...le,subtasks:E(le.subtasks)}:le});te.current.size>0?z(E(t)):z(t);},[t,z]);let xe=useRef(t),Pe=useRef(true);useEffect(()=>{if(Pe.current){Pe.current=false,xe.current=Y;return}if(!r)return;let E=JSON.stringify(xe.current),A=JSON.stringify(Y);E!==A&&(xe.current=Y,r(Y));},[Y,r]);let J=useMemo(()=>Ds(y,f),[y,f]),Ae=useCallback(E=>[{id:"name",label:E.columns.taskName,width:400,minWidth:200,maxWidth:2e3,visible:true,sortable:true,resizable:true},{id:"startDate",label:E.columns.startDate,width:110,minWidth:80,maxWidth:200,visible:false,sortable:true,resizable:true},{id:"endDate",label:E.columns.endDate,width:110,minWidth:80,maxWidth:200,visible:false,sortable:true,resizable:true},{id:"duration",label:E.columns.duration,width:80,minWidth:60,maxWidth:150,visible:false,sortable:true,resizable:true},{id:"assignees",label:E.columns.assignees,width:120,minWidth:80,maxWidth:300,visible:false,sortable:false,resizable:true},{id:"status",label:E.columns.status,width:100,minWidth:70,maxWidth:180,visible:false,sortable:true,resizable:true},{id:"progress",label:E.columns.progress,width:120,minWidth:80,maxWidth:200,visible:false,sortable:true,resizable:true},{id:"priority",label:E.columns.priority,width:90,minWidth:70,maxWidth:150,visible:false,sortable:true,resizable:true}],[]),[he,Ne]=useState(()=>Ae(J));useEffect(()=>{Ne(E=>E.map(A=>({...A,label:J.columns[A.id==="name"?"taskName":A.id]||A.label})));},[J]);let de=useMemo(()=>{let E=he.filter(ae=>ae.visible),A=E.some(ae=>ae.id!=="name");return E.reduce((ae,le)=>ae+le.width,0)+(A?20:0)},[he]);useEffect(()=>{ft!==null&&ft>de&&(he.filter(K=>K.visible).some(K=>K.id!=="name")||et(null));},[he,de,ft]);let Re=useMemo(()=>ft!==null?Math.max(280,ft,de):Math.max(280,de),[ft,de]),Fe=useRef(null),Oe=useRef(null),_=useRef(null),j=useMemo(()=>Yl(S),[S]),nt=useMemo(()=>({theme:j,themeName:S}),[j,S]),He=useMemo(()=>Md(d),[d]),ge=useMemo(()=>{if(!i)return Y;let E=ne.calculateCriticalPath(Y),A=K=>K.map(ae=>({...ae,isCriticalPath:E.includes(ae.id),subtasks:ae.subtasks?A(ae.subtasks):void 0}));return A(Y)},[Y,i]),Vt=vf(Me);Pd({undo:ke,redo:We,canUndo:Ue,canRedo:ht,enabled:true}),useImperativeHandle(o,()=>({getTask:E=>ne.findTaskById(Y,E),addTask:(E,A)=>{z(K=>{if(!A)return [...K,{...E,level:0}];let ae=le=>le.map(Se=>Se.id===A?{...Se,subtasks:[...Se.subtasks||[],{...E,parentId:A,level:(Se.level||0)+1}],isExpanded:true}:Se.subtasks?{...Se,subtasks:ae(Se.subtasks)}:Se);return ae(K)});},updateTask:(E,A)=>{z(K=>{let ae=le=>le.map(Se=>Se.id===E?{...Se,...A}:Se.subtasks?{...Se,subtasks:ae(Se.subtasks)}:Se);return ae(K)});},deleteTask:E=>{z(A=>{let K=ae=>ae.filter(le=>le.id===E?false:(le.subtasks&&(le.subtasks=K(le.subtasks)),true));return K(A)});},deleteTasks:E=>{z(A=>Is(A,E));},duplicateTask:E=>{z(A=>Ls(A,[E]));},splitTask:(E,A,K=3)=>{z(ae=>ne.splitTask(ae,E,A,K));},calculateEndDate:ne.calculateEndDate,calculateDuration:ne.calculateDuration,validateDependency:(E,A)=>!ne.validateDependencies(Y,E,A),getAllTasks:()=>ne.flattenTasks(Y),getTasksByStatus:E=>ne.flattenTasks(Y).filter(A=>A.status===E),getTasksByParent:E=>E?ne.findTaskById(Y,E)?.subtasks||[]:Y.filter(K=>!K.parentId),getCriticalPath:()=>ne.flattenTasks(Y).filter(E=>E.isCriticalPath),indentTask:E=>{z(A=>Ps(A,[E]));},outdentTask:E=>{z(A=>Ms(A,[E]));},moveTask:(E,A)=>{z(K=>As(K,[E],A));},createSubtask:async E=>{let{tasks:A,newTask:K}=Rs(Y,E);if(X){let ae=X({...K,parentId:E});if((ae instanceof Promise?await ae:ae)===false)return}z(A),ye&&ye({...K,parentId:E});},scrollToTask:E=>{let K=ne.flattenTasks(Y).findIndex(ae=>ae.id===E);if(K!==-1&&Fe.current){let ae=K*Vt;Fe.current.scrollTo({top:ae,behavior:"smooth"}),Oe.current&&Oe.current.scrollTo({top:ae,behavior:"smooth"});}},highlightTask:(E,A=2e3)=>{},expandTask:E=>{z(A=>{let K=ae=>ae.map(le=>le.id===E?{...le,isExpanded:true}:le.subtasks?{...le,subtasks:K(le.subtasks)}:le);return K(A)});},collapseTask:E=>{z(A=>{let K=ae=>ae.map(le=>le.id===E?{...le,isExpanded:false}:le.subtasks?{...le,subtasks:K(le.subtasks)}:le);return K(A)});},expandAll:()=>{z(E=>{let A=K=>K.map(ae=>({...ae,isExpanded:true,subtasks:ae.subtasks?A(ae.subtasks):void 0}));return A(E)});},collapseAll:()=>{z(E=>{let A=K=>K.map(ae=>({...ae,isExpanded:false,subtasks:ae.subtasks?A(ae.subtasks):void 0}));return A(E)});},undo:ke,redo:We,canUndo:()=>Ue,canRedo:()=>ht,clearHistory:Z,exportToPNG:async()=>{if(!_.current)throw new Error("Gantt container not found");let E=await Id(_.current,{backgroundColor:j.bgPrimary,scale:2});return new Promise((A,K)=>{E.toBlob(ae=>{ae?A(ae):K(new Error("Failed to create blob from canvas"));},"image/png");})},exportToPDF:async E=>{await ne.exportToPDF(Y,E);},exportToExcel:async E=>{await ne.exportToExcel(Y,E);},exportToJSON:()=>ne.exportToJSON(Y),exportToCSV:()=>ne.exportToCSV(Y),importFromJSON:E=>{let A=ne.importFromJSON(E);z(A);},getTasks:()=>Y,refresh:()=>{z(E=>[...E]);},clearAll:()=>{z([]);}}),[Y,ke,We,Ue,ht,Z,j,Vt]);let Tt=useCallback(E=>{Ne(A=>A.map(K=>K.id===E?{...K,visible:!K.visible}:K));},[]),U=useCallback((E,A)=>{Ne(K=>K.map(ae=>{if(ae.id!==E)return ae;let le=ae.minWidth??100,Se=ae.maxWidth??800,Bt=Math.max(le,Math.min(Se,A));return {...ae,width:Bt}}));},[]),ce=useCallback(E=>{z(A=>{let K=Bs(A,E),ae=le=>{for(let Se of le){if(Se.id===E){te.current.set(E,Se.isExpanded??true);return}Se.subtasks?.length&&ae(Se.subtasks);}};return ae(K),K}),a.onTaskToggleExpand?.(E);},[a]),Ce=useCallback((E,A)=>{if(we&&we(E,A)===false)return;let ae=ne.findTaskById(Y,E)?.progress,le=Bt=>Bt.map(Ht=>Ht.id===E?{...Ht,...A}:Ht.subtasks?{...Ht,subtasks:le(Ht.subtasks)}:Ht);z(le(Y));let Se=ne.findTaskById(le(Y),E);Se&&(M?.(Se),Ie?.(Se),A.progress!==void 0&&ae!==void 0&&A.progress!==ae&&v?.(E,ae,A.progress));},[Y,M,we,Ie,v]),zt=useCallback(E=>{E.length!==0&&(z(A=>Ps(A,E)),a.onTaskIndent?.(E[0]));},[a]),ea=useCallback(E=>{E.length!==0&&(z(A=>Ms(A,E)),a.onTaskOutdent?.(E[0]));},[a]),qa=useCallback((E,A,K)=>{z(ae=>gd(ae,E,A,K)),a.onTaskReparent?.(E,A,K);},[a]),Xr=useCallback((E,A)=>{E.length!==0&&(z(K=>As(K,E,A)),a.onTaskMove?.(E[0],A));},[a]),ie=useCallback(async E=>{let A=[];for(let K of E)Le&&await Promise.resolve(Le(K))===false||A.push(K);A.length!==0&&(a.onMultiTaskDelete?a.onMultiTaskDelete(A):(z(K=>Is(K,A)),A.forEach(K=>a.onTaskDelete?.(K))),O&&A.forEach(K=>O(K)));},[a,Le,O]),Dt=useCallback(E=>{z(A=>Ls(A,E)),E.forEach(A=>a.onTaskDuplicate?.(A));},[a]),Jt=useCallback((E,A)=>{z(K=>{let{tasks:ae,newTask:le}=ud(K,E,A);return X&&X(le)===false?K:(a.onTaskCreate?.(le.parentId,le.position||0),ye?.(le),ae)});},[a,X,ye]),Sr=useCallback((E,A)=>{z(K=>Fs(K,E,A)),a.onTaskRename?.(E,A);},[a]),Er=useCallback(E=>{z(A=>{let{tasks:K}=Rs(A,E);return a.onTaskCreate?.(E,0),K});},[a]),Pr=useCallback((E,A,K)=>{let ae=E.startDate?Math.round((A.getTime()-E.startDate.getTime())/864e5):0,le=Ht=>Ht.map(Zt=>Zt.id===E.id?{...Zt,startDate:A,endDate:K,...E.segments&&{segments:E.segments}}:Zt.subtasks?{...Zt,subtasks:le(Zt.subtasks)}:Zt),Se=le(Y);Se=ne.autoScheduleDependents(Se,E.id,ae),z(Se);let Bt={...E,startDate:A,endDate:K};M?.(Bt);},[Y,M]),Wa=useCallback((E,A)=>{N?.(E,A),se({isOpen:true,x:A.clientX,y:A.clientY,task:E});},[N]),ir=useCallback((E,A)=>{let K=ne.splitTask(Y,E.id,A);z(K),se({isOpen:false,x:0,y:0,task:null});},[Y]),Et=useCallback(E=>{let A=ne.findTaskById(Y,E.id)||E;D?.(A),L||De(A);},[Y,D,L]),So=useCallback((E,A,K)=>{let ae=new Map,le=Da=>{Da.forEach(Ha=>{Ha.dependencies&&ae.set(Ha.id,Ha.dependencies),Ha.subtasks&&le(Ha.subtasks);});};le(K);let Se=ae.get(A)||[];ae.set(A,[...Se,E]);let Bt=new Set,Ht=new Set,Zt=Da=>{if(!Bt.has(Da)){Bt.add(Da),Ht.add(Da);let Ha=ae.get(Da)||[];for(let lr of Ha){if(!Bt.has(lr)&&Zt(lr))return true;if(Ht.has(lr))return true}}return Ht.delete(Da),false};return Zt(A)},[]),Eo=useCallback((E,A)=>{if(So(E.id,A,Y)){console.warn("Cannot create dependency: would create a circular dependency"),alert(`Cannot create this dependency: it would create a circular dependency chain.
343
343
 
344
344
  Task dependencies must flow in one direction only.`);return}let K=ae=>ae.map(le=>{if(le.id===A){let Se=le.dependencies||[];if(!Se.includes(E.id))return {...le,dependencies:[...Se,E.id]}}return le.subtasks?{...le,subtasks:K(le.subtasks)}:le});z(K(Y)),P?.(E.id,A);},[Y,P,So]),An=useCallback((E,A)=>{let K=ae=>ae.map(le=>{if(le.id===E&&le.dependencies){let Se=le.dependencies.filter(Bt=>Bt!==A);return {...le,dependencies:Se}}return le.subtasks?{...le,subtasks:K(le.subtasks)}:le});z(K(Y)),H?.(E,A);},[Y,H]),{startDate:Jr,endDate:Kc}=useMemo(()=>{let E=Y.filter(Se=>Se.startDate&&Se.endDate);if(E.length===0){let Se=new Date,Bt=new Date(Se);Bt.setDate(Bt.getDate()-30);let Ht=new Date(Se);return Ht.setDate(Ht.getDate()+60),{startDate:Bt,endDate:Ht}}let A=E.flatMap(Se=>[Se.startDate,Se.endDate]).filter(Se=>Se!==void 0),K=new Date(Math.min(...A.map(Se=>Se.getTime()))),ae=new Date(Math.max(...A.map(Se=>Se.getTime()))),le=ee==="day"?7:ee==="week"?14:30;return K.setDate(K.getDate()-le),ae.setDate(ae.getDate()+le),{startDate:K,endDate:ae}},[Y,ee]),Yc=useCallback(async()=>{if(!_.current)return;let E=await Id(_.current,{backgroundColor:j.bgPrimary,scale:2}),A=document.createElement("a");A.download="gantt-chart.png",A.href=E.toDataURL("image/png"),A.click();},[j]),qc=useCallback(async()=>{await ne.exportToPDF(Y);},[Y]),Xc=useCallback(async()=>{await ne.exportToExcel(Y);},[Y]),Jc=useCallback(()=>{let E=ne.exportToCSV(Y),A=new Blob([E],{type:"text/csv;charset=utf-8;"}),K=document.createElement("a");K.href=URL.createObjectURL(A),K.download="gantt-chart.csv",K.click(),URL.revokeObjectURL(K.href);},[Y]),Zc=useCallback(()=>{let E=ne.exportToJSON(Y),A=new Blob([E],{type:"application/json;charset=utf-8;"}),K=document.createElement("a");K.href=URL.createObjectURL(A),K.download="gantt-chart.json",K.click(),URL.revokeObjectURL(K.href);},[Y]),Qc=useCallback(()=>{ne.exportToMSProject(Y,"Gantt Project","project.xml");},[Y]),ep=E=>{E.preventDefault(),gt(true);};return useEffect(()=>{let E=Oe.current,A=Fe.current;if(!E||!A)return;let K=A.querySelector(".gantt-taskgrid-content"),ae=()=>{let Zt=E.scrollTop;Te(Zt),K&&(K.style.transform=`translateY(-${Zt}px)`);},le=Zt=>{if(rt&&A){let Ha=A.parentElement?.getBoundingClientRect()?.left||0,lr=Zt.clientX-Ha,tp=280,ap=Math.min(window.innerWidth-300,800);lr>=tp&&lr<=ap&&et(lr);}},Se=()=>{gt(false);},Bt=A.querySelector(".gantt-grid-scroll")||A,Ht=Zt=>{let Da=Zt;Da.deltaY!==0&&(E.scrollTop+=Da.deltaY,Zt.preventDefault());};return E.addEventListener("scroll",ae),Bt.addEventListener("wheel",Ht,{passive:false}),document.addEventListener("mousemove",le),document.addEventListener("mouseup",Se),()=>{E.removeEventListener("scroll",ae),Bt.removeEventListener("wheel",Ht),document.removeEventListener("mousemove",le),document.removeEventListener("mouseup",Se);}},[rt]),jsx(Wr.Provider,{value:J,children:jsx(Rn.Provider,{value:nt,children:jsxs("div",{ref:_,className:"flex flex-col h-full w-full",style:{backgroundColor:j.bgPrimary,fontFamily:"Inter, sans-serif",minHeight:0,...a.disableScrollSync&&{scrollBehavior:"auto",overflowAnchor:"none"}},children:[jsx(qo,{theme:j,timeScale:ee,onTimeScaleChange:$,zoom:qe,onZoomChange:ue,currentTheme:S,onThemeChange:Ct,rowDensity:Me,onRowDensityChange:be,showThemeSelector:p,showCreateTaskButton:g,createTaskLabel:x,onCreateTask:b,onExportPNG:n?Yc:void 0,onExportPDF:n?qc:void 0,onExportExcel:n?Xc:void 0,onExportCSV:n?Jc:void 0,onExportJSON:n?Zc:void 0,onExportMSProject:n?Qc:void 0}),jsxs("div",{ref:Fe,className:"flex-1 flex min-h-0",style:{overflow:"clip",overflowClipMargin:"100px"},children:[jsx("div",{className:"gantt-grid-scroll flex-shrink-0",style:{width:Re,overflow:"hidden"},children:jsx(Qo,{tasks:ge,theme:j,rowHeight:Vt,availableUsers:m,templates:He,onTaskClick:w,onTaskDblClick:Et,onTaskContextMenu:N,onTaskToggle:ce,scrollTop:Qe,columns:he,onToggleColumn:Tt,onColumnResize:U,onTaskUpdate:Ce,onTaskIndent:zt,onTaskOutdent:ea,onTaskMove:Xr,onMultiTaskDelete:ie,onTaskDuplicate:Dt,onTaskCreate:Jt,onTaskRename:Sr,onCreateSubtask:Er,onOpenTaskModal:w?E=>w(E):void 0,onDeleteRequest:(E,A)=>Ve({taskId:E,taskName:A}),onTaskReparent:qa})}),jsx("div",{className:"flex-shrink-0 cursor-col-resize",style:{width:6,marginLeft:-3,zIndex:10},onMouseDown:ep}),jsx("div",{ref:Oe,className:"gantt-timeline-scroll flex-1",style:{minHeight:0,overflowX:"auto",overflowY:"auto",...a.disableScrollSync&&{scrollBehavior:"auto",overflowAnchor:"none"}},children:jsx(ln,{tasks:ge,theme:j,rowHeight:Vt,timeScale:ee,startDate:Jr,endDate:Kc,zoom:qe,templates:He,onTaskClick:w,onTaskDblClick:Et,onTaskContextMenu:Wa,onTaskDateChange:Pr,onDependencyCreate:Eo,onDependencyDelete:An})})]}),R.task&&jsx(Hr,{isOpen:R.isOpen,x:R.x,y:R.y,theme:j,onClose:()=>se({isOpen:false,x:0,y:0,task:null}),items:(()=>{let E=R.task;if(!E)return [];let A=ne.findTaskById(Y,E.id)||E;return A.subtasks&&A.subtasks.length>0?[{id:"addSubtask",label:J.contextMenu?.addSubtask||"Add Subtask",icon:kt.Add,onClick:()=>{T?T(A):Er(A.id);}},{id:"separator-delete",label:"",separator:true,onClick:()=>{}},{id:"delete",label:J.contextMenu?.deleteTask||"Delete Task",icon:kt.Delete,onClick:()=>{Ve({taskId:A.id,taskName:A.name});}}]:[{id:"edit",label:J.contextMenu?.editTask||"Edit Task",icon:kt.Pencil,onClick:()=>{L?L(A):De(A);}},{id:"addSubtask",label:J.contextMenu?.addSubtask||"Add Subtask",icon:kt.Add,onClick:()=>{T?T(A):Er(A.id);}},{id:"separator-status",label:"",separator:true,onClick:()=>{}},{id:"markIncomplete",label:J.contextMenu?.markIncomplete||"Mark Incomplete",icon:kt.MarkIncomplete,onClick:()=>{k?k(A):Ce(A.id,{status:"todo",progress:0});},disabled:A.status==="todo"},{id:"setInProgress",label:J.contextMenu?.setInProgress||"Set In Progress",icon:kt.SetInProgress,onClick:()=>{F?F(A):Ce(A.id,{status:"in-progress"});},disabled:A.status==="in-progress"},{id:"markComplete",label:J.contextMenu?.markComplete||"Mark Complete",icon:kt.MarkComplete,onClick:()=>{Ce(A.id,{status:"completed",progress:100});},disabled:A.status==="completed"},{id:"separator-advanced",label:"",separator:true,onClick:()=>{}},{id:"split",label:J.contextMenu?.splitTask||"Split Task",icon:kt.Split,onClick:()=>{if(!A.startDate||!A.endDate){console.warn("Cannot split task without dates");return}let ae=A.startDate.getTime(),le=A.endDate.getTime(),Se=ae+(le-ae)/2,Bt=new Date(Se);ir(A,Bt);},disabled:!A.startDate||!A.endDate},{id:"separator-delete",label:"",separator:true,onClick:()=>{}},{id:"delete",label:J.contextMenu?.deleteTask||"Delete Task",icon:kt.Delete,onClick:()=>{Ve({taskId:A.id,taskName:A.name});}}]})()}),ve&&jsx(cn,{isOpen:true,onClose:()=>De(null),task:ve,onSubmit:E=>{Ce(ve.id,E),De(null);},mode:"edit",theme:S}),jsx(AnimatePresence,{children:Ee&&jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[10000] flex items-center justify-center p-4",style:{backgroundColor:"rgba(0, 0, 0, 0.6)"},onClick:()=>Ve(null),children:jsxs(motion.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},transition:{duration:.2,ease:"easeOut"},onClick:E=>E.stopPropagation(),className:"w-full max-w-md rounded-xl shadow-2xl overflow-hidden",style:{backgroundColor:j.bgSecondary,border:`1px solid ${j.border}`},children:[jsx("div",{className:"px-6 py-4",style:{borderBottom:`1px solid ${j.border}`},children:jsxs("div",{className:"flex items-start gap-3",children:[jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0",style:{backgroundColor:"rgba(239, 68, 68, 0.2)"},children:jsx(AlertTriangle,{className:"w-5 h-5",style:{color:"#EF4444"}})}),jsxs("div",{className:"flex-1",children:[jsxs("h3",{className:"text-lg font-semibold",style:{color:j.textPrimary,fontFamily:"Inter, sans-serif"},children:[J.contextMenu?.deleteTask||"Delete Task","?"]}),jsx("p",{className:"text-sm mt-1",style:{color:j.textSecondary,fontFamily:"Inter, sans-serif"},children:y==="es"?"Esta acci\xF3n no se puede deshacer":"This action cannot be undone"})]})]})}),jsx("div",{className:"px-6 py-4",children:jsxs("p",{className:"text-sm leading-relaxed",style:{color:j.textSecondary,fontFamily:"Inter, sans-serif"},children:[y==="es"?"Est\xE1s a punto de eliminar la tarea":"You are about to delete the task"," ",jsxs("span",{className:"font-semibold",style:{color:j.textPrimary},children:['"',Ee.taskName,'"']}),"."]})}),jsxs("div",{className:"px-6 py-4 flex items-center justify-end gap-3",style:{backgroundColor:j.bgPrimary,borderTop:`1px solid ${j.border}`},children:[jsx("button",{onClick:()=>Ve(null),className:"px-4 py-2 text-sm font-medium rounded-lg transition-colors",style:{color:j.textSecondary,fontFamily:"Inter, sans-serif"},onMouseEnter:E=>{E.currentTarget.style.backgroundColor=j.hoverBg;},onMouseLeave:E=>{E.currentTarget.style.backgroundColor="transparent";},children:y==="es"?"Cancelar":"Cancel"}),jsxs("button",{onClick:()=>{ie([Ee.taskId]),Ve(null);},className:"px-4 py-2 text-sm font-medium text-white rounded-lg transition-colors flex items-center gap-2",style:{backgroundColor:"#EF4444",fontFamily:"Inter, sans-serif"},onMouseEnter:E=>{E.currentTarget.style.backgroundColor="#DC2626";},onMouseLeave:E=>{E.currentTarget.style.backgroundColor="#EF4444";},children:[jsx(Trash2,{className:"w-4 h-4"}),y==="es"?"Eliminar":"Delete"]})]})]})})}),u?.enabled&&jsx(pn,{tasks:Y,theme:j,config:u,onTasksUpdate:z,onTaskUpdate:Ce,onTaskCreate:E=>{z(A=>[...A,E]);},onTaskDelete:E=>{ie([E]);},onDependencyCreate:(E,A)=>{let K=ne.findTaskById(Y,E);K&&Eo(K,A);},onDependencyDelete:An})]})})})});var Fd=`You are a Gantt chart AI assistant. You help users edit project tasks using natural language commands.
345
345