@polderlabs/bizar 4.4.7 → 4.4.8

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.
@@ -350,5 +350,5 @@ Error generating stack: `+l.message+`
350
350
  * @license qrcode.react
351
351
  * Copyright (c) Paul O'Shannessy
352
352
  * SPDX-License-Identifier: ISC
353
- */var P2={L:xr.QrCode.Ecc.LOW,M:xr.QrCode.Ecc.MEDIUM,Q:xr.QrCode.Ecc.QUARTILE,H:xr.QrCode.Ecc.HIGH},Yp=128,Kp="L",Gp="#FFFFFF",Xp="#000000",Zp=!1,Jp=1,A2=4,M2=0,L2=.1;function eg(e,t=0){const n=[];return e.forEach(function(r,i){let l=null;r.forEach(function(s,o){if(!s&&l!==null){n.push(`M${l+t} ${i+t}h${o-l}v1H${l+t}z`),l=null;return}if(o===r.length-1){if(!s)return;l===null?n.push(`M${o+t},${i+t} h1v1H${o+t}z`):n.push(`M${l+t},${i+t} h${o+1-l}v1H${l+t}z`);return}s&&l===null&&(l=o)})}),n.join("")}function tg(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,l)=>l<t.x||l>=t.x+t.w?i:!1))}function R2(e,t,n,r){if(r==null)return null;const i=e.length+n*2,l=Math.floor(t*L2),s=i/t,o=(r.width||l)*s,u=(r.height||l)*s,d=r.x==null?e.length/2-o/2:r.x*s,c=r.y==null?e.length/2-u/2:r.y*s,f=r.opacity==null?1:r.opacity;let h=null;if(r.excavate){let p=Math.floor(d),x=Math.floor(c),S=Math.ceil(o+d-p),y=Math.ceil(u+c-x);h={x:p,y:x,w:S,h:y}}const m=r.crossOrigin;return{x:d,y:c,h:u,w:o,excavation:h,opacity:f,crossOrigin:m}}function D2(e,t){return t!=null?Math.max(Math.floor(t),0):e?A2:M2}function ng({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:l,size:s,boostLevel:o}){let u=Ae.useMemo(()=>{const p=(Array.isArray(e)?e:[e]).reduce((x,S)=>(x.push(...xr.QrSegment.makeSegments(S)),x),[]);return xr.QrCode.encodeSegments(p,P2[t],n,void 0,void 0,o)},[e,t,n,o]);const{cells:d,margin:c,numCells:f,calculatedImageSettings:h}=Ae.useMemo(()=>{let m=u.getModules();const p=D2(r,i),x=m.length+p*2,S=R2(m,s,p,l);return{cells:m,margin:p,numCells:x,calculatedImageSettings:S}},[u,s,l,r,i]);return{qrcode:u,margin:c,cells:d,numCells:f,calculatedImageSettings:h}}var _2=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),O2=Ae.forwardRef(function(t,n){const r=t,{value:i,size:l=Yp,level:s=Kp,bgColor:o=Gp,fgColor:u=Xp,includeMargin:d=Zp,minVersion:c=Jp,boostLevel:f,marginSize:h,imageSettings:m}=r,x=Ia(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:S}=x,y=Ia(x,["style"]),g=m==null?void 0:m.src,v=Ae.useRef(null),C=Ae.useRef(null),z=Ae.useCallback(H=>{v.current=H,typeof n=="function"?n(H):n&&(n.current=H)},[n]),[N,P]=Ae.useState(!1),{margin:M,cells:T,numCells:k,calculatedImageSettings:j}=ng({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:h,imageSettings:m,size:l});Ae.useEffect(()=>{if(v.current!=null){const H=v.current,L=H.getContext("2d");if(!L)return;let te=T;const J=C.current,D=j!=null&&J!==null&&J.complete&&J.naturalHeight!==0&&J.naturalWidth!==0;D&&j.excavation!=null&&(te=tg(T,j.excavation));const V=window.devicePixelRatio||1;H.height=H.width=l*V;const w=l/k*V;L.scale(w,w),L.fillStyle=o,L.fillRect(0,0,k,k),L.fillStyle=u,_2?L.fill(new Path2D(eg(te,M))):T.forEach(function(ne,ae){ne.forEach(function(E,ye){E&&L.fillRect(ye+M,ae+M,1,1)})}),j&&(L.globalAlpha=j.opacity),D&&L.drawImage(J,j.x+M,j.y+M,j.w,j.h)}}),Ae.useEffect(()=>{P(!1)},[g]);const I=za({height:l,width:l},S);let $=null;return g!=null&&($=Ae.createElement("img",{src:g,key:g,style:{display:"none"},onLoad:()=>{P(!0)},ref:C,crossOrigin:j==null?void 0:j.crossOrigin})),Ae.createElement(Ae.Fragment,null,Ae.createElement("canvas",za({style:I,height:l,width:l,ref:z,role:"img"},y)),$)});O2.displayName="QRCodeCanvas";var rg=Ae.forwardRef(function(t,n){const r=t,{value:i,size:l=Yp,level:s=Kp,bgColor:o=Gp,fgColor:u=Xp,includeMargin:d=Zp,minVersion:c=Jp,boostLevel:f,title:h,marginSize:m,imageSettings:p}=r,x=Ia(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:S,cells:y,numCells:g,calculatedImageSettings:v}=ng({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:m,imageSettings:p,size:l});let C=y,z=null;p!=null&&v!=null&&(v.excavation!=null&&(C=tg(y,v.excavation)),z=Ae.createElement("image",{href:p.src,height:v.h,width:v.w,x:v.x+S,y:v.y+S,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const N=eg(C,S);return Ae.createElement("svg",za({height:l,width:l,viewBox:`0 0 ${g} ${g}`,ref:n,role:"img"},x),!!h&&Ae.createElement("title",null,h),Ae.createElement("path",{fill:o,d:`M0,0 h${g}v${g}H0z`,shapeRendering:"crispEdges"}),Ae.createElement("path",{fill:u,d:N,shapeRendering:"crispEdges"}),z)});rg.displayName="QRCodeSVG";function F2({tabs:e,activeTab:t,onChange:n}){return a.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:e.map(r=>{const i=r.icon;return a.jsxs("button",{type:"button",className:Eu("mobile-nav-btn",t===r.id&&"mobile-nav-btn-active"),onClick:()=>n(r.id),"aria-label":r.label,"aria-current":t===r.id?"page":void 0,children:[a.jsx(i,{size:22}),a.jsx("span",{className:"mobile-nav-label",children:r.label})]},r.id)})})}function _t({open:e,onClose:t,title:n,children:r,actions:i,maxHeight:l="85vh"}){const s=b.useRef(null),o=b.useRef(null),u=b.useId(),d=b.useRef(null),c=b.useRef(null),f=b.useRef(0),h=b.useRef(0),m=()=>{var y;return((y=s.current)==null?void 0:y.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(b.useEffect(()=>{if(!e)return;d.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const y=g=>{var P;if(g.key==="Escape"&&t(),g.key!=="Tab")return;const v=Array.from(m());if(v.length===0){g.preventDefault(),(P=s.current)==null||P.focus();return}const C=v[0],z=v[v.length-1],N=document.activeElement;if(g.shiftKey){(!N||N===C||N===s.current)&&(g.preventDefault(),z==null||z.focus());return}N===z&&(g.preventDefault(),C==null||C.focus())};return window.addEventListener("keydown",y),requestAnimationFrame(()=>{var g,v;((g=o.current)==null?void 0:g.focus())??((v=s.current)==null||v.focus())}),()=>{var g;window.removeEventListener("keydown",y),(g=d.current)==null||g.focus()}},[e,t]),b.useEffect(()=>(e?(h.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${h.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%"):(document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width=""),()=>{document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,h.current)}),[e]),!e)return null;const p=y=>{var g;y.isPrimary&&(c.current=y.clientY,f.current=0,(g=s.current)==null||g.setPointerCapture(y.pointerId))},x=y=>{if(c.current==null||!s.current)return;const g=Math.max(0,y.clientY-c.current);f.current=g,s.current.style.transform=`translateY(${g}px)`},S=y=>{if(!s.current)return;y&&s.current.hasPointerCapture(y.pointerId)&&s.current.releasePointerCapture(y.pointerId);const g=f.current;s.current.style.transform="",c.current=null,f.current=0,g>72&&t()};return a.jsx("div",{className:"mobile-sheet-overlay",onClick:t,children:a.jsxs("div",{ref:s,className:"mobile-sheet",style:{maxHeight:l},onClick:y=>y.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Sheet","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsx("div",{className:"mobile-sheet-handle",onPointerDown:p,onPointerMove:x,onPointerUp:S,onPointerCancel:S,"aria-hidden":"true"}),a.jsxs("div",{className:"mobile-sheet-header",children:[n?a.jsx("h3",{id:u,className:"mobile-sheet-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:o,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(tr,{size:18})})]}),a.jsx("div",{className:"mobile-sheet-content",children:r}),i&&a.jsx("div",{className:"mobile-sheet-actions",children:i})]})})}function $2(e){switch(e){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function B2(e){const t=new Date(e),r=Date.now()-t.getTime();return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:t.toLocaleDateString()}function U2({onSelect:e}){const[t,n]=b.useState(!1),[r,i]=b.useState([]),[l,s]=b.useState(0),o=async()=>{var c;try{const f=await Q.get("/notifications");i(f.notifications||[]),s(((c=f.stats)==null?void 0:c.unread)||0)}catch{}};b.useEffect(()=>{o()},[]),b.useEffect(()=>{t&&o()},[t]);const u=async()=>{try{await Q.post("/notifications/read-all"),i(c=>c.map(f=>({...f,read:!0}))),s(0)}catch{}},d=async c=>{try{await Q.post(`/notifications/${encodeURIComponent(c)}/read`),i(f=>f.map(h=>h.id===c?{...h,read:!0}:h)),s(f=>Math.max(0,f-1))}catch{}};return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>n(!0),"aria-label":`Notifications${l>0?` (${l} unread)`:""}`,children:[a.jsx(rd,{size:20}),l>0&&a.jsx("span",{className:"mobile-notif-badge",children:l>9?"9+":l})]}),a.jsx(_t,{open:t,onClose:()=>n(!1),title:"Notifications",actions:l>0?a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:u,children:[a.jsx(B1,{size:14})," Mark all read"]}):void 0,children:a.jsxs("div",{className:"mobile-notif-list",children:[r.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(rd,{size:32}),a.jsx("p",{children:"No notifications"})]}),r.map(c=>a.jsxs("button",{type:"button",className:`mobile-notif-item ${c.read?"read":"unread"}`,onClick:()=>{c.read||d(c.id),e(c),n(!1)},children:[a.jsx("span",{className:`mobile-notif-icon severity-${c.severity}`,children:$2(c.severity)}),a.jsxs("div",{className:"mobile-notif-body",children:[a.jsx("span",{className:"mobile-notif-title",children:c.title||c.message}),c.message&&c.title&&a.jsx("span",{className:"mobile-notif-text",children:c.message}),a.jsx("span",{className:"mobile-notif-time",children:B2(c.ts)})]}),!c.read&&a.jsx("span",{className:"mobile-notif-dot"})]},c.id))]})})]})}const H2={activity:"Activity",chat:"Chat",tasks:"Tasks",settings:"Settings",more:"More",plans:"Plans",agents:"Agents",skills:"Skills",mods:"Mods",schedules:"Schedules",history:"History",config:"Config","plan-detail":"Plan","agent-detail":"Agent","task-detail":"Task"};function V2({activeTab:e,snapshot:t,onSearch:n,onNavigate:r}){const[i,l]=b.useState(!1),s=async o=>{try{await Q.post(`/projects/${encodeURIComponent(o)}/activate`),l(!1),window.location.reload()}catch{}};return a.jsxs("header",{className:"mobile-topbar",children:[a.jsxs("div",{className:"mobile-topbar-left",children:[a.jsx("span",{className:"mobile-logo",children:"ᛒ"}),(t==null?void 0:t.activeProject)&&a.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>l(!0),"aria-label":"Select project",children:[a.jsx("span",{className:"mobile-project-name",children:t.activeProject.name}),a.jsx(Cs,{size:14})]}),a.jsx("span",{className:"mobile-title",children:H2[e]||"Bizar"})]}),a.jsxs("div",{className:"mobile-topbar-right",children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:n,"aria-label":"Search",children:a.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[a.jsx("circle",{cx:"11",cy:"11",r:"8"}),a.jsx("path",{d:"m21 21-4.35-4.35"})]})}),a.jsx(U2,{onSelect:o=>{r("notification",o.link||"",o.meta??null)}}),(t==null?void 0:t.activeProject)&&a.jsx(_t,{open:i,onClose:()=>l(!1),title:"Projects",children:a.jsx("div",{className:"mobile-project-list",children:(t.projects||[]).map(o=>{var u,d;return a.jsxs("button",{type:"button",className:`mobile-project-item ${o.id===((u=t.activeProject)==null?void 0:u.id)?"active":""}`,onClick:()=>s(o.id),children:[a.jsx("div",{className:"mobile-project-status","data-status":o.status}),a.jsxs("div",{className:"mobile-project-info",children:[a.jsx("span",{className:"mobile-project-item-name",children:o.name}),a.jsx("span",{className:"mobile-project-item-path",children:o.path})]}),o.id===((d=t.activeProject)==null?void 0:d.id)&&a.jsx("span",{className:"mobile-active-badge",children:"active"})]},o.id)})})})]})]})}const W2=["all","tasks","agents","bg","artifacts","mods"],ko={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function Q2({snapshot:e,onRefresh:t}){var M;const[n,r]=b.useState(((M=e.overview)==null?void 0:M.recentActivity)||[]),[i,l]=b.useState(!0),[s,o]=b.useState("all"),[u,d]=b.useState(!1),[c,f]=b.useState(null),[h,m]=b.useState(""),[p,x]=b.useState(!1);b.useEffect(()=>{var T;(T=e.overview)!=null&&T.recentActivity?(r(e.overview.recentActivity),l(!1)):S()},[e.overview]);const S=async()=>{var T;try{const k=await Q.get("/snapshot");r(((T=k.overview)==null?void 0:T.recentActivity)||[])}catch{}finally{l(!1)}},y=s==="all"?n:n.filter(T=>{var k,j,I,$,H,L;return s==="tasks"?(k=T.kind)==null?void 0:k.startsWith("task"):s==="agents"?(j=T.kind)==null?void 0:j.startsWith("agent"):s==="bg"?((I=T.kind)==null?void 0:I.includes("bg"))||(($=T.kind)==null?void 0:$.includes("schedule")):s==="artifacts"?(H=T.kind)==null?void 0:H.includes("artifacts"):s==="mods"?(L=T.kind)==null?void 0:L.includes("mod"):!0}),g=e.agents||[],v=e.tasks||[],C=v.filter(T=>T.status==="doing"||T.status==="queued"),z=v.filter(T=>T.status==="done"),N=async()=>{if(!(!h.trim()||p)){x(!0);try{await Q.post("/chat",{message:h.trim(),agent:"odin"}),m(""),await t().catch(()=>{}),await S()}catch{}finally{x(!1)}}},P=async()=>{await t().catch(()=>{}),await S()};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-submit-hero",children:[a.jsx("textarea",{className:"mobile-submit-input",placeholder:"What needs to be done? Describe a task, bug, or refactor for Odin to artifacts…",value:h,onChange:T=>m(T.target.value),rows:2}),a.jsxs("div",{className:"mobile-submit-actions",children:[a.jsx("div",{className:"mobile-submit-chips",children:["Implement feature","Fix bug","Refactor","Investigate","Write tests"].map(T=>a.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>m(k=>k?`${k} ${T}`:T),children:T},T))}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:!h.trim()||p,onClick:N,children:[a.jsx(Rm,{size:14})," Submit to Odin"]})]})]}),a.jsxs("div",{className:"mobile-stats",children:[a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:g.length}),a.jsx("div",{className:"mobile-stat-label",children:"Agents"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:C.length}),a.jsx("div",{className:"mobile-stat-label",children:"Active"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:z.length}),a.jsx("div",{className:"mobile-stat-label",children:"Done"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:e.artifacts.length||0}),a.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),i&&n.length===0&&a.jsx("div",{className:"mobile-loading mobile-loading-inline",children:a.jsx("p",{children:"Loading activity…"})}),a.jsxs("div",{className:"mobile-activity-header",children:[a.jsx("h3",{className:"mobile-section-title",style:{margin:0},children:"Recent Activity"}),a.jsxs("div",{style:{display:"flex",gap:4},children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(T=>!T),"aria-label":u?"Resume":"Pause",children:u?a.jsx(Zl,{size:14}):a.jsx(ex,{size:14})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:P,"aria-label":"Refresh",children:a.jsx(Ot,{size:14})})]})]}),a.jsx("div",{className:"mobile-search-scopes",children:W2.map(T=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${s===T?"active":""}`,onClick:()=>o(T),children:ko[T]},T))}),g.length>0&&a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(Or,{size:14})," Agents"]}),a.jsx("div",{className:"mobile-card-list",children:g.slice(0,6).map(T=>a.jsxs("div",{className:"mobile-agent-card",children:[a.jsx("div",{className:"mobile-agent-dot","data-status":T.status||"idle"}),a.jsxs("div",{className:"mobile-agent-info",children:[a.jsx("span",{className:"mobile-agent-name",children:T.name}),a.jsx("span",{className:"mobile-agent-meta",children:T.status||"idle"})]})]},T.name))})]}),!u&&y.length>0&&a.jsx("section",{className:"mobile-section",children:a.jsx("div",{className:"mobile-card-list",children:y.slice(0,30).map((T,k)=>a.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>f(T),children:[a.jsx("span",{className:"mobile-event-kind","data-kind":T.kind,children:ko[T.kind]||T.kind}),a.jsx("span",{className:"mobile-event-msg",children:q2(T)}),a.jsx("span",{className:"mobile-event-time",children:jr(T.ts)})]},`${T.ts}-${T.kind}-${k}`))})}),!u&&y.length===0&&n.length>0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ma,{size:40}),a.jsx("p",{children:"No matching activity."}),a.jsx("p",{className:"muted",children:"Try a different filter."})]}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:ko[c.kind]||c.kind,children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Kind"}),a.jsx("span",{children:c.kind})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time"}),a.jsx("span",{children:new Date(c.ts).toLocaleString()})]}),Object.entries(c).filter(([T])=>!["ts","kind"].includes(T)).map(([T,k])=>a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:T}),a.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof k=="object"?JSON.stringify(k):String(k)})]},T))]})}),g.length===0&&C.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ma,{size:40}),a.jsx("p",{children:"No activity yet."}),a.jsx("p",{className:"muted",children:"Start a task or chat to see things here."})]})]})}function q2(e){const t=e.kind||"";return t.includes("task")?`Task: ${e.title||e.id||"updated"}`:t.includes("agent")?`Agent: ${e.name||"status changed"}`:t.includes("artifacts")?`Plan: ${e.slug||"changed"}`:t.includes("mod")?`Mod: ${e.name||"changed"}`:t.includes("schedule")?`Schedule: ${e.name||"triggered"}`:JSON.stringify(e).slice(0,80)}function Tn({open:e,onClose:t,title:n,children:r,actions:i}){const l=b.useRef(null),s=b.useRef(null),o=b.useRef(null),u=b.useId(),d=b.useRef(0);return b.useEffect(()=>{if(!e)return;o.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const c='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',f=h=>{var y,g;if(h.key==="Escape"&&t(),h.key!=="Tab")return;const m=Array.from(((y=l.current)==null?void 0:y.querySelectorAll(c))??[]);if(m.length===0){h.preventDefault(),(g=l.current)==null||g.focus();return}const p=m[0],x=m[m.length-1],S=document.activeElement;if(h.shiftKey){(!S||S===p||S===l.current)&&(h.preventDefault(),x==null||x.focus());return}S===x&&(h.preventDefault(),p==null||p.focus())};return window.addEventListener("keydown",f),d.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${d.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var h,m;((h=s.current)==null?void 0:h.focus())??((m=l.current)==null||m.focus())}),()=>{var h;window.removeEventListener("keydown",f),document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,d.current),(h=o.current)==null||h.focus()}},[e,t]),e?a.jsx("div",{className:"mobile-modal-overlay",onClick:c=>{c.target===c.currentTarget&&t()},children:a.jsxs("div",{ref:l,className:"mobile-modal",onClick:c=>c.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Modal","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsxs("div",{className:"mobile-modal-header",children:[n?a.jsx("h2",{id:u,className:"mobile-modal-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:s,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(tr,{size:20})})]}),a.jsx("div",{className:"mobile-modal-content",children:r}),i&&a.jsx("div",{className:"mobile-modal-actions",children:i})]})}):null}const ig=["reasoning","code","design","planning","gitops","analysis"],cf={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function df({snapshot:e,onBack:t,onOpenAgent:n,selectedAgent:r,onRefresh:i}){const[l,s]=b.useState(e.agents||[]),[o,u]=b.useState(!e.agents),[d,c]=b.useState(""),[f,h]=b.useState(""),[m,p]=b.useState(null),[x,S]=b.useState(!1),[y,g]=b.useState(""),[v,C]=b.useState(!1);b.useEffect(()=>{if(r){const j=l.find(I=>I.name===r);j&&p(j)}},[r,l]);const z=async()=>{try{const j=await Q.get("/agents");s(j.agents||[])}catch{}finally{u(!1)}},N=l.filter(j=>{if(d&&j.category!==d)return!1;if(f){const I=f.toLowerCase();if(!j.name.toLowerCase().includes(I)&&!(j.description||"").toLowerCase().includes(I))return!1}return!0}),P=async(j,I)=>{try{await Q.post(`/agents/${encodeURIComponent(j)}/invoke`,{prompt:I}),C(!1),g("")}catch{}},M=async j=>{try{await Q.post(`/agents/${encodeURIComponent(j)}/restart`),await z()}catch{}},T=async j=>{if(confirm(`Delete agent "${j}"?`))try{await Q.del(`/agents/${encodeURIComponent(j)}`),s(I=>I.filter($=>$.name!==j)),p(null),i==null||i()}catch{}},k=async j=>{try{const I=await Q.post("/agents",j);s($=>[...$,I]),S(!1),i==null||i()}catch{}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search agents…",value:f,onChange:j=>h(j.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>z(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>S(!0),"aria-label":"New agent",children:a.jsx(yt,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${d?"":"active"}`,onClick:()=>c(""),children:"All"}),ig.map(j=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${d===j?"active":""}`,onClick:()=>c(j),children:j},j))]}),o?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):N.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Or,{size:40}),a.jsx("p",{children:"No agents found."})]}):a.jsx("div",{className:"mobile-card-list",children:N.map(j=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{p(j),n(j.name)},children:[a.jsx("div",{className:"mobile-agent-dot","data-status":j.status||"idle"}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:j.name}),a.jsx("span",{className:"mobile-list-meta",children:j.model||j.mode||"—"})]}),j.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:cf[j.category]||"var(--text-dim)"},children:j.category}),a.jsx("span",{className:"mobile-list-badge","data-status":j.status||"idle",children:j.status||"idle"})]},j.name))}),m&&a.jsx(_t,{open:!0,onClose:()=>p(null),title:m.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{g(""),C(!0)},children:[a.jsx(Zl,{size:14})," Invoke"]}),(m.isStuck||m.status==="error"||m.status==="working")&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>M(m.name),children:[a.jsx(ix,{size:14})," Restart"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>T(m.name),children:a.jsx($i,{size:14})})]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsxs("div",{className:"mobile-agent-detail-status",children:[a.jsx("span",{className:"mobile-agent-dot","data-status":m.status||"idle"}),a.jsx("span",{className:"mobile-agent-detail-status-text",children:m.status||"idle"}),m.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:cf[m.category]},children:m.category})]}),a.jsx("p",{className:"mobile-agent-detail-desc",children:m.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Model"}),a.jsx("span",{className:"mono",children:m.model||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Mode"}),a.jsx("span",{children:m.mode||"subagent"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Path"}),a.jsx("span",{className:"mono",style:{fontSize:11},children:m.path})]}),m.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{children:m.lastError.message})]}),m.tasksTotal!=null&&m.tasksTotal>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Success rate"}),a.jsxs("span",{children:[Math.round((m.successRate||0)*100),"%"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last modified"}),a.jsx("span",{children:jr(m.mtime)})]})]})]})}),a.jsxs(Tn,{open:v,onClose:()=>C(!1),title:`Invoke ${m==null?void 0:m.name}`,actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!y.trim(),onClick:()=>{m&&P(m.name,y.trim())},children:[a.jsx(Zl,{size:14})," Invoke"]}),children:[a.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",a.jsx("span",{className:"mono",children:(m==null?void 0:m.model)||"—"})]}),a.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:y,onChange:j=>g(j.target.value),autoFocus:!0})]}),a.jsx(Y2,{open:x,onClose:()=>S(!1),onCreate:k})]})}function Y2({open:e,onClose:t,onCreate:n}){const[r,i]=b.useState(""),[l,s]=b.useState(""),[o,u]=b.useState(""),[d,c]=b.useState("subagent"),[f,h]=b.useState("#8b5cf6"),[m,p]=b.useState(""),[x,S]=b.useState(""),[y,g]=b.useState(""),v=C=>{C.preventDefault(),r.trim()&&(n({name:r.trim(),description:l.trim(),model:o,mode:d,color:f,tools:[],tags:x.split(",").map(z=>z.trim()).filter(Boolean),category:m,prompt:y}),i(""),s(""),u(""),c("subagent"),h("#8b5cf6"),p(""),S(""),g(""))};return a.jsx(Tn,{open:e,onClose:t,title:"New Agent",actions:a.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-agent-form",onSubmit:v,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-agent",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:r,onChange:C=>i(C.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"What does this agent do?",value:l,onChange:C=>s(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:o,onChange:C=>u(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Category"}),a.jsxs("select",{className:"mobile-input",value:m,onChange:C=>p(C.target.value),children:[a.jsx("option",{value:"",children:"None"}),ig.map(C=>a.jsx("option",{value:C,children:C},C))]}),a.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:x,onChange:C=>S(C.target.value)})]})})}function K2({sessions:e,opencodeSessions:t,activeSessionId:n,activeOpencodeSessionId:r,activeProject:i,creating:l,onCreateSession:s,onSelectSession:o,onSelectOpencodeSession:u}){const[d,c]=b.useState("all"),[f,h]=b.useState(!1),m=30,p=d==="all"?[...e,...t].sort((g,v)=>Number(v.mtime)-Number(g.mtime)):e,x=f?p:p.slice(0,m),S=t.length,y=g=>{if(g.source==="opencode"){u(g);return}o(g.id)};return a.jsxs("div",{className:"chat-sessions",children:[a.jsxs("div",{className:"chat-sessions-header",children:[a.jsx("span",{className:"chat-sessions-header-title",children:"Sessions"}),a.jsx("span",{className:"chat-sessions-count",children:x.length})]}),S>0&&a.jsxs("div",{className:"chat-sessions-toggle",children:[a.jsx("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="bizar"?"active":""}`,onClick:()=>c("bizar"),children:"Bizar"}),a.jsxs("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="all"?"active":""}`,onClick:()=>c("all"),children:["All (",S," opencode)"]})]}),a.jsxs("button",{type:"button",className:"chat-sessions-new",onClick:s,disabled:l||!i,title:i?"Create new session":"Pick a project first","aria-label":"Create new session",children:[l?a.jsx($m,{size:"sm"}):a.jsx(yt,{size:14}),a.jsx("span",{children:l?"Creating…":"New session"})]}),e.length===0?a.jsx("div",{className:"chat-sessions-empty",children:a.jsx(Cx,{icon:a.jsx(Jl,{size:20}),title:i?"No sessions yet":"No project",message:i?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions.",action:i?a.jsxs(ts,{variant:"primary",size:"sm",onClick:s,loading:l,children:[a.jsx(yt,{size:12})," New session"]}):a.jsxs(ts,{variant:"secondary",size:"sm",onClick:()=>{window.location.hash="#overview"},children:[a.jsx(Nu,{size:12})," Open Overview"]})})}):a.jsx("ul",{className:"chat-sessions-list",children:x.map(g=>{const v=g.source==="opencode",C=v?r===g.id:n===g.id;return a.jsxs("li",{className:`chat-sessions-item ${C?"active":""} ${v?"chat-sessions-item-opencode":""}`,onClick:()=>y(g),title:v?`Open in dashboard: ${g.title||g.id}`:g.id,children:[v&&a.jsx(q1,{size:10,className:"chat-sessions-item-icon"}),a.jsx("span",{className:"chat-sessions-item-id",children:g.title||g.id}),a.jsx("span",{className:"chat-sessions-item-meta",children:new Date(Number(g.mtime)).toLocaleDateString()})]},v?`oc-${g.id}`:g.id)})}),p.length>m&&a.jsx("button",{type:"button",className:"chat-sessions-show-more",onClick:()=>h(g=>!g),children:f?`Show less (${p.length-m} hidden)`:`Show all ${p.length} sessions`})]})}function G2(e){return a.jsx("div",{className:"chat-composer-wrap",children:a.jsx("div",{className:"chat-composer-pill",children:a.jsx(S2,{...e})})})}function X2({sessionId:e,messages:t,pinned:n,agent:r,model:i,agents:l,mcps:s,allCommands:o}){const[u,d]=b.useState(!1),[c,f]=b.useState(!1),h=u?l:l.slice(0,4),m=c?o:o.slice(0,4);return a.jsxs("div",{className:"chat-info",children:[a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(Bn,{size:14})," Session"]}),a.jsxs("dl",{className:"env-table",children:[a.jsx("dt",{children:"id"}),a.jsx("dd",{className:"mono",children:e||"Live"}),a.jsx("dt",{children:"Messages"}),a.jsx("dd",{className:"mono",children:t.length}),a.jsx("dt",{children:"Pinned"}),a.jsx("dd",{className:"mono",children:n.size}),a.jsx("dt",{children:"Agent"}),a.jsx("dd",{className:"mono",children:r||"—"}),a.jsx("dt",{children:"Model"}),a.jsx("dd",{className:"mono ellipsis",title:i,children:i||"—"})]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(Or,{size:14})," Agents",a.jsx("span",{className:"chat-info-card-count",children:l.length})]}),a.jsx("ul",{className:"mod-mini-list",children:h.map(p=>a.jsxs("li",{className:"mod-mini",children:[a.jsxs("span",{className:"mod-mini-name",children:["@",p.name]}),a.jsx("span",{className:"mod-mini-meta",children:p.model||p.mode||""})]},p.name))}),l.length>4&&a.jsx("button",{type:"button",className:"chat-info-card-toggle",onClick:()=>d(p=>!p),children:u?"− Show fewer":`+ ${l.length-4} more`})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(lx,{size:14})," MCPs",a.jsx("span",{className:"chat-info-card-count",children:s.length})]}),a.jsxs("ul",{className:"mod-mini-list",children:[s.length===0?a.jsx("li",{className:"muted",children:"No MCPs configured."}):null,s.map(p=>a.jsxs("li",{className:"mod-mini",children:[a.jsx("span",{className:"mod-mini-name",children:p.id}),a.jsx("span",{className:`mod-mini-pill ${p.enabled?"on":"off"}`,children:p.enabled?"on":"off"})]},p.id))]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("button",{type:"button",className:"chat-info-card-title chat-info-card-title-button",onClick:()=>f(p=>!p),"aria-expanded":c,children:[a.jsx(ax,{size:14})," Slash commands",a.jsx("span",{className:"chat-info-card-count",children:o.length}),a.jsx(Cs,{size:12,className:`chat-info-card-chevron ${c?"open":""}`})]}),c&&a.jsx("ul",{className:"mod-mini-list",children:m.map(p=>a.jsxs("li",{children:[a.jsx("code",{children:p.cmd}),a.jsx("span",{className:"muted",children:p.desc})]},p.cmd))})]})]})}function Z2({snapshot:e,settings:t,setActiveTab:n,initialTaskId:r,onClearTaskId:i}){const l=yx(),s=px(),o=E2(e,t,r??""),[u,d]=b.useState(""),[c,f]=b.useState(t.defaultAgent||"odin"),[h,m]=b.useState(t.defaultModel||""),[p,x]=b.useState([]),[S,y]=b.useState(!1),[g,v]=b.useState(!1),[C,z]=b.useState(!1),N=b.useRef(null),{allCommands:P,suggestions:M,setQuery:T}=z2(e);b.useEffect(()=>{T(u)},[u,T]);const k=()=>{var L;return(L=N.current)==null?void 0:L.click()},j=L=>{const te=L.target.files;if(!te)return;const J=[];for(let D=0;D<te.length;D++)J.push(te[D].name);x(D=>{const V=J.filter(w=>!D.includes(w));return[...D,...V]}),N.current&&(N.current.value="")},I=()=>{const L=u.trim();L&&(d(""),T(""),o.onSend(L,c,h,p))},$=async()=>{if(!S){if(!e.activeProject){l.warning("Pick a project in Overview to scope chat sessions.",4e3);return}y(!0);try{const L=await fetch("/chat/sessions",{method:"POST"}).then(te=>te.json());o.loadChat(L.id),l.success(`Session ${L.id} created.`)}catch(L){l.error(`Create failed: ${L.message}`)}finally{y(!1)}}},H=L=>{s.open({title:"Delete message?",children:a.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(ts,{variant:"secondary",size:"sm",onClick:()=>s.close(),children:"Cancel"}),a.jsx(ts,{variant:"danger",size:"sm",onClick:()=>{s.close(),o.deleteMessage(L)},children:"Delete"})]})})};return a.jsxs("div",{className:"chat-shell",children:[a.jsx(Sx,{activeProject:e.activeProject,sessionCount:o.sessions.length,sessionsOpen:g,infoOpen:C,onToggleSessions:()=>v(L=>!L),onToggleInfo:()=>z(L=>!L),onOpenOverview:()=>n==null?void 0:n("overview")}),a.jsxs("div",{className:"chat-body",children:[a.jsx("aside",{className:`chat-sessions ${g?"":"chat-sessions-hidden"}`,children:a.jsx(K2,{sessions:o.sessions,opencodeSessions:o.opencodeSessions,activeSessionId:o.sessionId,activeOpencodeSessionId:o.activeOpencodeSessionId,activeProject:e.activeProject,onCreateSession:$,onSelectSession:o.selectBizarSession,onSelectOpencodeSession:L=>o.loadOpencodeSession(L.id),creating:S})}),a.jsxs("main",{className:"chat-main",children:[a.jsx(k2,{messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,loading:o.loading,activeProject:e.activeProject,sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,pinned:o.pinned,onPickSuggestion:L=>d(L),onCopy:L=>o.copyMessage(L),onDelete:H,onTogglePin:o.togglePin,onRegenerate:o.onRegenerate}),a.jsx(G2,{agent:c,setAgent:f,model:h,setModel:m,text:u,setText:d,sending:o.sending,onSend:I,attachments:p,setAttachments:x,suggestions:M,onPickSuggestion:L=>d(`${L.split(" ")[0]} `),agents:e.agents||[],onAttach:k,sessionsOpen:g,infoOpen:C}),a.jsx("input",{ref:N,type:"file",multiple:!0,style:{display:"none"},onChange:j})]}),a.jsx("aside",{className:`chat-info ${C?"":"chat-info-hidden"}`,children:a.jsx(X2,{sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,pinned:o.pinned,agent:c,model:h,agents:e.agents||[],mcps:e.mcps||[],allCommands:P})})]})]})}function J2({onBack:e}){const[t,n]=b.useState([]),[r,i]=b.useState(!0),[l,s]=b.useState({}),[o,u]=b.useState(!1),d=async()=>{try{const x=await Q.get("/config"),S=Object.entries(x).map(([y,g])=>({key:y,value:g,type:c(g)}));n(S),s(Object.fromEntries(Object.entries(x).map(([y,g])=>[y,g])))}catch{}finally{i(!1)}};b.useEffect(()=>{d()},[]);const c=x=>typeof x=="boolean"?"boolean":typeof x=="number"?"number":typeof x=="string"?"string":Array.isArray(x)?"array":x&&typeof x=="object"?"object":"unknown",f=(x,S)=>{s(y=>({...y,[x]:S}))},h=async()=>{u(!0);try{await Q.patch("/config",l),await d()}catch{}finally{u(!1)}},m=(x,S)=>{s(y=>({...y,[x]:S}))},p=x=>{const S=l[x.key];switch(x.type){case"boolean":return a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!S,onChange:y=>f(x.key,y.target.checked)}),a.jsx("span",{className:"mobile-toggle-slider"})]});case"number":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"number",inputMode:"numeric",value:String(S??""),onChange:y=>f(x.key,Number(y.target.value))});case"string":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(S??""),onChange:y=>f(x.key,y.target.value)});case"object":case"array":return a.jsx("textarea",{className:"mobile-input mobile-input-sm",rows:2,value:JSON.stringify(S??null,null,2),onChange:y=>{try{f(x.key,JSON.parse(y.target.value))}catch{}}});default:return a.jsx("span",{className:"mobile-setting-value mono",children:String(S??"null")})}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsxs("span",{style:{fontSize:14,color:"var(--text-muted)",flex:1},children:[t.length," config entries"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:()=>h(),children:[a.jsx(Lm,{size:14})," ",o?"Saving…":"Save all"]})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):t.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Mr,{size:40}),a.jsx("p",{children:"No config entries."})]}):a.jsx("div",{className:"mobile-config-list",children:t.map(x=>a.jsxs("div",{className:"mobile-config-row",children:[a.jsxs("div",{className:"mobile-config-key",children:[a.jsx("span",{className:"mono",children:x.key}),a.jsx("span",{className:"mobile-config-type",children:x.type})]}),a.jsx("div",{className:"mobile-config-value",children:p(x)}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(x.key,x.defaultValue),"aria-label":"Reset to default",title:"Reset",children:a.jsx(rx,{size:14})})]},x.key))})]})}function eC({onBack:e}){const[t,n]=b.useState([]),[r,i]=b.useState(!0),[l,s]=b.useState(null),[o,u]=b.useState(""),d=async()=>{try{const m=await Q.get("/history");if(Array.isArray(m.history)){n(m.history);return}if(Array.isArray(m.projects)){const p=new Map;for(const x of m.events||[]){const S=x.projectId;if(!S)continue;const y=p.get(S);(!y||new Date(x.ts).getTime()>new Date(y.ts).getTime())&&p.set(S,x)}n(m.projects.map(x=>{const S=p.get(x.id);return{id:x.id,ts:x.lastAccessed||(S==null?void 0:S.ts)||new Date(0).toISOString(),agent:x.name,taskCount:x.tasks.total,summary:`${x.path} · ${x.tasks.done}/${x.tasks.total} done · ${x.plans} plan${x.plans===1?"":"s"}`,output:S?`${S.kind}${S.text?` — ${S.text}`:""}`:"No recent events."}}));return}n([])}catch{}finally{i(!1)}};b.useEffect(()=>{d()},[]);const c=m=>{if(!m)return"—";const p=Math.floor(m/1e3);if(p<60)return`${p}s`;const x=Math.floor(p/60),S=p%60;return`${x}m ${S}s`},f=m=>new Date(m).toLocaleString(),h=o.trim()?t.filter(m=>{const p=o.toLowerCase();return(m.agent||"session").toLowerCase().includes(p)||(m.summary||"").toLowerCase().includes(p)||(m.output||"").toLowerCase().includes(p)}):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search history…",value:o,onChange:m=>u(m.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):h.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ga,{size:40}),a.jsx("p",{children:t.length===0?"No history yet.":"No matching sessions."})]}):a.jsx("div",{className:"mobile-card-list",children:h.map(m=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>s(m),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(ga,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:m.agent||"Session"}),a.jsxs("span",{className:"mobile-list-meta",children:[f(m.ts),m.duration?` · ${c(m.duration)}`:"",m.taskCount?` · ${m.taskCount} tasks`:""]})]})]},m.id))}),l&&a.jsxs(_t,{open:!0,onClose:()=>s(null),title:"Session Detail",children:[a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Agent"}),a.jsx("span",{children:l.agent||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Started"}),a.jsx("span",{children:f(l.ts)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Duration"}),a.jsx("span",{children:c(l.duration)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tasks"}),a.jsx("span",{children:l.taskCount||0})]})]}),l.summary&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Summary"}),a.jsx("p",{style:{fontSize:13},children:l.summary})]}),l.output&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Output"}),a.jsxs("pre",{className:"mono",style:{fontSize:11,whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--bg-elev-2)",padding:8,borderRadius:6},children:[l.output.slice(0,1e3),l.output.length>1e3?"…":""]})]})]})]})}function tC({snapshot:e,onBack:t}){const[n,r]=b.useState(e.mods||[]),[i,l]=b.useState(!e.mods),[s,o]=b.useState(""),[u,d]=b.useState("all"),[c,f]=b.useState(null),h=async()=>{try{const x=await Q.get("/mods");r(x.mods||[])}catch{}finally{l(!1)}};b.useEffect(()=>{e.mods?(r(e.mods),l(!1)):h()},[e.mods]);const m=async(x,S)=>{try{await Q.patch(`/mods/${encodeURIComponent(x)}`,{enabled:S}),r(y=>y.map(g=>g.id===x?{...g,enabled:S}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:S})}catch{}},p=n.filter(x=>{if(u==="enabled"&&!x.enabled||u==="disabled"&&x.enabled)return!1;if(s){const S=s.toLowerCase();return x.name.toLowerCase().includes(S)||x.description.toLowerCase().includes(S)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search mods…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x.charAt(0).toUpperCase()+x.slice(1)},x))}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Mr,{size:40}),a.jsx("p",{children:"No mods found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Mr,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:["v",x.version," · ",x.author]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsx("div",{className:"mobile-task-detail-actions",children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{c&&m(c.id,!c.enabled)},children:[a.jsx(Mm,{size:14})," ",c.enabled?"Disable":"Enable"]})}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Author"}),a.jsx("span",{children:c.author})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Bizar"}),a.jsx("span",{className:"mono",children:c.bizar})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:c.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Permissions"}),a.jsx("span",{children:c.permissions.length})]}),c.installedAt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Installed"}),a.jsx("span",{children:new Date(c.installedAt).toLocaleDateString()})]})]})]})})]})}function nC({snapshot:e,onNavigate:t}){var s,o,u;const[n,r]=b.useState(""),i=[{id:"artifacts",icon:Gn,label:"Plans",count:e.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:Or,label:"Agents",count:((s=e.agents)==null?void 0:s.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:Mr,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:Mr,label:"Mods",count:((o=e.mods)==null?void 0:o.length)||0,desc:"Installed modifications"},{id:"schedules",icon:pa,label:"Schedules",count:((u=e.schedules)==null?void 0:u.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:ga,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:Dm,label:"Config",count:null,desc:"Key-value configuration editor"}],l=n.trim()?i.filter(d=>d.label.toLowerCase().includes(n.toLowerCase())||d.desc.toLowerCase().includes(n.toLowerCase())):i;return a.jsxs("div",{className:"mobile-view",children:[a.jsx("div",{className:"mobile-tasks-toolbar",children:a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search…",value:n,onChange:d=>r(d.target.value),style:{flex:1}})}),a.jsx("div",{className:"mobile-card-list",children:l.map(d=>{const c=d.icon;return a.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>t(d.id),children:[a.jsx("div",{className:"mobile-more-nav-icon",children:a.jsx(c,{size:20})}),a.jsxs("div",{className:"mobile-more-nav-content",children:[a.jsxs("span",{className:"mobile-more-nav-label",children:[d.label,d.count!=null&&a.jsx("span",{className:"mobile-more-nav-count",children:d.count})]}),a.jsx("span",{className:"mobile-more-nav-desc",children:d.desc})]}),a.jsx(id,{size:16,className:"mobile-more-nav-arrow"})]},d.id)})}),a.jsx("div",{className:"mobile-more-footer",children:a.jsxs("a",{href:"/?desktop=1",className:"mobile-more-link",children:["Switch to Desktop ",a.jsx(id,{size:14})]})})]})}const qu=[{id:"task",label:"Task",color:"var(--info)"},{id:"note",label:"Note",color:"var(--text-dim)"},{id:"decision",label:"Decision",color:"var(--accent)"},{id:"question",label:"Question",color:"var(--warning)"}];function wo(e){var t;return((t=qu.find(n=>n.id===e))==null?void 0:t.color)||"var(--text-dim)"}function rC({type:e,size:t=12}){switch(e){case"task":return a.jsx(es,{size:t,style:{color:"var(--info)"}});case"note":return a.jsx(od,{size:t,style:{color:"var(--text-dim)"}});case"decision":return a.jsx(es,{size:t,style:{color:"var(--accent)"}});case"question":return a.jsx(V1,{size:t,style:{color:"var(--warning)"}});default:return a.jsx(od,{size:t})}}function iC({slug:e,onBack:t}){const[n,r]=b.useState(null),[i,l]=b.useState(null),[s,o]=b.useState(!0),[u,d]=b.useState(!1),[c,f]=b.useState(null),[h,m]=b.useState(!1),[p,x]=b.useState(!1),[S,y]=b.useState(!1),[g,v]=b.useState(""),C=async()=>{o(!0);try{const T=await Q.get(`/plans/${encodeURIComponent(e)}`);r(T.canvas),l(T.meta)}catch{}finally{o(!1)}};b.useEffect(()=>{C()},[e]);const z=async(T,k,j)=>{try{const I=((n==null?void 0:n.elements)||[]).reduce((H,L)=>Math.max(H,L.x||0),40),$=((n==null?void 0:n.elements)||[]).reduce((H,L)=>Math.max(H,L.y||0),40);await Q.post(`/plans/${encodeURIComponent(e)}/elements`,{type:T,title:k,content:j,x:20+I,y:20+$,width:240,height:120}),await C(),x(!1)}catch{}},N=async(T,k)=>{try{await Q.put(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(T)}`,k),await C(),f(null)}catch{}},P=async T=>{if(confirm("Delete this element?"))try{await Q.del(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(T)}`),f(null),await C()}catch{}},M=async(T,k)=>{try{const j=k?`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(k)}/comments`:`/plans/${encodeURIComponent(e)}/comments`;await Q.post(j,{text:T,elementId:k}),await C(),v(""),y(!1)}catch{}};return s||!n||!i?a.jsx("div",{className:"mobile-view",children:a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading canvas…"})})}):a.jsxs("div",{className:"mobile-view mobile-view-canvas",children:[a.jsxs("div",{className:"mobile-canvas-bar",children:[a.jsxs("div",{className:"mobile-canvas-meta",children:[a.jsx("span",{className:"mobile-canvas-title",children:i.title||e}),a.jsx("span",{className:"mobile-canvas-status","data-status":i.status,children:i.status})]}),a.jsxs("div",{className:"mobile-canvas-actions",children:[a.jsx("button",{type:"button",className:`mobile-icon-btn ${u?"active":""}`,onClick:()=>d(T=>!T),"aria-label":u?"Done editing":"Edit",children:a.jsx(Am,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(T=>!T),"aria-label":"Comments",children:[a.jsx(Bn,{size:16}),n.comments.length>0&&a.jsx("span",{className:"mobile-canvas-comment-count",children:n.comments.length})]}),u&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(!0),"aria-label":"Add element",children:a.jsx(yt,{size:16})})]})]}),a.jsxs("div",{className:"mobile-canvas-elements",children:[n.elements.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx("p",{children:"No elements yet."}),u&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>x(!0),children:[a.jsx(yt,{size:14})," Add Element"]})]}),n.elements.map(T=>a.jsxs("button",{type:"button",className:`mobile-canvas-element ${(c==null?void 0:c.id)===T.id?"selected":""}`,style:{borderColor:wo(T.type)},onClick:()=>{u&&f(T)},"aria-pressed":(c==null?void 0:c.id)===T.id,children:[a.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${wo(T.type)}18`},children:[a.jsx(rC,{type:T.type,size:12}),a.jsx("span",{className:"mobile-canvas-el-type",style:{color:wo(T.type)},children:T.type}),T.status&&T.status!=="open"&&a.jsx("span",{className:"mobile-canvas-el-status",children:T.status})]}),a.jsx("div",{className:"mobile-canvas-el-title",children:T.title||"Untitled"}),T.content&&a.jsxs("div",{className:"mobile-canvas-el-content",children:[T.content.slice(0,120),T.content.length>120?"…":""]}),a.jsxs("div",{className:"mobile-canvas-el-comments",children:[a.jsx(Bn,{size:10}),n.comments.filter(k=>k.elementId===T.id).length]})]},T.id))]}),h&&a.jsxs("div",{className:"mobile-canvas-comments",children:[a.jsxs("div",{className:"mobile-canvas-comments-header",children:[a.jsxs("h4",{children:["Comments (",n.comments.length,")"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(!1),children:a.jsx(tr,{size:16})})]}),a.jsxs("div",{className:"mobile-canvas-comment-list",children:[n.comments.length===0&&a.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),n.comments.map(T=>a.jsxs("div",{className:"mobile-canvas-comment",children:[a.jsxs("div",{className:"mobile-canvas-comment-head",children:[a.jsx("span",{className:"mono",children:T.author}),a.jsx("span",{className:"muted",children:jr(T.created)})]}),a.jsx("div",{className:"mobile-canvas-comment-text",children:T.text})]},T.id))]}),a.jsxs("div",{className:"mobile-canvas-comment-input",children:[a.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:g,onChange:T=>v(T.target.value)}),a.jsx("button",{type:"button",className:"mobile-btn",disabled:!g.trim(),onClick:()=>{M(g.trim(),null)},children:"Post"})]})]}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:`Edit ${c.title||c.type}`,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>P(c.id),children:[a.jsx($i,{size:14})," Delete"]}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>y(!0),children:[a.jsx(Bn,{size:14})," Comment"]})]}),children:a.jsx(lC,{element:c,onSave:T=>N(c.id,T),onClose:()=>f(null)})}),a.jsx(sC,{open:p,onClose:()=>x(!1),onAdd:z}),a.jsx(Tn,{open:S,onClose:()=>y(!1),title:"Add Comment",actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!g.trim(),onClick:()=>{M(g.trim(),(c==null?void 0:c.id)||null),y(!1)},children:[a.jsx(Bn,{size:14})," Post"]}),children:a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:g,onChange:T=>v(T.target.value),autoFocus:!0})})]})}function lC({element:e,onSave:t,onClose:n}){const[r,i]=b.useState(e.type),[l,s]=b.useState(e.title||""),[o,u]=b.useState(e.content||""),[d,c]=b.useState(e.status||"open");return a.jsxs("form",{className:"mobile-task-form",onSubmit:f=>{f.preventDefault(),t({type:r,title:l,content:o,status:d}),n()},children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:f=>i(f.target.value),children:qu.map(f=>a.jsx("option",{value:f.id,children:f.label},f.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title"}),a.jsx("input",{className:"mobile-input",type:"text",value:l,onChange:f=>s(f.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Status"}),a.jsx("input",{className:"mobile-input",type:"text",value:d,onChange:f=>c(f.target.value),placeholder:"open / done / blocked"}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:4,value:o,onChange:f=>u(f.target.value)}),a.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function sC({open:e,onClose:t,onAdd:n}){const[r,i]=b.useState("task"),[l,s]=b.useState(""),[o,u]=b.useState(""),d=c=>{c.preventDefault(),l.trim()&&(n(r,l.trim(),o.trim()),s(""),u(""))};return a.jsx(Tn,{open:e,onClose:t,title:"Add Element",actions:a.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Add"]}),children:a.jsxs("form",{id:"add-el-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:c=>i(c.target.value),children:qu.map(c=>a.jsx("option",{value:c.id,children:c.label},c.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:l,onChange:c=>s(c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Description…",value:o,onChange:c=>u(c.target.value)})]})})}function oC({snapshot:e,onBack:t,onOpenArtifact:n}){const[r,i]=b.useState(e.artifacts||[]),[l,s]=b.useState(!e.artifacts),[o,u]=b.useState(""),[d,c]=b.useState(!1),[f,h]=b.useState(""),[m,p]=b.useState(""),x=async()=>{try{const g=await Q.get("/artifacts");i(g.artifacts||[])}catch{}finally{s(!1)}},S=async()=>{if(f.trim())try{const g=await Q.post("/artifacts",{slug:f.trim(),title:m.trim()||void 0});c(!1),h(""),p(""),n(g.slug)}catch{}},y=o.trim()?r.filter(g=>(g.title||g.slug||"").toLowerCase().includes(o.toLowerCase())):r;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search artifacts…",value:o,onChange:g=>u(g.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsx("div",{style:{marginBottom:12},children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>c(!0),children:[a.jsx(yt,{size:14})," New Artifact"]})}),l?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):y.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Gn,{size:40}),a.jsx("p",{children:"No artifacts yet."})]}):a.jsx("div",{className:"mobile-card-list",children:y.map(g=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>n(g.slug),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Gn,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:g.title||g.slug}),a.jsxs("span",{className:"mobile-list-meta",children:[g.status," · ",g.source,g.elementCount!=null?` · ${g.elementCount} elements`:"",g.commentCount!=null?` · ${g.commentCount} comments`:""]})]}),a.jsx("span",{className:"mobile-list-badge","data-status":g.status,children:g.status})]},g.slug))}),a.jsx(Tn,{open:d,onClose:()=>c(!1),title:"New Artifact",actions:a.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-plan-form",onSubmit:g=>{g.preventDefault(),S()},className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Slug *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-plan",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:f,onChange:g=>h(g.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Title (optional)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"My Artifact",value:m,onChange:g=>p(g.target.value)})]})})]})}const aC=["cron","interval","once"],uC=["command","agent","webhook"],ff=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],lg=Array.from({length:24},(e,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),cC=Array.from({length:12},(e,t)=>t*5),sg=[{value:"*",label:"Every day"},{value:"0",label:"Sun"},{value:"1",label:"Mon"},{value:"2",label:"Tue"},{value:"3",label:"Wed"},{value:"4",label:"Thu"},{value:"5",label:"Fri"},{value:"6",label:"Sat"}],dC=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function fC({snapshot:e}){var S;const[t,n]=b.useState(e.schedules||[]),[r,i]=b.useState(!e.schedules),[l,s]=b.useState(""),[o,u]=b.useState(null),[d,c]=b.useState({open:!1}),f=async()=>{try{const y=await Q.get("/schedules");n(y.schedules||[])}catch{}finally{i(!1)}};b.useEffect(()=>{e.schedules?(n(e.schedules),i(!1)):f()},[e.schedules]);const h=async(y,g)=>{try{await Q.patch(`/schedules/${encodeURIComponent(y)}`,{enabled:g}),n(v=>v.map(C=>C.id===y?{...C,enabled:g}:C)),(o==null?void 0:o.id)===y&&u(v=>v&&{...v,enabled:g})}catch{}},m=async y=>{if(confirm("Delete this schedule?"))try{await Q.del(`/schedules/${encodeURIComponent(y)}`),n(g=>g.filter(v=>v.id!==y)),(o==null?void 0:o.id)===y&&u(null)}catch{}},p=async y=>{try{await Q.post(`/schedules/${encodeURIComponent(y)}/trigger`)}catch{}},x=l.trim()?t.filter(y=>y.name.toLowerCase().includes(l.toLowerCase())):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search schedules…",value:l,onChange:y=>s(y.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>f(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>c({open:!0}),"aria-label":"New schedule",children:a.jsx(yt,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):x.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(pa,{size:40}),a.jsx("p",{children:"No schedules found."})]}):a.jsx("div",{className:"mobile-card-list",children:x.map(y=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>u(y),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(pa,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:y.name}),a.jsxs("span",{className:"mobile-list-meta",children:[pf(y)," ·"," ",y.nextRun?`next ${mf(y.nextRun,y.timezone)}`:"no next run"]})]}),a.jsx("span",{className:`mobile-list-badge ${y.enabled?"badge-on":"badge-off"}`,children:y.enabled?"on":"off"})]},y.id))}),o&&a.jsx(_t,{open:!0,onClose:()=>u(null),title:o.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&p(o.id)},children:[a.jsx(Zl,{size:14})," Trigger now"]}),a.jsx("button",{type:"button",className:`mobile-btn ${o.enabled?"mobile-btn-secondary":""}`,onClick:()=>{o&&h(o.id,!o.enabled)},children:o.enabled?"Disable":"Enable"}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&(c({open:!0,initial:o}),u(null))},children:[a.jsx(Am,{size:14})," Edit"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{o&&m(o.id)},children:a.jsx($i,{size:14})})]}),children:a.jsx("div",{className:"mobile-agent-detail",children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:o.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Schedule"}),a.jsx("span",{className:"mono",children:pf(o)||o.schedule})]}),o.timezone&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Timezone"}),a.jsx("span",{className:"mono",children:o.timezone})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Action"}),a.jsxs("span",{children:[o.action.type,": ",o.action.target]})]}),o.action.type==="agent"&&o.action.prompt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Prompt"}),a.jsx("span",{style:{fontSize:12},children:o.action.prompt})]}),((S=o.budgetCheck)==null?void 0:S.skipIfBudgetLow)&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Budget gate"}),a.jsxs("span",{children:["skip if ≥ ",o.budgetCheck.maxConcurrent??6," concurrent"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Next run"}),a.jsx("span",{children:o.nextRun?mf(o.nextRun,o.timezone):"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last run"}),a.jsx("span",{children:o.lastRun?pC(o.lastRun):"—"})]}),o.lastResult&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last result"}),a.jsx("span",{style:{fontSize:12},children:o.lastResult})]}),o.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{style:{fontSize:12},children:o.lastError})]})]})})}),a.jsx(mC,{open:d.open,initial:d.initial,onClose:()=>c({open:!1}),onSaved:()=>{c({open:!1}),f()}})]})}function hf(e){var r,i;if(!e)return{name:"",type:"cron",cronMinute:0,cronHour:13,cronDow:"0",intervalN:30,intervalUnit:"m",onceAt:"",timezone:"UTC",actionType:"agent",actionTarget:"",actionPrompt:"",skipIfBudgetLow:!1,maxConcurrent:6,enabled:!0};const t=e.type==="cron"?og(e.schedule):null,n=e.type==="interval"?gC(e.schedule):null;return{name:e.name||"",type:e.type,cronMinute:(t==null?void 0:t.minute)??0,cronHour:(t==null?void 0:t.hour)??9,cronDow:(t==null?void 0:t.dow)??"*",intervalN:(n==null?void 0:n.n)??30,intervalUnit:(n==null?void 0:n.unit)??"m",onceAt:e.type==="once"?yC(e.schedule):"",timezone:e.timezone||"UTC",actionType:e.action.type,actionTarget:e.action.target||"",actionPrompt:e.action.prompt||"",skipIfBudgetLow:!!((r=e.budgetCheck)!=null&&r.skipIfBudgetLow),maxConcurrent:Number.isFinite((i=e.budgetCheck)==null?void 0:i.maxConcurrent)?e.budgetCheck.maxConcurrent:6,enabled:e.enabled!==!1}}function hC(e){if(e.type==="cron")return`${e.cronMinute} ${e.cronHour} * * ${e.cronDow}`;if(e.type==="interval")return`${e.intervalN}${e.intervalUnit}`;if(!e.onceAt)return"";try{return new Date(e.onceAt).toISOString()}catch{return e.onceAt}}function mC({open:e,initial:t,onClose:n,onSaved:r}){const[i,l]=b.useState(()=>hf(t)),[s,o]=b.useState(!1);b.useEffect(()=>{e&&l(hf(t))},[e,t]);const u=(c,f)=>{l(h=>({...h,[c]:f}))},d=async c=>{if(c.preventDefault(),!i.name.trim())return;const f=hC(i);if(f){o(!0);try{const h={name:i.name.trim(),type:i.type,schedule:f,timezone:i.timezone,action:{type:i.actionType,target:i.actionTarget.trim(),...i.actionType==="agent"&&i.actionPrompt.trim()?{prompt:i.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:i.maxConcurrent,skipIfBudgetLow:i.skipIfBudgetLow},enabled:i.enabled};t?await Q.put(`/schedules/${encodeURIComponent(t.id)}`,h):await Q.post("/schedules",h),r()}catch{}finally{o(!1)}}};return a.jsx(Tn,{open:e,onClose:n,title:t?`Edit ${t.name}`:"New schedule",actions:a.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:s,children:[a.jsx(yt,{size:14})," ",t?"Save":"Create"]}),children:a.jsxs("form",{id:"mobile-schedule-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Weekly review",value:i.name,onChange:c=>u("name",c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:i.type,onChange:c=>u("type",c.target.value),children:aC.map(c=>a.jsx("option",{value:c,children:c},c))}),i.type==="cron"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Day of week"}),a.jsx("select",{className:"mobile-input",value:i.cronDow,onChange:c=>u("cronDow",c.target.value),children:sg.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))}),a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Hour"}),a.jsx("select",{className:"mobile-input",value:String(i.cronHour),onChange:c=>u("cronHour",parseInt(c.target.value,10)),children:lg.map(c=>a.jsx("option",{value:String(c.value),children:c.label},c.value))})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Minute"}),a.jsx("select",{className:"mobile-input",value:String(i.cronMinute),onChange:c=>u("cronMinute",parseInt(c.target.value,10)),children:cC.map(c=>a.jsx("option",{value:String(c),children:String(c).padStart(2,"0")},c))})]})]})]}),i.type==="interval"&&a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Every"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,value:i.intervalN,onChange:c=>u("intervalN",parseInt(c.target.value,10)||1)})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Unit"}),a.jsx("select",{className:"mobile-input",value:i.intervalUnit,onChange:c=>u("intervalUnit",c.target.value),children:dC.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),i.type==="once"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Run at"}),a.jsx("input",{className:"mobile-input",type:"datetime-local",value:i.onceAt,onChange:c=>u("onceAt",c.target.value)})]}),a.jsx("label",{className:"mobile-field-label",children:"Timezone"}),a.jsx("select",{className:"mobile-input",value:ff.includes(i.timezone)?i.timezone:"UTC",onChange:c=>u("timezone",c.target.value),children:ff.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Action type"}),a.jsx("select",{className:"mobile-input",value:i.actionType,onChange:c=>u("actionType",c.target.value),children:uC.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Target"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:i.actionType==="webhook"?"https://...":i.actionType==="agent"?"agent or task ref":"echo hello",value:i.actionTarget,onChange:c=>u("actionTarget",c.target.value)}),i.actionType==="agent"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Prompt"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"What should the agent do?",value:i.actionPrompt,onChange:c=>u("actionPrompt",c.target.value)})]}),a.jsxs("fieldset",{className:"mobile-budget-card",children:[a.jsx("legend",{children:"Budget pre-flight"}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.skipIfBudgetLow,onChange:c=>u("skipIfBudgetLow",c.target.checked)}),a.jsx("span",{children:"Skip if too many bg tasks are running"})]}),a.jsx("label",{className:"mobile-field-label",children:"Cap"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,max:64,value:i.maxConcurrent,onChange:c=>u("maxConcurrent",parseInt(c.target.value,10)||6),disabled:!i.skipIfBudgetLow})]}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.enabled,onChange:c=>u("enabled",c.target.checked)}),a.jsx("span",{children:"Enabled"})]})]})})}function pC(e){const t=Date.now()-new Date(e).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(e).toLocaleDateString()}function mf(e,t){try{return new Date(e).toLocaleString(void 0,{timeZone:t||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(e).toLocaleString()}}function og(e){if(typeof e!="string")return null;const t=e.trim().split(/\s+/);if(t.length!==5)return null;const[n,r,,,i]=t,l=parseInt(n,10),s=parseInt(r,10);return!Number.isFinite(l)||!Number.isFinite(s)||n!==String(l)||r!==String(s)?null:{minute:l,hour:s,dow:i==="*"?"*":Number.isFinite(parseInt(i,10))?i:"*"}}function gC(e){if(typeof e!="string")return null;const t=/^(\d+)([smhd])$/i.exec(e.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function yC(e){if(!e)return"";try{const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}catch{return""}}function pf(e){var l,s;if(e.type!=="cron")return e.schedule;const t=og(e.schedule);if(!t)return e.schedule;const n=((l=sg.find(o=>o.value===t.dow))==null?void 0:l.label)||t.dow,r=((s=lg.find(o=>o.value===t.hour))==null?void 0:s.label)||`${t.hour}`,i=String(t.minute).padStart(2,"0");return n==="Every day"?`Every day ${r} :${i}`:`Every ${n} ${r} :${i}`}const xC=["all","tasks","agents","artifacts","projects","settings"],vC={tasks:es,agents:Or,plans:Gn,projects:Nu,settings:Mr};function kC({open:e,onClose:t,onNavigate:n}){const[r,i]=b.useState(""),[l,s]=b.useState("all"),[o,u]=b.useState([]),[d,c]=b.useState(!1),f=b.useRef(null);b.useEffect(()=>{e&&(i(""),u([]),requestAnimationFrame(()=>{var p;return(p=f.current)==null?void 0:p.focus()}))},[e]),b.useEffect(()=>{if(!r.trim()){u([]);return}const p=setTimeout(async()=>{c(!0);try{const x=await Q.get(`/search?q=${encodeURIComponent(r)}&scope=${l}`);u(x.results||[])}catch{u([])}finally{c(!1)}},250);return()=>clearTimeout(p)},[r,l]);const h=p=>{const x=p.item,S=x.id||x.slug||x.name||"";n(p.type,S),t()},m=o.reduce((p,x)=>(p[x.type]||(p[x.type]=[]),p[x.type].push(x),p),{});return a.jsx(Tn,{open:e,onClose:t,title:"Search",children:a.jsxs("div",{className:"mobile-search-container",children:[a.jsxs("div",{className:"mobile-search-input-row",children:[a.jsx(sd,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),a.jsx("input",{ref:f,className:"mobile-search-field",type:"text",placeholder:"Search…",value:r,onChange:p=>i(p.target.value),enterKeyHint:"search",onKeyDown:p=>{p.key==="Escape"&&t(),p.key==="Enter"&&o.length>0&&h(o[0])}}),r&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>i(""),"aria-label":"Clear",children:a.jsx(tr,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:xC.map(p=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${l===p?"active":""}`,onClick:()=>s(p),children:p==="all"?"All":p.charAt(0).toUpperCase()+p.slice(1)},p))}),a.jsxs("div",{className:"mobile-search-results",children:[d&&a.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!d&&r&&o.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(sd,{size:32}),a.jsx("p",{children:"No results found"})]}),!d&&!r&&a.jsx("div",{className:"mobile-empty",children:a.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(m).map(([p,x])=>{const S=vC[p]||Gn;return a.jsxs("div",{className:"mobile-search-group",children:[a.jsxs("h4",{className:"mobile-search-group-title",children:[a.jsx(S,{size:12})," ",p.charAt(0).toUpperCase()+p.slice(1)," (",x.length,")"]}),x.map((y,g)=>{const v=y.item;return a.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>h(y),children:[a.jsx("span",{className:"mobile-search-result-title",children:v.title||v.name||v.slug||"(unnamed)"}),v.description&&a.jsx("span",{className:"mobile-search-result-meta",children:v.description.slice(0,80)})]},g)})]},p)})]})]})})}const wC=[{id:"dark",label:"Dark",Icon:J1},{id:"light",label:"Light",Icon:ox},{id:"system",label:"System",Icon:Z1}],bC=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}];function SC(e){if(e<=0)return"expired";const t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,"0")}`}function CC({settings:e,snapshot:t,onRefresh:n}){var z,N,P,M,T,k;const[r,i]=b.useState(e),[l,s]=b.useState(!1),[o,u]=b.useState(!1),[d,c]=b.useState(null),[f,h]=b.useState(!1),[m,p]=b.useState(Date.now());b.useEffect(()=>{i(e),s(!1),e.theme&&fi(e.theme)},[e]),b.useEffect(()=>{if(!d)return;const j=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(j)},[d]);const x=j=>{i(I=>{const $={...I,theme:{...I.theme,...j}};return ns($.theme),fi($.theme),$}),s(!0)},S=(j,I)=>{i($=>({...$,[j]:I})),s(!0)},y=async()=>{u(!0);try{const j=await Q.put("/settings",r);i(j.data),s(!1),ns(j.data.theme),fi(j.data.theme),n()}catch{}finally{u(!1)}},g=async()=>{h(!0);try{const j=await Q.post("/pair/start");c(j)}catch{}finally{h(!1)}},v=d?d.expiresAt-m:0,C=d!=null&&v<=0;return a.jsxs("div",{className:"mobile-view",children:[l&&a.jsxs("div",{className:"mobile-settings-save-bar",children:[a.jsx("span",{children:"Unsaved changes"}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:y,children:[a.jsx(Lm,{size:14})," ",o?"Saving…":"Save"]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Appearance"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Theme"}),a.jsx("div",{className:"mobile-theme-btns",children:wC.map(({id:j,label:I,Icon:$})=>a.jsxs("button",{type:"button",className:`mobile-theme-btn ${r.theme.mode===j?"active":""}`,onClick:()=>x({mode:j}),children:[a.jsx($,{size:14})," ",I]},j))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Accent color"}),a.jsx("div",{className:"mobile-accent-swatches",children:bC.map(j=>a.jsx("button",{type:"button",className:`mobile-accent-swatch ${r.theme.accent===j.accent?"active":""}`,style:{background:j.accent},onClick:()=>x({accent:j.accent}),title:j.name},j.name))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsxs("span",{className:"mobile-setting-label",children:["Font size: ",r.theme.fontSize,"px"]}),a.jsx("input",{type:"range",min:12,max:20,value:r.theme.fontSize,onChange:j=>x({fontSize:Number(j.target.value)}),style:{width:"100%"}})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Compact mode"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.compactMode,onChange:j=>x({compactMode:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Animations"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.animations,onChange:j=>x({animations:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Chat Defaults"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Default Agent"}),a.jsx("select",{className:"mobile-input",value:r.defaultAgent||"odin",onChange:j=>S("defaultAgent",j.target.value),children:((t==null?void 0:t.agents)||[]).map(j=>a.jsxs("option",{value:j.name,children:["@",j.name]},j.name))}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Default Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(auto)",value:r.defaultModel||"",onChange:j=>S("defaultModel",j.target.value)})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Notifications"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agent completion"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onAgentComplete,onChange:j=>{i(I=>({...I,notifications:{...I.notifications,onAgentComplete:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plan approval"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onPlanApproval,onChange:j=>{i(I=>({...I,notifications:{...I.notifications,onPlanApproval:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Agent Behavior"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Max parallel agents"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:1,max:20,value:((z=r.agents)==null?void 0:z.maxParallel)??6,onChange:j=>{i(I=>({...I,agents:{...I.agents,maxParallel:Math.max(1,Math.min(20,parseInt(j.target.value,10)||6))}})),s(!0)}}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Stuck threshold (ms)"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:6e4,max:36e5,step:6e4,value:((N=r.agents)==null?void 0:N.stuckThresholdMs)??6e5,onChange:j=>{i(I=>({...I,agents:{...I.agents,stuckThresholdMs:Math.max(6e4,parseInt(j.target.value,10)||6e5)}})),s(!0)}}),a.jsxs("div",{className:"mobile-setting-row",style:{marginTop:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Auto-restart stuck agents"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!((P=r.agents)!=null&&P.autoRestart),onChange:j=>{i(I=>({...I,agents:{...I.agents,autoRestart:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Tailscale Serve"}),a.jsx("div",{className:"mobile-card",children:a.jsxs("p",{className:"muted",style:{fontSize:13},children:["Use ",a.jsx("code",{children:"bizar service"})," commands in the terminal to configure Tailscale serve."]})})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(sx,{size:14})," Companion App"]}),a.jsxs("div",{className:"mobile-card",children:[!d&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,disabled:f,style:{width:"100%"},children:[a.jsx(nx,{size:14})," ",f?"Generating…":"Generate QR Code"]}),d&&!C&&a.jsxs("div",{style:{textAlign:"center"},children:[a.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12,display:"inline-block"},children:a.jsx(rg,{value:d.qrPayload,size:180,level:"M"})}),a.jsxs("div",{style:{marginTop:8,fontSize:12},children:["Expires in ",a.jsx("strong",{children:SC(v)})]}),a.jsx("div",{className:"mono",style:{fontSize:10,wordBreak:"break-all",marginTop:4},children:d.publicUrl})]}),d&&C&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,style:{width:"100%"},children:[a.jsx(Ot,{size:14})," Generate new QR"]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"About"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Version"}),a.jsx("span",{className:"mobile-setting-value mono",children:((M=r.about)==null?void 0:M.version)||"—"})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agents"}),a.jsx("span",{className:"mobile-setting-value",children:((T=t==null?void 0:t.agents)==null?void 0:T.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Tasks"}),a.jsx("span",{className:"mobile-setting-value",children:((k=t==null?void 0:t.tasks)==null?void 0:k.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plans"}),a.jsx("span",{className:"mobile-setting-value",children:(t==null?void 0:t.artifacts.length)||0})]})]})]}),a.jsx("div",{className:"mobile-view-footer",children:a.jsx("a",{href:"/?desktop=1",className:"mobile-btn mobile-btn-secondary",children:"Switch to Desktop"})})]})}const jC=["languages","framework","design","testing","devops","data","security","integration"];function NC({snapshot:e,onBack:t}){const[n,r]=b.useState([]),[i,l]=b.useState(!0),[s,o]=b.useState(""),[u,d]=b.useState(""),[c,f]=b.useState(null),h=async()=>{try{const x=await Q.get("/skills");r(x.skills||[])}catch{}finally{l(!1)}};b.useEffect(()=>{h()},[]);const m=async(x,S)=>{try{await Q.patch(`/skills/${encodeURIComponent(x)}`,{enabled:S}),r(y=>y.map(g=>g.id===x?{...g,enabled:S}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:S})}catch{}},p=n.filter(x=>{if(u&&x.category!==u)return!1;if(s){const S=s.toLowerCase();return x.name.toLowerCase().includes(S)||x.description.toLowerCase().includes(S)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search skills…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${u?"":"active"}`,onClick:()=>d(""),children:"All"}),jC.map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x},x))]}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Jl,{size:40}),a.jsx("p",{children:"No skills found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Jl,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:[x.category," · v",x.version]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsxs("button",{type:"button",className:`mobile-btn ${c.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{c&&m(c.id,!c.enabled)},children:[a.jsx(Mm,{size:14})," ",c.enabled?"Disable":"Enable"]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Category"}),a.jsx("span",{children:c.category})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Source"}),a.jsx("span",{children:c.source})]}),c.tags.length>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tags"}),a.jsx("span",{children:c.tags.join(", ")})]})]})]})})]})}const EC=["queued","doing","blocked","done"],dl={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},gf={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function TC(e){const t=e.metadata??{};return!!(t.sessionId||t.bgInstanceId)}function zC(e){var n;const t=e.metadata??{};return!!((n=t.artifactIds)!=null&&n.length||t.artifactId)}function yf({snapshot:e,onRefresh:t,selectedTaskId:n,onCloseDetail:r,onOpenChat:i,onOpenArtifact:l}){var fe,Ye;const[s,o]=b.useState(e.tasks||[]),[u,d]=b.useState(!e.tasks),[c,f]=b.useState(""),[h,m]=b.useState("queued"),[p,x]=b.useState(null),[S,y]=b.useState(!1),[g,v]=b.useState(null),[C,z]=b.useState([]),[N,P]=b.useState(""),[M,T]=b.useState(null),[k,j]=b.useState(!1),[I,$]=b.useState(""),[H,L]=b.useState("updated");b.useEffect(()=>{var B;if(e.tasks&&(o(e.tasks),d(!1)),n){const ie=(B=e.tasks)==null?void 0:B.find(re=>re.id===n);ie&&x(ie)}},[e.tasks,n]),b.useEffect(()=>{if(n){const B=s.find(ie=>ie.id===n);B&&x(B)}},[n,s]);const te=async()=>{try{const B=await Q.get("/tasks");o(Array.isArray(B)?B:[])}catch{}finally{d(!1)}},J=async(B,ie)=>{o(re=>re.map(be=>be.id===B?{...be,status:ie}:be)),(p==null?void 0:p.id)===B&&x(re=>re&&{...re,status:ie});try{await Q.patch(`/tasks/${encodeURIComponent(B)}/status`,{status:ie})}catch{await te()}},D=async B=>{if(confirm("Delete this task?"))try{await Q.del(`/tasks/${encodeURIComponent(B)}`),o(ie=>ie.filter(re=>re.id!==B)),(p==null?void 0:p.id)===B&&x(null)}catch{await te()}},V=async B=>{try{await Q.post(`/tasks/${encodeURIComponent(B)}/archive`),o(ie=>ie.filter(re=>re.id!==B)),(p==null?void 0:p.id)===B&&x(null)}catch{}},ne=[...s.filter(B=>{var ie,re;if(c.trim()){const be=c.toLowerCase();if(!(B.title||"").toLowerCase().includes(be)&&!(B.description||"").toLowerCase().includes(be))return!1}if(I.trim()){const be=I==="mine"?((re=(ie=e.settings)==null?void 0:ie.data)==null?void 0:re.defaultAgent)||IC(e):I.replace(/^@/,"");if((B.assignee||"").toLowerCase()!==be.toLowerCase())return!1}return!0})].sort((B,ie)=>{switch(H){case"priority":{const re={high:0,normal:1,low:2};return(re[B.priority]??1)-(re[ie.priority]??1)}case"created":return new Date(ie.createdAt).getTime()-new Date(B.createdAt).getTime();case"updated":default:return new Date(ie.updatedAt).getTime()-new Date(B.updatedAt).getTime()}}),ae=ne.filter(B=>B.status===h),E=e.agents||[],ye=async(B,ie,re,be)=>{try{const zn=await Q.post("/tasks",{title:B,description:ie,assignee:re||null,priority:be});o(In=>[zn,...In]),y(!1)}catch{}},qe=async B=>{j(!0),P(""),T(null),v(B);try{const re=((await Q.get(`/tasks/${encodeURIComponent(B)}/artifacts`)).artifacts||[]).map(be=>be.id);if(z(re),re.length>0){const[be,zn]=await Promise.all([Q.get(`/artifacts/${encodeURIComponent(re[0])}`),fetch(Q.urlWithToken(`/artifacts/${encodeURIComponent(re[0])}/content`)).then(In=>In.text())]);T(be),P(zn)}}catch{}finally{j(!1)}};return u?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):a.jsxs("div",{className:"mobile-view mobile-view-tasks",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search tasks…",value:c,onChange:B=>f(B.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>te(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsxs("div",{className:"mobile-tasks-filters",children:[a.jsxs("select",{className:"mobile-filter-select",value:I,onChange:B=>$(B.target.value),children:[a.jsx("option",{value:"",children:"All"}),a.jsx("option",{value:"mine",children:"Mine"}),E.map(B=>a.jsxs("option",{value:`@${B.name}`,children:["@",B.name]},B.name))]}),a.jsxs("select",{className:"mobile-filter-select",value:H,onChange:B=>L(B.target.value),children:[a.jsx("option",{value:"updated",children:"Updated"}),a.jsx("option",{value:"created",children:"Created"}),a.jsx("option",{value:"priority",children:"Priority"})]})]}),a.jsx("div",{className:"mobile-kanban-tabs",children:EC.map(B=>{const ie=ne.filter(re=>re.status===B).length;return a.jsxs("button",{type:"button",className:`mobile-kanban-tab ${h===B?"active":""}`,onClick:()=>m(B),children:[dl[B]," (",ie,")"]},B)})}),a.jsxs("div",{className:"mobile-card-list",children:[ae.length===0&&a.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[a.jsxs("p",{children:["No ",dl[h].toLowerCase()," tasks."]}),a.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),ae.map(B=>{var ie;return a.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>x(B),children:[a.jsx("div",{className:"priority-dot",style:{background:dx[B.priority]||"var(--info)"}}),a.jsxs("div",{className:"task-content",children:[a.jsx("div",{className:"task-title",children:B.title}),a.jsxs("div",{className:"task-meta",children:[B.assignee?`@${B.assignee}`:"unassigned"," · ",jr(B.updatedAt||B.createdAt),(ie=B.dependencies)!=null&&ie.length?` · ${B.dependencies.length} deps`:""]})]})]},B.id)})]}),a.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>y(!0),"aria-label":"Add task",children:a.jsx(yt,{size:24})}),a.jsx(_t,{open:!!p,onClose:()=>{x(null),r==null||r()},title:"Task Detail",actions:p&&a.jsxs("div",{className:"mobile-task-detail-actions",children:[p.status!=="done"&&a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{p&&J(p.id,gf[p.status])},children:["Move to ",dl[gf[p.status]||"queued"]]}),a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{p&&V(p.id)},children:[a.jsx(F1,{size:14})," Archive"]}),TC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{i==null||i(p.id)},children:[a.jsx(Bn,{size:14})," Chat"]}),zC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{qe(p.id)},children:[a.jsx(Gn,{size:14})," Artifact"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{p&&D(p.id)},children:a.jsx($i,{size:14})})]}),children:p&&a.jsxs("div",{className:"mobile-task-detail",children:[a.jsxs("div",{className:"mobile-task-detail-header",children:[a.jsx("span",{className:`mobile-task-status-badge status-${p.status}`,children:dl[p.status]||p.status}),a.jsx("span",{className:`mobile-task-priority priority-${p.priority}`,children:p.priority})]}),a.jsx("h3",{className:"mobile-task-detail-title",children:p.title}),p.description&&a.jsx("p",{className:"mobile-task-detail-desc",children:p.description}),a.jsxs("div",{className:"mobile-task-detail-meta",children:[p.assignee&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Assignee"}),a.jsxs("span",{children:["@",p.assignee]})]}),p.dueDate&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Due"}),a.jsx("span",{children:new Date(p.dueDate).toLocaleDateString()})]}),p.timeSpent!=null&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time spent"}),a.jsxs("span",{children:[Math.round(p.timeSpent/6e4),"min"]})]}),(fe=p.dependencies)!=null&&fe.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Dependencies"}),a.jsx("span",{children:p.dependencies.length})]}):null,(Ye=p.comments)!=null&&Ye.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Comments"}),a.jsx("span",{children:p.comments.length})]}):null,a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Created"}),a.jsx("span",{children:jr(p.createdAt)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Updated"}),a.jsx("span",{children:jr(p.updatedAt)})]})]})]})}),a.jsx(PC,{open:S,onClose:()=>y(!1),onCreate:ye,agents:E}),a.jsx(_t,{open:!!g,onClose:()=>{v(null),P(""),T(null)},title:(M==null?void 0:M.name)||"Artifact",actions:C.length>1?a.jsx("div",{className:"mobile-task-detail-actions",children:C.map((B,ie)=>a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{j(!0),Promise.all([Q.get(`/artifacts/${encodeURIComponent(B)}`),fetch(Q.urlWithToken(`/artifacts/${encodeURIComponent(B)}/content`)).then(re=>re.text())]).then(([re,be])=>{T(re),P(be),j(!1)}).catch(()=>j(!1))},children:["Artifact ",ie+1]},B))}):null,children:a.jsx("div",{className:"mobile-artifact-viewer",children:k?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading artifact…"})}):N?a.jsx("iframe",{srcDoc:N,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(M==null?void 0:M.name)||"Artifact",loading:"lazy"}):a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Gn,{size:32}),a.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function IC(e){var t,n;return((n=(t=e.settings)==null?void 0:t.data)==null?void 0:n.defaultAgent)||"odin"}function PC({open:e,onClose:t,onCreate:n,agents:r}){const[i,l]=b.useState(""),[s,o]=b.useState(""),[u,d]=b.useState(""),[c,f]=b.useState("normal"),h=m=>{m.preventDefault(),i.trim()&&(n(i.trim(),s.trim(),u,c),l(""),o(""),d(""),f("normal"))};return a.jsx(Tn,{open:e,onClose:t,title:"New Task",actions:a.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Create Task"]}),children:a.jsxs("form",{id:"new-task-form",onSubmit:h,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Task title",value:i,onChange:m=>l(m.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Optional description",value:s,onChange:m=>o(m.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Assignee"}),a.jsxs("select",{className:"mobile-input",value:u,onChange:m=>d(m.target.value),children:[a.jsx("option",{value:"",children:"Unassigned"}),r.map(m=>a.jsxs("option",{value:m.name,children:["@",m.name]},m.name))]}),a.jsx("label",{className:"mobile-field-label",children:"Priority"}),a.jsxs("select",{className:"mobile-input",value:c,onChange:m=>f(m.target.value),children:[a.jsx("option",{value:"low",children:"Low"}),a.jsx("option",{value:"normal",children:"Normal"}),a.jsx("option",{value:"high",children:"High"})]})]})})}const AC=[{id:"activity",label:"Activity",icon:ma},{id:"chat",label:"Chat",icon:Bn},{id:"tasks",label:"Tasks",icon:es},{id:"settings",label:"Settings",icon:Dm},{id:"more",label:"More",icon:Y1}];function MC(e){const t=e.meta??{},n=typeof t.taskId=="string"?t.taskId:null,r=typeof t.slug=="string"?t.slug:null,i=typeof t.agent=="string"?t.agent:null;if(n)return{id:"task-detail",taskId:n};if(r)return{id:"artifacts?-detail",slug:r};if(i)return{id:"agent-detail",name:i};const l=e.link??"";return l.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(l.slice(12))}:l.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(l.slice(7))}:l.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(l.slice(8))}:null}function HC(){const[e,t]=b.useState("activity"),[n,r]=b.useState([]),[i,l]=b.useState(!1),[s,o]=b.useState(null),[u,d]=b.useState(null),[c,f]=b.useState(null),[h,m]=b.useState(null),[p,x]=b.useState(!0),[S,y]=b.useState(0),g=b.useMemo(()=>n[n.length-1]??{id:e},[e,n]),v=b.useCallback(k=>{r(j=>[...j,k])},[]),C=b.useCallback(()=>{r(k=>k.slice(0,-1))},[]),z=b.useCallback(k=>{r([]),t(k)},[]),N=b.useCallback(async()=>{var k;try{const j=await Q.get("/snapshot");d(j),(k=j.settings)!=null&&k.data&&f(j.settings.data),m(null)}catch(j){throw m(j.message||"Dashboard server unreachable."),j}},[]);b.useEffect(()=>{let k=!1;return Promise.all([Q.get("/snapshot").catch(()=>null),Q.get("/settings").catch(()=>null),Q.probeAuthStatus().catch(()=>null)]).then(([j,I])=>{var H;if(k)return;const $=(I==null?void 0:I.data)??((H=j==null?void 0:j.settings)==null?void 0:H.data)??null;j&&d(j),$&&f($),m(!j&&!$?"Dashboard server unreachable.":null)}).catch(j=>{k||m(j.message||"Dashboard server unreachable.")}).finally(()=>{k||x(!1)}),()=>{k=!0}},[]),b.useEffect(()=>{c!=null&&c.theme&&(ns(c.theme),fi(c.theme))},[c==null?void 0:c.theme]),b.useEffect(()=>{var I;if(((I=c==null?void 0:c.theme)==null?void 0:I.mode)!=="system")return;const k=window.matchMedia("(prefers-color-scheme: light)"),j=()=>{c!=null&&c.theme&&(ns(c.theme),fi(c.theme))};return k.addEventListener("change",j),()=>k.removeEventListener("change",j)},[c==null?void 0:c.theme]),b.useEffect(()=>{const k=()=>{y(I=>I+1),N().catch(()=>{})},j=()=>{document.visibilityState==="visible"&&k()};return window.addEventListener("online",k),window.addEventListener("pageshow",k),document.addEventListener("visibilitychange",j),()=>{window.removeEventListener("online",k),window.removeEventListener("pageshow",k),document.removeEventListener("visibilitychange",j)}},[N]),b.useEffect(()=>{const k=new Fm,j=k.on(I=>{if(I.type==="snapshot"&&"data"in I&&I.data)d($=>({...$??{},...I.data}));else if(I.type==="change")N().catch(()=>{});else if(I.type==="tasks:change"){const $=I.task;d(H=>{if(!H)return H;const L=(H.tasks||[]).map(J=>J.id===$.id?$:J),te=L.some(J=>J.id===$.id);return{...H,tasks:te?L:[$,...L]}})}else I.type==="tasks:delete"?d($=>$&&{...$,tasks:($.tasks||[]).filter(H=>H.id!==I.id)}):I.type==="settings:change"?I.settings&&f(I.settings):I.type==="project:change"||I.type==="agents:change"||I.type==="schedules:change"||I.type==="artifact:change"?N().catch(()=>{}):(I.type==="agent:status"||I.type==="agent:restarted")&&d($=>{if(!$)return $;const H=($.agents||[]).map(L=>L.name===I.agent.name?I.agent:L);return{...$,agents:H}})});return()=>{j(),k.close()}},[N,S]);const P=b.useCallback(k=>{(k==="activity"||k==="chat"||k==="tasks"||k==="settings"||k==="more")&&z(k)},[z]),M=b.useCallback((k,j,I)=>{if(k==="notification"){const $=MC({link:j||null,meta:I??null});$&&v($);return}if(k==="task"&&j){v({id:"task-detail",taskId:j});return}if(k==="artifacts?"&&j){v({id:"artifacts?-detail",slug:j});return}if(k==="agent"&&j){v({id:"agent-detail",name:j});return}if(k==="project"){z("activity");return}k==="setting"&&z("settings")},[z,v]),T=()=>{if(!u||!c)return null;if(n.length>0){const k=n[n.length-1];switch(k.id){case"artifacts?":return a.jsx(oC,{snapshot:u,onBack:C,onOpenArtifact:j=>v({id:"artifacts?-detail",slug:j})});case"agents":return a.jsx(df,{snapshot:u,onBack:C,onOpenAgent:j=>v({id:"agent-detail",name:j}),onRefresh:N});case"skills":return a.jsx(NC,{snapshot:u,onBack:C});case"mods":return a.jsx(tC,{snapshot:u,onBack:C});case"schedules":return a.jsx(fC,{snapshot:u,onBack:C});case"history":return a.jsx(eC,{onBack:C});case"config":return a.jsx(J2,{onBack:C});case"artifacts?-detail":return a.jsx(iC,{slug:k.slug,onBack:C});case"agent-detail":return a.jsx(df,{snapshot:u,onBack:C,onOpenAgent:()=>{},onRefresh:N,selectedAgent:k.name});case"task-detail":return a.jsx(yf,{snapshot:u,onRefresh:N,selectedTaskId:k.taskId,onCloseDetail:C,onOpenChat:j=>{o(j),z("chat")}});default:return null}}switch(e){case"activity":return a.jsx(Q2,{snapshot:u,onRefresh:N});case"chat":return a.jsx(Z2,{snapshot:u,settings:c,initialTaskId:s,onClearTaskId:()=>o(null)});case"tasks":return a.jsx(yf,{snapshot:u,onRefresh:N,onOpenChat:k=>{o(k),z("chat")}});case"settings":return a.jsx(CC,{settings:c,snapshot:u,onRefresh:N});case"more":return a.jsx(nC,{snapshot:u,onNavigate:k=>{(k==="artifacts?"||k==="agents"||k==="skills"||k==="mods"||k==="schedules"||k==="history"||k==="config")&&v({id:k})}});default:return null}};return p?a.jsxs("div",{className:"mobile-loading",children:[a.jsx($m,{size:"lg"}),a.jsx("p",{children:"Loading Bizar…"})]}):h||!u||!c?a.jsxs("div",{className:"mobile-loading",children:[a.jsx("h2",{children:"Dashboard unavailable"}),a.jsx("p",{children:h||"Dashboard server unreachable."}),a.jsx("p",{className:"muted",children:"Make sure the Bizar dashboard server is running."})]}):a.jsxs("div",{className:"mobile-app",children:[a.jsx(V2,{activeTab:g.id,snapshot:u,onSearch:()=>l(!0),onNavigate:M}),a.jsx("main",{className:"mobile-content",children:T()}),n.length===0&&a.jsx(F2,{tabs:AC,activeTab:e,onChange:P}),n.length>0&&a.jsx("button",{type:"button",className:"mobile-back-btn",onClick:C,"aria-label":"Go back",children:"← Back"}),a.jsx(kC,{open:i,onClose:()=>l(!1),onNavigate:M})]})}export{hx as $,ma as A,Or as B,U1 as C,ax as D,Cx as E,Nu as F,E2 as G,ga as H,G1 as I,z2 as J,Sx as K,k2 as L,Bn as M,Lm as N,RC as O,yt as P,Zl as Q,Ot as R,es as S,ux as T,Am as U,ix as V,od as W,tr as X,lb as Y,x2 as Z,F1 as _,Q as a,OC as a0,dx as a1,ld as a2,Gn as a3,ex as a4,_C as a5,DC as a6,fi as a7,rx as a8,J1 as a9,ox as aa,Z1 as ab,Q1 as ac,ns as ad,Fm as ae,sx as af,rg as ag,nx as ah,$1 as ai,N2 as aj,W1 as ak,$C as al,FC as am,R1 as an,HC as ao,Cs as b,X as c,id as d,Jl as e,pa as f,Mr as g,sd as h,Eu as i,a as j,ts as k,yx as l,rd as m,H1 as n,jr as o,$m as p,Rm as q,b as r,cx as s,$i as t,px as u,Mm as v,Im as w,q1 as x,S2 as y,lx as z};
354
- //# sourceMappingURL=mobile-CaZ0gEeJ.js.map
353
+ */var P2={L:xr.QrCode.Ecc.LOW,M:xr.QrCode.Ecc.MEDIUM,Q:xr.QrCode.Ecc.QUARTILE,H:xr.QrCode.Ecc.HIGH},Yp=128,Kp="L",Gp="#FFFFFF",Xp="#000000",Zp=!1,Jp=1,A2=4,M2=0,L2=.1;function eg(e,t=0){const n=[];return e.forEach(function(r,i){let l=null;r.forEach(function(s,o){if(!s&&l!==null){n.push(`M${l+t} ${i+t}h${o-l}v1H${l+t}z`),l=null;return}if(o===r.length-1){if(!s)return;l===null?n.push(`M${o+t},${i+t} h1v1H${o+t}z`):n.push(`M${l+t},${i+t} h${o+1-l}v1H${l+t}z`);return}s&&l===null&&(l=o)})}),n.join("")}function tg(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((i,l)=>l<t.x||l>=t.x+t.w?i:!1))}function R2(e,t,n,r){if(r==null)return null;const i=e.length+n*2,l=Math.floor(t*L2),s=i/t,o=(r.width||l)*s,u=(r.height||l)*s,d=r.x==null?e.length/2-o/2:r.x*s,c=r.y==null?e.length/2-u/2:r.y*s,f=r.opacity==null?1:r.opacity;let h=null;if(r.excavate){let p=Math.floor(d),x=Math.floor(c),S=Math.ceil(o+d-p),y=Math.ceil(u+c-x);h={x:p,y:x,w:S,h:y}}const m=r.crossOrigin;return{x:d,y:c,h:u,w:o,excavation:h,opacity:f,crossOrigin:m}}function D2(e,t){return t!=null?Math.max(Math.floor(t),0):e?A2:M2}function ng({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:l,size:s,boostLevel:o}){let u=Ae.useMemo(()=>{const p=(Array.isArray(e)?e:[e]).reduce((x,S)=>(x.push(...xr.QrSegment.makeSegments(S)),x),[]);return xr.QrCode.encodeSegments(p,P2[t],n,void 0,void 0,o)},[e,t,n,o]);const{cells:d,margin:c,numCells:f,calculatedImageSettings:h}=Ae.useMemo(()=>{let m=u.getModules();const p=D2(r,i),x=m.length+p*2,S=R2(m,s,p,l);return{cells:m,margin:p,numCells:x,calculatedImageSettings:S}},[u,s,l,r,i]);return{qrcode:u,margin:c,cells:d,numCells:f,calculatedImageSettings:h}}var _2=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),O2=Ae.forwardRef(function(t,n){const r=t,{value:i,size:l=Yp,level:s=Kp,bgColor:o=Gp,fgColor:u=Xp,includeMargin:d=Zp,minVersion:c=Jp,boostLevel:f,marginSize:h,imageSettings:m}=r,x=Ia(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:S}=x,y=Ia(x,["style"]),g=m==null?void 0:m.src,v=Ae.useRef(null),C=Ae.useRef(null),z=Ae.useCallback(H=>{v.current=H,typeof n=="function"?n(H):n&&(n.current=H)},[n]),[N,P]=Ae.useState(!1),{margin:M,cells:T,numCells:k,calculatedImageSettings:j}=ng({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:h,imageSettings:m,size:l});Ae.useEffect(()=>{if(v.current!=null){const H=v.current,L=H.getContext("2d");if(!L)return;let te=T;const J=C.current,D=j!=null&&J!==null&&J.complete&&J.naturalHeight!==0&&J.naturalWidth!==0;D&&j.excavation!=null&&(te=tg(T,j.excavation));const V=window.devicePixelRatio||1;H.height=H.width=l*V;const w=l/k*V;L.scale(w,w),L.fillStyle=o,L.fillRect(0,0,k,k),L.fillStyle=u,_2?L.fill(new Path2D(eg(te,M))):T.forEach(function(ne,ae){ne.forEach(function(E,ye){E&&L.fillRect(ye+M,ae+M,1,1)})}),j&&(L.globalAlpha=j.opacity),D&&L.drawImage(J,j.x+M,j.y+M,j.w,j.h)}}),Ae.useEffect(()=>{P(!1)},[g]);const I=za({height:l,width:l},S);let $=null;return g!=null&&($=Ae.createElement("img",{src:g,key:g,style:{display:"none"},onLoad:()=>{P(!0)},ref:C,crossOrigin:j==null?void 0:j.crossOrigin})),Ae.createElement(Ae.Fragment,null,Ae.createElement("canvas",za({style:I,height:l,width:l,ref:z,role:"img"},y)),$)});O2.displayName="QRCodeCanvas";var rg=Ae.forwardRef(function(t,n){const r=t,{value:i,size:l=Yp,level:s=Kp,bgColor:o=Gp,fgColor:u=Xp,includeMargin:d=Zp,minVersion:c=Jp,boostLevel:f,title:h,marginSize:m,imageSettings:p}=r,x=Ia(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:S,cells:y,numCells:g,calculatedImageSettings:v}=ng({value:i,level:s,minVersion:c,boostLevel:f,includeMargin:d,marginSize:m,imageSettings:p,size:l});let C=y,z=null;p!=null&&v!=null&&(v.excavation!=null&&(C=tg(y,v.excavation)),z=Ae.createElement("image",{href:p.src,height:v.h,width:v.w,x:v.x+S,y:v.y+S,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const N=eg(C,S);return Ae.createElement("svg",za({height:l,width:l,viewBox:`0 0 ${g} ${g}`,ref:n,role:"img"},x),!!h&&Ae.createElement("title",null,h),Ae.createElement("path",{fill:o,d:`M0,0 h${g}v${g}H0z`,shapeRendering:"crispEdges"}),Ae.createElement("path",{fill:u,d:N,shapeRendering:"crispEdges"}),z)});rg.displayName="QRCodeSVG";function F2({tabs:e,activeTab:t,onChange:n}){return a.jsx("nav",{className:"mobile-bottom-nav",role:"navigation","aria-label":"Mobile navigation",children:e.map(r=>{const i=r.icon;return a.jsxs("button",{type:"button",className:Eu("mobile-nav-btn",t===r.id&&"mobile-nav-btn-active"),onClick:()=>n(r.id),"aria-label":r.label,"aria-current":t===r.id?"page":void 0,children:[a.jsx(i,{size:22}),a.jsx("span",{className:"mobile-nav-label",children:r.label})]},r.id)})})}function _t({open:e,onClose:t,title:n,children:r,actions:i,maxHeight:l="85vh"}){const s=b.useRef(null),o=b.useRef(null),u=b.useId(),d=b.useRef(null),c=b.useRef(null),f=b.useRef(0),h=b.useRef(0),m=()=>{var y;return((y=s.current)==null?void 0:y.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))??[]};if(b.useEffect(()=>{if(!e)return;d.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const y=g=>{var P;if(g.key==="Escape"&&t(),g.key!=="Tab")return;const v=Array.from(m());if(v.length===0){g.preventDefault(),(P=s.current)==null||P.focus();return}const C=v[0],z=v[v.length-1],N=document.activeElement;if(g.shiftKey){(!N||N===C||N===s.current)&&(g.preventDefault(),z==null||z.focus());return}N===z&&(g.preventDefault(),C==null||C.focus())};return window.addEventListener("keydown",y),requestAnimationFrame(()=>{var g,v;((g=o.current)==null?void 0:g.focus())??((v=s.current)==null||v.focus())}),()=>{var g;window.removeEventListener("keydown",y),(g=d.current)==null||g.focus()}},[e,t]),b.useEffect(()=>(e?(h.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${h.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%"):(document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width=""),()=>{document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,h.current)}),[e]),!e)return null;const p=y=>{var g;y.isPrimary&&(c.current=y.clientY,f.current=0,(g=s.current)==null||g.setPointerCapture(y.pointerId))},x=y=>{if(c.current==null||!s.current)return;const g=Math.max(0,y.clientY-c.current);f.current=g,s.current.style.transform=`translateY(${g}px)`},S=y=>{if(!s.current)return;y&&s.current.hasPointerCapture(y.pointerId)&&s.current.releasePointerCapture(y.pointerId);const g=f.current;s.current.style.transform="",c.current=null,f.current=0,g>72&&t()};return a.jsx("div",{className:"mobile-sheet-overlay",onClick:t,children:a.jsxs("div",{ref:s,className:"mobile-sheet",style:{maxHeight:l},onClick:y=>y.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Sheet","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsx("div",{className:"mobile-sheet-handle",onPointerDown:p,onPointerMove:x,onPointerUp:S,onPointerCancel:S,"aria-hidden":"true"}),a.jsxs("div",{className:"mobile-sheet-header",children:[n?a.jsx("h3",{id:u,className:"mobile-sheet-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:o,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(tr,{size:18})})]}),a.jsx("div",{className:"mobile-sheet-content",children:r}),i&&a.jsx("div",{className:"mobile-sheet-actions",children:i})]})})}function $2(e){switch(e){case"success":return"✓";case"error":return"✗";case"warning":return"⚠";default:return"ℹ"}}function B2(e){const t=new Date(e),r=Date.now()-t.getTime();return r<6e4?"just now":r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:t.toLocaleDateString()}function U2({onSelect:e}){const[t,n]=b.useState(!1),[r,i]=b.useState([]),[l,s]=b.useState(0),o=async()=>{var c;try{const f=await Q.get("/notifications");i(f.notifications||[]),s(((c=f.stats)==null?void 0:c.unread)||0)}catch{}};b.useEffect(()=>{o()},[]),b.useEffect(()=>{t&&o()},[t]);const u=async()=>{try{await Q.post("/notifications/read-all"),i(c=>c.map(f=>({...f,read:!0}))),s(0)}catch{}},d=async c=>{try{await Q.post(`/notifications/${encodeURIComponent(c)}/read`),i(f=>f.map(h=>h.id===c?{...h,read:!0}:h)),s(f=>Math.max(0,f-1))}catch{}};return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"mobile-icon-btn mobile-notif-btn",onClick:()=>n(!0),"aria-label":`Notifications${l>0?` (${l} unread)`:""}`,children:[a.jsx(rd,{size:20}),l>0&&a.jsx("span",{className:"mobile-notif-badge",children:l>9?"9+":l})]}),a.jsx(_t,{open:t,onClose:()=>n(!1),title:"Notifications",actions:l>0?a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{width:"100%"},onClick:u,children:[a.jsx(B1,{size:14})," Mark all read"]}):void 0,children:a.jsxs("div",{className:"mobile-notif-list",children:[r.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(rd,{size:32}),a.jsx("p",{children:"No notifications"})]}),r.map(c=>a.jsxs("button",{type:"button",className:`mobile-notif-item ${c.read?"read":"unread"}`,onClick:()=>{c.read||d(c.id),e(c),n(!1)},children:[a.jsx("span",{className:`mobile-notif-icon severity-${c.severity}`,children:$2(c.severity)}),a.jsxs("div",{className:"mobile-notif-body",children:[a.jsx("span",{className:"mobile-notif-title",children:c.title||c.message}),c.message&&c.title&&a.jsx("span",{className:"mobile-notif-text",children:c.message}),a.jsx("span",{className:"mobile-notif-time",children:B2(c.ts)})]}),!c.read&&a.jsx("span",{className:"mobile-notif-dot"})]},c.id))]})})]})}const H2={activity:"Activity",chat:"Chat",tasks:"Tasks",settings:"Settings",more:"More",plans:"Plans",agents:"Agents",skills:"Skills",mods:"Mods",schedules:"Schedules",history:"History",config:"Config","plan-detail":"Plan","agent-detail":"Agent","task-detail":"Task"};function V2({activeTab:e,snapshot:t,onSearch:n,onNavigate:r}){const[i,l]=b.useState(!1),s=async o=>{try{await Q.post(`/projects/${encodeURIComponent(o)}/activate`),l(!1),window.location.reload()}catch{}};return a.jsxs("header",{className:"mobile-topbar",children:[a.jsxs("div",{className:"mobile-topbar-left",children:[a.jsx("span",{className:"mobile-logo",children:"ᛒ"}),(t==null?void 0:t.activeProject)&&a.jsxs("button",{type:"button",className:"mobile-project-btn",onClick:()=>l(!0),"aria-label":"Select project",children:[a.jsx("span",{className:"mobile-project-name",children:t.activeProject.name}),a.jsx(Cs,{size:14})]}),a.jsx("span",{className:"mobile-title",children:H2[e]||"Bizar"})]}),a.jsxs("div",{className:"mobile-topbar-right",children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:n,"aria-label":"Search",children:a.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[a.jsx("circle",{cx:"11",cy:"11",r:"8"}),a.jsx("path",{d:"m21 21-4.35-4.35"})]})}),a.jsx(U2,{onSelect:o=>{r("notification",o.link||"",o.meta??null)}}),(t==null?void 0:t.activeProject)&&a.jsx(_t,{open:i,onClose:()=>l(!1),title:"Projects",children:a.jsx("div",{className:"mobile-project-list",children:(t.projects||[]).map(o=>{var u,d;return a.jsxs("button",{type:"button",className:`mobile-project-item ${o.id===((u=t.activeProject)==null?void 0:u.id)?"active":""}`,onClick:()=>s(o.id),children:[a.jsx("div",{className:"mobile-project-status","data-status":o.status}),a.jsxs("div",{className:"mobile-project-info",children:[a.jsx("span",{className:"mobile-project-item-name",children:o.name}),a.jsx("span",{className:"mobile-project-item-path",children:o.path})]}),o.id===((d=t.activeProject)==null?void 0:d.id)&&a.jsx("span",{className:"mobile-active-badge",children:"active"})]},o.id)})})})]})]})}const W2=["all","tasks","agents","bg","artifacts","mods"],ko={all:"All",tasks:"Tasks",agents:"Agents",bg:"Background",artifacts:"Plans",mods:"Mods"};function Q2({snapshot:e,onRefresh:t}){var M;const[n,r]=b.useState(((M=e.overview)==null?void 0:M.recentActivity)||[]),[i,l]=b.useState(!0),[s,o]=b.useState("all"),[u,d]=b.useState(!1),[c,f]=b.useState(null),[h,m]=b.useState(""),[p,x]=b.useState(!1);b.useEffect(()=>{var T;(T=e.overview)!=null&&T.recentActivity?(r(e.overview.recentActivity),l(!1)):S()},[e.overview]);const S=async()=>{var T;try{const k=await Q.get("/snapshot");r(((T=k.overview)==null?void 0:T.recentActivity)||[])}catch{}finally{l(!1)}},y=s==="all"?n:n.filter(T=>{var k,j,I,$,H,L;return s==="tasks"?(k=T.kind)==null?void 0:k.startsWith("task"):s==="agents"?(j=T.kind)==null?void 0:j.startsWith("agent"):s==="bg"?((I=T.kind)==null?void 0:I.includes("bg"))||(($=T.kind)==null?void 0:$.includes("schedule")):s==="artifacts"?(H=T.kind)==null?void 0:H.includes("artifacts"):s==="mods"?(L=T.kind)==null?void 0:L.includes("mod"):!0}),g=e.agents||[],v=e.tasks||[],C=v.filter(T=>T.status==="doing"||T.status==="queued"),z=v.filter(T=>T.status==="done"),N=async()=>{if(!(!h.trim()||p)){x(!0);try{await Q.post("/chat",{message:h.trim(),agent:"odin"}),m(""),await t().catch(()=>{}),await S()}catch{}finally{x(!1)}}},P=async()=>{await t().catch(()=>{}),await S()};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-submit-hero",children:[a.jsx("textarea",{className:"mobile-submit-input",placeholder:"What needs to be done? Describe a task, bug, or refactor for Odin to artifacts…",value:h,onChange:T=>m(T.target.value),rows:2}),a.jsxs("div",{className:"mobile-submit-actions",children:[a.jsx("div",{className:"mobile-submit-chips",children:["Implement feature","Fix bug","Refactor","Investigate","Write tests"].map(T=>a.jsx("button",{type:"button",className:"mobile-submit-chip",onClick:()=>m(k=>k?`${k} ${T}`:T),children:T},T))}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:!h.trim()||p,onClick:N,children:[a.jsx(Rm,{size:14})," Submit to Odin"]})]})]}),a.jsxs("div",{className:"mobile-stats",children:[a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:g.length}),a.jsx("div",{className:"mobile-stat-label",children:"Agents"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:C.length}),a.jsx("div",{className:"mobile-stat-label",children:"Active"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:z.length}),a.jsx("div",{className:"mobile-stat-label",children:"Done"})]}),a.jsxs("div",{className:"mobile-stat",children:[a.jsx("div",{className:"mobile-stat-value",children:e.artifacts.length||0}),a.jsx("div",{className:"mobile-stat-label",children:"Plans"})]})]}),i&&n.length===0&&a.jsx("div",{className:"mobile-loading mobile-loading-inline",children:a.jsx("p",{children:"Loading activity…"})}),a.jsxs("div",{className:"mobile-activity-header",children:[a.jsx("h3",{className:"mobile-section-title",style:{margin:0},children:"Recent Activity"}),a.jsxs("div",{style:{display:"flex",gap:4},children:[a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(T=>!T),"aria-label":u?"Resume":"Pause",children:u?a.jsx(Zl,{size:14}):a.jsx(ex,{size:14})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:P,"aria-label":"Refresh",children:a.jsx(Ot,{size:14})})]})]}),a.jsx("div",{className:"mobile-search-scopes",children:W2.map(T=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${s===T?"active":""}`,onClick:()=>o(T),children:ko[T]},T))}),g.length>0&&a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(Or,{size:14})," Agents"]}),a.jsx("div",{className:"mobile-card-list",children:g.slice(0,6).map(T=>a.jsxs("div",{className:"mobile-agent-card",children:[a.jsx("div",{className:"mobile-agent-dot","data-status":T.status||"idle"}),a.jsxs("div",{className:"mobile-agent-info",children:[a.jsx("span",{className:"mobile-agent-name",children:T.name}),a.jsx("span",{className:"mobile-agent-meta",children:T.status||"idle"})]})]},T.name))})]}),!u&&y.length>0&&a.jsx("section",{className:"mobile-section",children:a.jsx("div",{className:"mobile-card-list",children:y.slice(0,30).map((T,k)=>a.jsxs("button",{type:"button",className:"mobile-event-item",onClick:()=>f(T),children:[a.jsx("span",{className:"mobile-event-kind","data-kind":T.kind,children:ko[T.kind]||T.kind}),a.jsx("span",{className:"mobile-event-msg",children:q2(T)}),a.jsx("span",{className:"mobile-event-time",children:jr(T.ts)})]},`${T.ts}-${T.kind}-${k}`))})}),!u&&y.length===0&&n.length>0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ma,{size:40}),a.jsx("p",{children:"No matching activity."}),a.jsx("p",{className:"muted",children:"Try a different filter."})]}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:ko[c.kind]||c.kind,children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Kind"}),a.jsx("span",{children:c.kind})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time"}),a.jsx("span",{children:new Date(c.ts).toLocaleString()})]}),Object.entries(c).filter(([T])=>!["ts","kind"].includes(T)).map(([T,k])=>a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:T}),a.jsx("span",{style:{fontSize:12,maxWidth:200,wordBreak:"break-all"},children:typeof k=="object"?JSON.stringify(k):String(k)})]},T))]})}),g.length===0&&C.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ma,{size:40}),a.jsx("p",{children:"No activity yet."}),a.jsx("p",{className:"muted",children:"Start a task or chat to see things here."})]})]})}function q2(e){const t=e.kind||"";return t.includes("task")?`Task: ${e.title||e.id||"updated"}`:t.includes("agent")?`Agent: ${e.name||"status changed"}`:t.includes("artifacts")?`Plan: ${e.slug||"changed"}`:t.includes("mod")?`Mod: ${e.name||"changed"}`:t.includes("schedule")?`Schedule: ${e.name||"triggered"}`:JSON.stringify(e).slice(0,80)}function Tn({open:e,onClose:t,title:n,children:r,actions:i}){const l=b.useRef(null),s=b.useRef(null),o=b.useRef(null),u=b.useId(),d=b.useRef(0);return b.useEffect(()=>{if(!e)return;o.current=document.activeElement instanceof HTMLElement?document.activeElement:null;const c='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',f=h=>{var y,g;if(h.key==="Escape"&&t(),h.key!=="Tab")return;const m=Array.from(((y=l.current)==null?void 0:y.querySelectorAll(c))??[]);if(m.length===0){h.preventDefault(),(g=l.current)==null||g.focus();return}const p=m[0],x=m[m.length-1],S=document.activeElement;if(h.shiftKey){(!S||S===p||S===l.current)&&(h.preventDefault(),x==null||x.focus());return}S===x&&(h.preventDefault(),p==null||p.focus())};return window.addEventListener("keydown",f),d.current=window.scrollY,document.documentElement.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`-${d.current}px`,document.body.style.left="0",document.body.style.right="0",document.body.style.width="100%",requestAnimationFrame(()=>{var h,m;((h=s.current)==null?void 0:h.focus())??((m=l.current)==null||m.focus())}),()=>{var h;window.removeEventListener("keydown",f),document.documentElement.style.overflow="",document.body.style.overflow="",document.body.style.position="",document.body.style.top="",document.body.style.left="",document.body.style.right="",document.body.style.width="",window.scrollTo(0,d.current),(h=o.current)==null||h.focus()}},[e,t]),e?a.jsx("div",{className:"mobile-modal-overlay",onClick:c=>{c.target===c.currentTarget&&t()},children:a.jsxs("div",{ref:l,className:"mobile-modal",onClick:c=>c.stopPropagation(),role:"dialog","aria-modal":!0,"aria-label":n?void 0:"Modal","aria-labelledby":n?u:void 0,tabIndex:-1,children:[a.jsxs("div",{className:"mobile-modal-header",children:[n?a.jsx("h2",{id:u,className:"mobile-modal-title",children:n}):a.jsx("div",{}),a.jsx("button",{ref:s,type:"button",className:"mobile-icon-btn",onClick:t,"aria-label":"Close",children:a.jsx(tr,{size:20})})]}),a.jsx("div",{className:"mobile-modal-content",children:r}),i&&a.jsx("div",{className:"mobile-modal-actions",children:i})]})}):null}const ig=["reasoning","code","design","planning","gitops","analysis"],cf={reasoning:"var(--accent)",code:"var(--info)",design:"var(--success)",planning:"var(--warning)",gitops:"var(--error)",analysis:"var(--text-dim)"};function df({snapshot:e,onBack:t,onOpenAgent:n,selectedAgent:r,onRefresh:i}){const[l,s]=b.useState(e.agents||[]),[o,u]=b.useState(!e.agents),[d,c]=b.useState(""),[f,h]=b.useState(""),[m,p]=b.useState(null),[x,S]=b.useState(!1),[y,g]=b.useState(""),[v,C]=b.useState(!1);b.useEffect(()=>{if(r){const j=l.find(I=>I.name===r);j&&p(j)}},[r,l]);const z=async()=>{try{const j=await Q.get("/agents");s(j.agents||[])}catch{}finally{u(!1)}},N=l.filter(j=>{if(d&&j.category!==d)return!1;if(f){const I=f.toLowerCase();if(!j.name.toLowerCase().includes(I)&&!(j.description||"").toLowerCase().includes(I))return!1}return!0}),P=async(j,I)=>{try{await Q.post(`/agents/${encodeURIComponent(j)}/invoke`,{prompt:I}),C(!1),g("")}catch{}},M=async j=>{try{await Q.post(`/agents/${encodeURIComponent(j)}/restart`),await z()}catch{}},T=async j=>{if(confirm(`Delete agent "${j}"?`))try{await Q.del(`/agents/${encodeURIComponent(j)}`),s(I=>I.filter($=>$.name!==j)),p(null),i==null||i()}catch{}},k=async j=>{try{const I=await Q.post("/agents",j);s($=>[...$,I]),S(!1),i==null||i()}catch{}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search agents…",value:f,onChange:j=>h(j.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>z(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>S(!0),"aria-label":"New agent",children:a.jsx(yt,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${d?"":"active"}`,onClick:()=>c(""),children:"All"}),ig.map(j=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${d===j?"active":""}`,onClick:()=>c(j),children:j},j))]}),o?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):N.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Or,{size:40}),a.jsx("p",{children:"No agents found."})]}):a.jsx("div",{className:"mobile-card-list",children:N.map(j=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>{p(j),n(j.name)},children:[a.jsx("div",{className:"mobile-agent-dot","data-status":j.status||"idle"}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:j.name}),a.jsx("span",{className:"mobile-list-meta",children:j.model||j.mode||"—"})]}),j.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:cf[j.category]||"var(--text-dim)"},children:j.category}),a.jsx("span",{className:"mobile-list-badge","data-status":j.status||"idle",children:j.status||"idle"})]},j.name))}),m&&a.jsx(_t,{open:!0,onClose:()=>p(null),title:m.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{g(""),C(!0)},children:[a.jsx(Zl,{size:14})," Invoke"]}),(m.isStuck||m.status==="error"||m.status==="working")&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>M(m.name),children:[a.jsx(ix,{size:14})," Restart"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>T(m.name),children:a.jsx($i,{size:14})})]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsxs("div",{className:"mobile-agent-detail-status",children:[a.jsx("span",{className:"mobile-agent-dot","data-status":m.status||"idle"}),a.jsx("span",{className:"mobile-agent-detail-status-text",children:m.status||"idle"}),m.category&&a.jsx("span",{className:"mobile-list-badge",style:{color:cf[m.category]},children:m.category})]}),a.jsx("p",{className:"mobile-agent-detail-desc",children:m.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Model"}),a.jsx("span",{className:"mono",children:m.model||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Mode"}),a.jsx("span",{children:m.mode||"subagent"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Path"}),a.jsx("span",{className:"mono",style:{fontSize:11},children:m.path})]}),m.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",style:{color:"var(--error)"},children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{children:m.lastError.message})]}),m.tasksTotal!=null&&m.tasksTotal>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Success rate"}),a.jsxs("span",{children:[Math.round((m.successRate||0)*100),"%"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last modified"}),a.jsx("span",{children:jr(m.mtime)})]})]})]})}),a.jsxs(Tn,{open:v,onClose:()=>C(!1),title:`Invoke ${m==null?void 0:m.name}`,actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!y.trim(),onClick:()=>{m&&P(m.name,y.trim())},children:[a.jsx(Zl,{size:14})," Invoke"]}),children:[a.jsxs("p",{className:"muted",style:{marginBottom:12},children:["Model: ",a.jsx("span",{className:"mono",children:(m==null?void 0:m.model)||"—"})]}),a.jsx("textarea",{className:"mobile-input",rows:5,placeholder:"What should this agent do?",value:y,onChange:j=>g(j.target.value),autoFocus:!0})]}),a.jsx(Y2,{open:x,onClose:()=>S(!1),onCreate:k})]})}function Y2({open:e,onClose:t,onCreate:n}){const[r,i]=b.useState(""),[l,s]=b.useState(""),[o,u]=b.useState(""),[d,c]=b.useState("subagent"),[f,h]=b.useState("#8b5cf6"),[m,p]=b.useState(""),[x,S]=b.useState(""),[y,g]=b.useState(""),v=C=>{C.preventDefault(),r.trim()&&(n({name:r.trim(),description:l.trim(),model:o,mode:d,color:f,tools:[],tags:x.split(",").map(z=>z.trim()).filter(Boolean),category:m,prompt:y}),i(""),s(""),u(""),c("subagent"),h("#8b5cf6"),p(""),S(""),g(""))};return a.jsx(Tn,{open:e,onClose:t,title:"New Agent",actions:a.jsxs("button",{type:"submit",form:"new-agent-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-agent-form",onSubmit:v,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-agent",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:r,onChange:C=>i(C.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"What does this agent do?",value:l,onChange:C=>s(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(provider default)",value:o,onChange:C=>u(C.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Category"}),a.jsxs("select",{className:"mobile-input",value:m,onChange:C=>p(C.target.value),children:[a.jsx("option",{value:"",children:"None"}),ig.map(C=>a.jsx("option",{value:C,children:C},C))]}),a.jsx("label",{className:"mobile-field-label",children:"Tags (comma-separated)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"tag1, tag2",value:x,onChange:C=>S(C.target.value)})]})})}function K2({sessions:e,opencodeSessions:t,activeSessionId:n,activeOpencodeSessionId:r,activeProject:i,creating:l,onCreateSession:s,onSelectSession:o,onSelectOpencodeSession:u}){const[d,c]=b.useState("all"),[f,h]=b.useState(!1),m=30,p=d==="all"?[...e,...t].sort((g,v)=>Number(v.mtime)-Number(g.mtime)):e,x=f?p:p.slice(0,m),S=t.length,y=g=>{if(g.source==="opencode"){u(g);return}o(g.id)};return a.jsxs("div",{className:"chat-sessions",children:[a.jsxs("div",{className:"chat-sessions-header",children:[a.jsx("span",{className:"chat-sessions-header-title",children:"Sessions"}),a.jsx("span",{className:"chat-sessions-count",children:x.length})]}),S>0&&a.jsxs("div",{className:"chat-sessions-toggle",children:[a.jsx("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="bizar"?"active":""}`,onClick:()=>c("bizar"),children:"Bizar"}),a.jsxs("button",{type:"button",className:`chat-sessions-toggle-btn ${d==="all"?"active":""}`,onClick:()=>c("all"),children:["All (",S," opencode)"]})]}),a.jsxs("button",{type:"button",className:"chat-sessions-new",onClick:s,disabled:l||!i,title:i?"Create new session":"Pick a project first","aria-label":"Create new session",children:[l?a.jsx($m,{size:"sm"}):a.jsx(yt,{size:14}),a.jsx("span",{children:l?"Creating…":"New session"})]}),e.length===0?a.jsx("div",{className:"chat-sessions-empty",children:a.jsx(Cx,{icon:a.jsx(Jl,{size:20}),title:i?"No sessions yet":"No project",message:i?"Create your first session to start chatting.":"Pick a project in Overview to scope chat sessions.",action:i?a.jsxs(ts,{variant:"primary",size:"sm",onClick:s,loading:l,children:[a.jsx(yt,{size:12})," New session"]}):a.jsxs(ts,{variant:"secondary",size:"sm",onClick:()=>{window.location.hash="#overview"},children:[a.jsx(Nu,{size:12})," Open Overview"]})})}):a.jsx("ul",{className:"chat-sessions-list",children:x.map(g=>{const v=g.source==="opencode",C=v?r===g.id:n===g.id;return a.jsxs("li",{className:`chat-sessions-item ${C?"active":""} ${v?"chat-sessions-item-opencode":""}`,onClick:()=>y(g),title:v?`Open in dashboard: ${g.title||g.id}`:g.id,children:[v&&a.jsx(q1,{size:10,className:"chat-sessions-item-icon"}),a.jsx("span",{className:"chat-sessions-item-id",children:g.title||g.id}),a.jsx("span",{className:"chat-sessions-item-meta",children:new Date(Number(g.mtime)).toLocaleDateString()})]},v?`oc-${g.id}`:g.id)})}),p.length>m&&a.jsx("button",{type:"button",className:"chat-sessions-show-more",onClick:()=>h(g=>!g),children:f?`Show less (${p.length-m} hidden)`:`Show all ${p.length} sessions`})]})}function G2(e){return a.jsx("div",{className:"chat-composer-wrap",children:a.jsx("div",{className:"chat-composer-pill",children:a.jsx(S2,{...e})})})}function X2({sessionId:e,messages:t,pinned:n,agent:r,model:i,agents:l,mcps:s,allCommands:o}){const[u,d]=b.useState(!1),[c,f]=b.useState(!1),h=u?l:l.slice(0,4),m=c?o:o.slice(0,4);return a.jsxs("div",{className:"chat-info",children:[a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(Bn,{size:14})," Session"]}),a.jsxs("dl",{className:"env-table",children:[a.jsx("dt",{children:"id"}),a.jsx("dd",{className:"mono",children:e||"Live"}),a.jsx("dt",{children:"Messages"}),a.jsx("dd",{className:"mono",children:t.length}),a.jsx("dt",{children:"Pinned"}),a.jsx("dd",{className:"mono",children:n.size}),a.jsx("dt",{children:"Agent"}),a.jsx("dd",{className:"mono",children:r||"—"}),a.jsx("dt",{children:"Model"}),a.jsx("dd",{className:"mono ellipsis",title:i,children:i||"—"})]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(Or,{size:14})," Agents",a.jsx("span",{className:"chat-info-card-count",children:l.length})]}),a.jsx("ul",{className:"mod-mini-list",children:h.map(p=>a.jsxs("li",{className:"mod-mini",children:[a.jsxs("span",{className:"mod-mini-name",children:["@",p.name]}),a.jsx("span",{className:"mod-mini-meta",children:p.model||p.mode||""})]},p.name))}),l.length>4&&a.jsx("button",{type:"button",className:"chat-info-card-toggle",onClick:()=>d(p=>!p),children:u?"− Show fewer":`+ ${l.length-4} more`})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("div",{className:"chat-info-card-title",children:[a.jsx(lx,{size:14})," MCPs",a.jsx("span",{className:"chat-info-card-count",children:s.length})]}),a.jsxs("ul",{className:"mod-mini-list",children:[s.length===0?a.jsx("li",{className:"muted",children:"No MCPs configured."}):null,s.map(p=>a.jsxs("li",{className:"mod-mini",children:[a.jsx("span",{className:"mod-mini-name",children:p.id}),a.jsx("span",{className:`mod-mini-pill ${p.enabled?"on":"off"}`,children:p.enabled?"on":"off"})]},p.id))]})]}),a.jsxs("div",{className:"chat-info-card",children:[a.jsxs("button",{type:"button",className:"chat-info-card-title chat-info-card-title-button",onClick:()=>f(p=>!p),"aria-expanded":c,children:[a.jsx(ax,{size:14})," Slash commands",a.jsx("span",{className:"chat-info-card-count",children:o.length}),a.jsx(Cs,{size:12,className:`chat-info-card-chevron ${c?"open":""}`})]}),c&&a.jsx("ul",{className:"mod-mini-list",children:m.map(p=>a.jsxs("li",{children:[a.jsx("code",{children:p.cmd}),a.jsx("span",{className:"muted",children:p.desc})]},p.cmd))})]})]})}function Z2({snapshot:e,settings:t,setActiveTab:n,initialTaskId:r,onClearTaskId:i}){const l=yx(),s=px(),o=E2(e,t,r??""),[u,d]=b.useState(""),[c,f]=b.useState(t.defaultAgent||"odin"),[h,m]=b.useState(t.defaultModel||""),[p,x]=b.useState([]),[S,y]=b.useState(!1),[g,v]=b.useState(!1),[C,z]=b.useState(!1),N=b.useRef(null),{allCommands:P,suggestions:M,setQuery:T}=z2(e);b.useEffect(()=>{T(u)},[u,T]);const k=()=>{var L;return(L=N.current)==null?void 0:L.click()},j=L=>{const te=L.target.files;if(!te)return;const J=[];for(let D=0;D<te.length;D++)J.push(te[D].name);x(D=>{const V=J.filter(w=>!D.includes(w));return[...D,...V]}),N.current&&(N.current.value="")},I=()=>{const L=u.trim();L&&(d(""),T(""),o.onSend(L,c,h,p))},$=async()=>{if(!S){if(!e.activeProject){l.warning("Pick a project in Overview to scope chat sessions.",4e3);return}y(!0);try{const L=await fetch("/chat/sessions",{method:"POST"}).then(te=>te.json());o.loadChat(L.id),l.success(`Session ${L.id} created.`)}catch(L){l.error(`Create failed: ${L.message}`)}finally{y(!1)}}},H=L=>{s.open({title:"Delete message?",children:a.jsx("p",{style:{margin:0},children:"This action cannot be undone."}),footer:a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(ts,{variant:"secondary",size:"sm",onClick:()=>s.close(),children:"Cancel"}),a.jsx(ts,{variant:"danger",size:"sm",onClick:()=>{s.close(),o.deleteMessage(L)},children:"Delete"})]})})};return a.jsxs("div",{className:"chat-shell",children:[a.jsx(Sx,{activeProject:e.activeProject,sessionCount:o.sessions.length,sessionsOpen:g,infoOpen:C,onToggleSessions:()=>v(L=>!L),onToggleInfo:()=>z(L=>!L),onOpenOverview:()=>n==null?void 0:n("overview")}),a.jsxs("div",{className:"chat-body",children:[a.jsx("aside",{className:`chat-sessions ${g?"":"chat-sessions-hidden"}`,children:a.jsx(K2,{sessions:o.sessions,opencodeSessions:o.opencodeSessions,activeSessionId:o.sessionId,activeOpencodeSessionId:o.activeOpencodeSessionId,activeProject:e.activeProject,onCreateSession:$,onSelectSession:o.selectBizarSession,onSelectOpencodeSession:L=>o.loadOpencodeSession(L.id),creating:S})}),a.jsxs("main",{className:"chat-main",children:[a.jsx(k2,{messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,loading:o.loading,activeProject:e.activeProject,sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,pinned:o.pinned,onPickSuggestion:L=>d(L),onCopy:L=>o.copyMessage(L),onDelete:H,onTogglePin:o.togglePin,onRegenerate:o.onRegenerate}),a.jsx(G2,{agent:c,setAgent:f,model:h,setModel:m,text:u,setText:d,sending:o.sending,onSend:I,attachments:p,setAttachments:x,suggestions:M,onPickSuggestion:L=>d(`${L.split(" ")[0]} `),agents:e.agents||[],onAttach:k,sessionsOpen:g,infoOpen:C}),a.jsx("input",{ref:N,type:"file",multiple:!0,style:{display:"none"},onChange:j})]}),a.jsx("aside",{className:`chat-info ${C?"":"chat-info-hidden"}`,children:a.jsx(X2,{sessionId:o.activeSource==="opencode"?o.activeOpencodeSessionId??o.sessionId:o.sessionId,messages:o.activeSource==="opencode"?o.opencodeMessages:o.bizarMessages,pinned:o.pinned,agent:c,model:h,agents:e.agents||[],mcps:e.mcps||[],allCommands:P})})]})]})}function J2({onBack:e}){const[t,n]=b.useState([]),[r,i]=b.useState(!0),[l,s]=b.useState({}),[o,u]=b.useState(!1),d=async()=>{try{const x=await Q.get("/config"),S=Object.entries(x).map(([y,g])=>({key:y,value:g,type:c(g)}));n(S),s(Object.fromEntries(Object.entries(x).map(([y,g])=>[y,g])))}catch{}finally{i(!1)}};b.useEffect(()=>{d()},[]);const c=x=>typeof x=="boolean"?"boolean":typeof x=="number"?"number":typeof x=="string"?"string":Array.isArray(x)?"array":x&&typeof x=="object"?"object":"unknown",f=(x,S)=>{s(y=>({...y,[x]:S}))},h=async()=>{u(!0);try{await Q.patch("/config",l),await d()}catch{}finally{u(!1)}},m=(x,S)=>{s(y=>({...y,[x]:S}))},p=x=>{const S=l[x.key];switch(x.type){case"boolean":return a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!S,onChange:y=>f(x.key,y.target.checked)}),a.jsx("span",{className:"mobile-toggle-slider"})]});case"number":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"number",inputMode:"numeric",value:String(S??""),onChange:y=>f(x.key,Number(y.target.value))});case"string":return a.jsx("input",{className:"mobile-input mobile-input-sm",type:"text",value:String(S??""),onChange:y=>f(x.key,y.target.value)});case"object":case"array":return a.jsx("textarea",{className:"mobile-input mobile-input-sm",rows:2,value:JSON.stringify(S??null,null,2),onChange:y=>{try{f(x.key,JSON.parse(y.target.value))}catch{}}});default:return a.jsx("span",{className:"mobile-setting-value mono",children:String(S??"null")})}};return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsxs("span",{style:{fontSize:14,color:"var(--text-muted)",flex:1},children:[t.length," config entries"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:()=>h(),children:[a.jsx(Lm,{size:14})," ",o?"Saving…":"Save all"]})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):t.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Mr,{size:40}),a.jsx("p",{children:"No config entries."})]}):a.jsx("div",{className:"mobile-config-list",children:t.map(x=>a.jsxs("div",{className:"mobile-config-row",children:[a.jsxs("div",{className:"mobile-config-key",children:[a.jsx("span",{className:"mono",children:x.key}),a.jsx("span",{className:"mobile-config-type",children:x.type})]}),a.jsx("div",{className:"mobile-config-value",children:p(x)}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(x.key,x.defaultValue),"aria-label":"Reset to default",title:"Reset",children:a.jsx(rx,{size:14})})]},x.key))})]})}function eC({onBack:e}){const[t,n]=b.useState([]),[r,i]=b.useState(!0),[l,s]=b.useState(null),[o,u]=b.useState(""),d=async()=>{try{const m=await Q.get("/history");if(Array.isArray(m.history)){n(m.history);return}if(Array.isArray(m.projects)){const p=new Map;for(const x of m.events||[]){const S=x.projectId;if(!S)continue;const y=p.get(S);(!y||new Date(x.ts).getTime()>new Date(y.ts).getTime())&&p.set(S,x)}n(m.projects.map(x=>{const S=p.get(x.id);return{id:x.id,ts:x.lastAccessed||(S==null?void 0:S.ts)||new Date(0).toISOString(),agent:x.name,taskCount:x.tasks.total,summary:`${x.path} · ${x.tasks.done}/${x.tasks.total} done · ${x.plans} plan${x.plans===1?"":"s"}`,output:S?`${S.kind}${S.text?` — ${S.text}`:""}`:"No recent events."}}));return}n([])}catch{}finally{i(!1)}};b.useEffect(()=>{d()},[]);const c=m=>{if(!m)return"—";const p=Math.floor(m/1e3);if(p<60)return`${p}s`;const x=Math.floor(p/60),S=p%60;return`${x}m ${S}s`},f=m=>new Date(m).toLocaleString(),h=o.trim()?t.filter(m=>{const p=o.toLowerCase();return(m.agent||"session").toLowerCase().includes(p)||(m.summary||"").toLowerCase().includes(p)||(m.output||"").toLowerCase().includes(p)}):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search history…",value:o,onChange:m=>u(m.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>d(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):h.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(ga,{size:40}),a.jsx("p",{children:t.length===0?"No history yet.":"No matching sessions."})]}):a.jsx("div",{className:"mobile-card-list",children:h.map(m=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>s(m),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(ga,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:m.agent||"Session"}),a.jsxs("span",{className:"mobile-list-meta",children:[f(m.ts),m.duration?` · ${c(m.duration)}`:"",m.taskCount?` · ${m.taskCount} tasks`:""]})]})]},m.id))}),l&&a.jsxs(_t,{open:!0,onClose:()=>s(null),title:"Session Detail",children:[a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Agent"}),a.jsx("span",{children:l.agent||"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Started"}),a.jsx("span",{children:f(l.ts)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Duration"}),a.jsx("span",{children:c(l.duration)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tasks"}),a.jsx("span",{children:l.taskCount||0})]})]}),l.summary&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Summary"}),a.jsx("p",{style:{fontSize:13},children:l.summary})]}),l.output&&a.jsxs("div",{style:{marginTop:12},children:[a.jsx("h4",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:4},children:"Output"}),a.jsxs("pre",{className:"mono",style:{fontSize:11,whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--bg-elev-2)",padding:8,borderRadius:6},children:[l.output.slice(0,1e3),l.output.length>1e3?"…":""]})]})]})]})}function tC({snapshot:e,onBack:t}){const[n,r]=b.useState(e.mods||[]),[i,l]=b.useState(!e.mods),[s,o]=b.useState(""),[u,d]=b.useState("all"),[c,f]=b.useState(null),h=async()=>{try{const x=await Q.get("/mods");r(x.mods||[])}catch{}finally{l(!1)}};b.useEffect(()=>{e.mods?(r(e.mods),l(!1)):h()},[e.mods]);const m=async(x,S)=>{try{await Q.patch(`/mods/${encodeURIComponent(x)}`,{enabled:S}),r(y=>y.map(g=>g.id===x?{...g,enabled:S}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:S})}catch{}},p=n.filter(x=>{if(u==="enabled"&&!x.enabled||u==="disabled"&&x.enabled)return!1;if(s){const S=s.toLowerCase();return x.name.toLowerCase().includes(S)||x.description.toLowerCase().includes(S)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search mods…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:["all","enabled","disabled"].map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x.charAt(0).toUpperCase()+x.slice(1)},x))}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Mr,{size:40}),a.jsx("p",{children:"No mods found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Mr,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:["v",x.version," · ",x.author]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsx("div",{className:"mobile-task-detail-actions",children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{c&&m(c.id,!c.enabled)},children:[a.jsx(Mm,{size:14})," ",c.enabled?"Disable":"Enable"]})}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Author"}),a.jsx("span",{children:c.author})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Bizar"}),a.jsx("span",{className:"mono",children:c.bizar})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:c.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Permissions"}),a.jsx("span",{children:c.permissions.length})]}),c.installedAt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Installed"}),a.jsx("span",{children:new Date(c.installedAt).toLocaleDateString()})]})]})]})})]})}function nC({snapshot:e,onNavigate:t}){var s,o,u;const[n,r]=b.useState(""),i=[{id:"artifacts",icon:Gn,label:"Plans",count:e.artifacts.length||0,desc:"Visual artifacts with elements & comments"},{id:"agents",icon:Or,label:"Agents",count:((s=e.agents)==null?void 0:s.length)||0,desc:"The Norse pantheon"},{id:"skills",icon:Mr,label:"Skills",count:null,desc:"Agent capabilities & tools"},{id:"mods",icon:Mr,label:"Mods",count:((o=e.mods)==null?void 0:o.length)||0,desc:"Installed modifications"},{id:"schedules",icon:pa,label:"Schedules",count:((u=e.schedules)==null?void 0:u.length)||0,desc:"Cron jobs & automated tasks"},{id:"history",icon:ga,label:"History",count:null,desc:"Past sessions & outputs"},{id:"config",icon:Dm,label:"Config",count:null,desc:"Key-value configuration editor"}],l=n.trim()?i.filter(d=>d.label.toLowerCase().includes(n.toLowerCase())||d.desc.toLowerCase().includes(n.toLowerCase())):i;return a.jsxs("div",{className:"mobile-view",children:[a.jsx("div",{className:"mobile-tasks-toolbar",children:a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search…",value:n,onChange:d=>r(d.target.value),style:{flex:1}})}),a.jsx("div",{className:"mobile-card-list",children:l.map(d=>{const c=d.icon;return a.jsxs("button",{type:"button",className:"mobile-more-nav-item",onClick:()=>t(d.id),children:[a.jsx("div",{className:"mobile-more-nav-icon",children:a.jsx(c,{size:20})}),a.jsxs("div",{className:"mobile-more-nav-content",children:[a.jsxs("span",{className:"mobile-more-nav-label",children:[d.label,d.count!=null&&a.jsx("span",{className:"mobile-more-nav-count",children:d.count})]}),a.jsx("span",{className:"mobile-more-nav-desc",children:d.desc})]}),a.jsx(id,{size:16,className:"mobile-more-nav-arrow"})]},d.id)})}),a.jsx("div",{className:"mobile-more-footer",children:a.jsxs("a",{href:"/?desktop=1",className:"mobile-more-link",children:["Switch to Desktop ",a.jsx(id,{size:14})]})})]})}const qu=[{id:"task",label:"Task",color:"var(--info)"},{id:"note",label:"Note",color:"var(--text-dim)"},{id:"decision",label:"Decision",color:"var(--accent)"},{id:"question",label:"Question",color:"var(--warning)"}];function wo(e){var t;return((t=qu.find(n=>n.id===e))==null?void 0:t.color)||"var(--text-dim)"}function rC({type:e,size:t=12}){switch(e){case"task":return a.jsx(es,{size:t,style:{color:"var(--info)"}});case"note":return a.jsx(od,{size:t,style:{color:"var(--text-dim)"}});case"decision":return a.jsx(es,{size:t,style:{color:"var(--accent)"}});case"question":return a.jsx(V1,{size:t,style:{color:"var(--warning)"}});default:return a.jsx(od,{size:t})}}function iC({slug:e,onBack:t}){const[n,r]=b.useState(null),[i,l]=b.useState(null),[s,o]=b.useState(!0),[u,d]=b.useState(!1),[c,f]=b.useState(null),[h,m]=b.useState(!1),[p,x]=b.useState(!1),[S,y]=b.useState(!1),[g,v]=b.useState(""),C=async()=>{o(!0);try{const T=await Q.get(`/plans/${encodeURIComponent(e)}`);r(T.canvas),l(T.meta)}catch{}finally{o(!1)}};b.useEffect(()=>{C()},[e]);const z=async(T,k,j)=>{try{const I=((n==null?void 0:n.elements)||[]).reduce((H,L)=>Math.max(H,L.x||0),40),$=((n==null?void 0:n.elements)||[]).reduce((H,L)=>Math.max(H,L.y||0),40);await Q.post(`/plans/${encodeURIComponent(e)}/elements`,{type:T,title:k,content:j,x:20+I,y:20+$,width:240,height:120}),await C(),x(!1)}catch{}},N=async(T,k)=>{try{await Q.put(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(T)}`,k),await C(),f(null)}catch{}},P=async T=>{if(confirm("Delete this element?"))try{await Q.del(`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(T)}`),f(null),await C()}catch{}},M=async(T,k)=>{try{const j=k?`/plans/${encodeURIComponent(e)}/elements/${encodeURIComponent(k)}/comments`:`/plans/${encodeURIComponent(e)}/comments`;await Q.post(j,{text:T,elementId:k}),await C(),v(""),y(!1)}catch{}};return s||!n||!i?a.jsx("div",{className:"mobile-view",children:a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading canvas…"})})}):a.jsxs("div",{className:"mobile-view mobile-view-canvas",children:[a.jsxs("div",{className:"mobile-canvas-bar",children:[a.jsxs("div",{className:"mobile-canvas-meta",children:[a.jsx("span",{className:"mobile-canvas-title",children:i.title||e}),a.jsx("span",{className:"mobile-canvas-status","data-status":i.status,children:i.status})]}),a.jsxs("div",{className:"mobile-canvas-actions",children:[a.jsx("button",{type:"button",className:`mobile-icon-btn ${u?"active":""}`,onClick:()=>d(T=>!T),"aria-label":u?"Done editing":"Edit",children:a.jsx(Am,{size:16})}),a.jsxs("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(T=>!T),"aria-label":"Comments",children:[a.jsx(Bn,{size:16}),n.comments.length>0&&a.jsx("span",{className:"mobile-canvas-comment-count",children:n.comments.length})]}),u&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(!0),"aria-label":"Add element",children:a.jsx(yt,{size:16})})]})]}),a.jsxs("div",{className:"mobile-canvas-elements",children:[n.elements.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx("p",{children:"No elements yet."}),u&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>x(!0),children:[a.jsx(yt,{size:14})," Add Element"]})]}),n.elements.map(T=>a.jsxs("button",{type:"button",className:`mobile-canvas-element ${(c==null?void 0:c.id)===T.id?"selected":""}`,style:{borderColor:wo(T.type)},onClick:()=>{u&&f(T)},"aria-pressed":(c==null?void 0:c.id)===T.id,children:[a.jsxs("div",{className:"mobile-canvas-el-header",style:{background:`${wo(T.type)}18`},children:[a.jsx(rC,{type:T.type,size:12}),a.jsx("span",{className:"mobile-canvas-el-type",style:{color:wo(T.type)},children:T.type}),T.status&&T.status!=="open"&&a.jsx("span",{className:"mobile-canvas-el-status",children:T.status})]}),a.jsx("div",{className:"mobile-canvas-el-title",children:T.title||"Untitled"}),T.content&&a.jsxs("div",{className:"mobile-canvas-el-content",children:[T.content.slice(0,120),T.content.length>120?"…":""]}),a.jsxs("div",{className:"mobile-canvas-el-comments",children:[a.jsx(Bn,{size:10}),n.comments.filter(k=>k.elementId===T.id).length]})]},T.id))]}),h&&a.jsxs("div",{className:"mobile-canvas-comments",children:[a.jsxs("div",{className:"mobile-canvas-comments-header",children:[a.jsxs("h4",{children:["Comments (",n.comments.length,")"]}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>m(!1),children:a.jsx(tr,{size:16})})]}),a.jsxs("div",{className:"mobile-canvas-comment-list",children:[n.comments.length===0&&a.jsx("p",{className:"mobile-empty-inline",children:"No comments yet."}),n.comments.map(T=>a.jsxs("div",{className:"mobile-canvas-comment",children:[a.jsxs("div",{className:"mobile-canvas-comment-head",children:[a.jsx("span",{className:"mono",children:T.author}),a.jsx("span",{className:"muted",children:jr(T.created)})]}),a.jsx("div",{className:"mobile-canvas-comment-text",children:T.text})]},T.id))]}),a.jsxs("div",{className:"mobile-canvas-comment-input",children:[a.jsx("textarea",{className:"mobile-input",rows:2,placeholder:"Add a comment…",value:g,onChange:T=>v(T.target.value)}),a.jsx("button",{type:"button",className:"mobile-btn",disabled:!g.trim(),onClick:()=>{M(g.trim(),null)},children:"Post"})]})]}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:`Edit ${c.title||c.type}`,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>P(c.id),children:[a.jsx($i,{size:14})," Delete"]}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>y(!0),children:[a.jsx(Bn,{size:14})," Comment"]})]}),children:a.jsx(lC,{element:c,onSave:T=>N(c.id,T),onClose:()=>f(null)})}),a.jsx(sC,{open:p,onClose:()=>x(!1),onAdd:z}),a.jsx(Tn,{open:S,onClose:()=>y(!1),title:"Add Comment",actions:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},disabled:!g.trim(),onClick:()=>{M(g.trim(),(c==null?void 0:c.id)||null),y(!1)},children:[a.jsx(Bn,{size:14})," Post"]}),children:a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Your comment…",value:g,onChange:T=>v(T.target.value),autoFocus:!0})})]})}function lC({element:e,onSave:t,onClose:n}){const[r,i]=b.useState(e.type),[l,s]=b.useState(e.title||""),[o,u]=b.useState(e.content||""),[d,c]=b.useState(e.status||"open");return a.jsxs("form",{className:"mobile-task-form",onSubmit:f=>{f.preventDefault(),t({type:r,title:l,content:o,status:d}),n()},children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:f=>i(f.target.value),children:qu.map(f=>a.jsx("option",{value:f.id,children:f.label},f.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title"}),a.jsx("input",{className:"mobile-input",type:"text",value:l,onChange:f=>s(f.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Status"}),a.jsx("input",{className:"mobile-input",type:"text",value:d,onChange:f=>c(f.target.value),placeholder:"open / done / blocked"}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:4,value:o,onChange:f=>u(f.target.value)}),a.jsx("button",{type:"submit",className:"mobile-btn",style:{width:"100%",marginTop:8},children:"Save"})]})}function sC({open:e,onClose:t,onAdd:n}){const[r,i]=b.useState("task"),[l,s]=b.useState(""),[o,u]=b.useState(""),d=c=>{c.preventDefault(),l.trim()&&(n(r,l.trim(),o.trim()),s(""),u(""))};return a.jsx(Tn,{open:e,onClose:t,title:"Add Element",actions:a.jsxs("button",{type:"submit",form:"add-el-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Add"]}),children:a.jsxs("form",{id:"add-el-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:r,onChange:c=>i(c.target.value),children:qu.map(c=>a.jsx("option",{value:c.id,children:c.label},c.id))}),a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Element title",value:l,onChange:c=>s(c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Content (markdown)"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Description…",value:o,onChange:c=>u(c.target.value)})]})})}function oC({snapshot:e,onBack:t,onOpenArtifact:n}){const[r,i]=b.useState(e.artifacts||[]),[l,s]=b.useState(!e.artifacts),[o,u]=b.useState(""),[d,c]=b.useState(!1),[f,h]=b.useState(""),[m,p]=b.useState(""),x=async()=>{try{const g=await Q.get("/artifacts");i(g.artifacts||[])}catch{}finally{s(!1)}},S=async()=>{if(f.trim())try{const g=await Q.post("/artifacts",{slug:f.trim(),title:m.trim()||void 0});c(!1),h(""),p(""),n(g.slug)}catch{}},y=o.trim()?r.filter(g=>(g.title||g.slug||"").toLowerCase().includes(o.toLowerCase())):r;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search artifacts…",value:o,onChange:g=>u(g.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>x(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsx("div",{style:{marginBottom:12},children:a.jsxs("button",{type:"button",className:"mobile-btn",style:{width:"100%"},onClick:()=>c(!0),children:[a.jsx(yt,{size:14})," New Artifact"]})}),l?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):y.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Gn,{size:40}),a.jsx("p",{children:"No artifacts yet."})]}):a.jsx("div",{className:"mobile-card-list",children:y.map(g=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>n(g.slug),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Gn,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:g.title||g.slug}),a.jsxs("span",{className:"mobile-list-meta",children:[g.status," · ",g.source,g.elementCount!=null?` · ${g.elementCount} elements`:"",g.commentCount!=null?` · ${g.commentCount} comments`:""]})]}),a.jsx("span",{className:"mobile-list-badge","data-status":g.status,children:g.status})]},g.slug))}),a.jsx(Tn,{open:d,onClose:()=>c(!1),title:"New Artifact",actions:a.jsxs("button",{type:"submit",form:"new-plan-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Create"]}),children:a.jsxs("form",{id:"new-plan-form",onSubmit:g=>{g.preventDefault(),S()},className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Slug *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"my-plan",pattern:"[a-z0-9][a-z0-9-]{0,63}",value:f,onChange:g=>h(g.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Title (optional)"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"My Artifact",value:m,onChange:g=>p(g.target.value)})]})})]})}const aC=["cron","interval","once"],uC=["command","agent","webhook"],ff=["UTC","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Tokyo"],lg=Array.from({length:24},(e,t)=>({value:t,label:t===0?"12 AM":t<12?`${t} AM`:t===12?"12 PM":`${t-12} PM`})),cC=Array.from({length:12},(e,t)=>t*5),sg=[{value:"*",label:"Every day"},{value:"0",label:"Sun"},{value:"1",label:"Mon"},{value:"2",label:"Tue"},{value:"3",label:"Wed"},{value:"4",label:"Thu"},{value:"5",label:"Fri"},{value:"6",label:"Sat"}],dC=[{value:"s",label:"sec"},{value:"m",label:"min"},{value:"h",label:"hr"},{value:"d",label:"day"}];function fC({snapshot:e}){var S;const[t,n]=b.useState(e.schedules||[]),[r,i]=b.useState(!e.schedules),[l,s]=b.useState(""),[o,u]=b.useState(null),[d,c]=b.useState({open:!1}),f=async()=>{try{const y=await Q.get("/schedules");n(y.schedules||[])}catch{}finally{i(!1)}};b.useEffect(()=>{e.schedules?(n(e.schedules),i(!1)):f()},[e.schedules]);const h=async(y,g)=>{try{await Q.patch(`/schedules/${encodeURIComponent(y)}`,{enabled:g}),n(v=>v.map(C=>C.id===y?{...C,enabled:g}:C)),(o==null?void 0:o.id)===y&&u(v=>v&&{...v,enabled:g})}catch{}},m=async y=>{if(confirm("Delete this schedule?"))try{await Q.del(`/schedules/${encodeURIComponent(y)}`),n(g=>g.filter(v=>v.id!==y)),(o==null?void 0:o.id)===y&&u(null)}catch{}},p=async y=>{try{await Q.post(`/schedules/${encodeURIComponent(y)}/trigger`)}catch{}},x=l.trim()?t.filter(y=>y.name.toLowerCase().includes(l.toLowerCase())):t;return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search schedules…",value:l,onChange:y=>s(y.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>f(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>c({open:!0}),"aria-label":"New schedule",children:a.jsx(yt,{size:16})})]}),r?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):x.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(pa,{size:40}),a.jsx("p",{children:"No schedules found."})]}):a.jsx("div",{className:"mobile-card-list",children:x.map(y=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>u(y),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(pa,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:y.name}),a.jsxs("span",{className:"mobile-list-meta",children:[pf(y)," ·"," ",y.nextRun?`next ${mf(y.nextRun,y.timezone)}`:"no next run"]})]}),a.jsx("span",{className:`mobile-list-badge ${y.enabled?"badge-on":"badge-off"}`,children:y.enabled?"on":"off"})]},y.id))}),o&&a.jsx(_t,{open:!0,onClose:()=>u(null),title:o.name,actions:a.jsxs("div",{className:"mobile-task-detail-actions",children:[a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&p(o.id)},children:[a.jsx(Zl,{size:14})," Trigger now"]}),a.jsx("button",{type:"button",className:`mobile-btn ${o.enabled?"mobile-btn-secondary":""}`,onClick:()=>{o&&h(o.id,!o.enabled)},children:o.enabled?"Disable":"Enable"}),a.jsxs("button",{type:"button",className:"mobile-btn",onClick:()=>{o&&(c({open:!0,initial:o}),u(null))},children:[a.jsx(Am,{size:14})," Edit"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{o&&m(o.id)},children:a.jsx($i,{size:14})})]}),children:a.jsx("div",{className:"mobile-agent-detail",children:a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Type"}),a.jsx("span",{children:o.type})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Schedule"}),a.jsx("span",{className:"mono",children:pf(o)||o.schedule})]}),o.timezone&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Timezone"}),a.jsx("span",{className:"mono",children:o.timezone})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Action"}),a.jsxs("span",{children:[o.action.type,": ",o.action.target]})]}),o.action.type==="agent"&&o.action.prompt&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Prompt"}),a.jsx("span",{style:{fontSize:12},children:o.action.prompt})]}),((S=o.budgetCheck)==null?void 0:S.skipIfBudgetLow)&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Budget gate"}),a.jsxs("span",{children:["skip if ≥ ",o.budgetCheck.maxConcurrent??6," concurrent"]})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Next run"}),a.jsx("span",{children:o.nextRun?mf(o.nextRun,o.timezone):"—"})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last run"}),a.jsx("span",{children:o.lastRun?pC(o.lastRun):"—"})]}),o.lastResult&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last result"}),a.jsx("span",{style:{fontSize:12},children:o.lastResult})]}),o.lastError&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Last error"}),a.jsx("span",{style:{fontSize:12},children:o.lastError})]})]})})}),a.jsx(mC,{open:d.open,initial:d.initial,onClose:()=>c({open:!1}),onSaved:()=>{c({open:!1}),f()}})]})}function hf(e){var r,i;if(!e)return{name:"",type:"cron",cronMinute:0,cronHour:13,cronDow:"0",intervalN:30,intervalUnit:"m",onceAt:"",timezone:"UTC",actionType:"agent",actionTarget:"",actionPrompt:"",skipIfBudgetLow:!1,maxConcurrent:6,enabled:!0};const t=e.type==="cron"?og(e.schedule):null,n=e.type==="interval"?gC(e.schedule):null;return{name:e.name||"",type:e.type,cronMinute:(t==null?void 0:t.minute)??0,cronHour:(t==null?void 0:t.hour)??9,cronDow:(t==null?void 0:t.dow)??"*",intervalN:(n==null?void 0:n.n)??30,intervalUnit:(n==null?void 0:n.unit)??"m",onceAt:e.type==="once"?yC(e.schedule):"",timezone:e.timezone||"UTC",actionType:e.action.type,actionTarget:e.action.target||"",actionPrompt:e.action.prompt||"",skipIfBudgetLow:!!((r=e.budgetCheck)!=null&&r.skipIfBudgetLow),maxConcurrent:Number.isFinite((i=e.budgetCheck)==null?void 0:i.maxConcurrent)?e.budgetCheck.maxConcurrent:6,enabled:e.enabled!==!1}}function hC(e){if(e.type==="cron")return`${e.cronMinute} ${e.cronHour} * * ${e.cronDow}`;if(e.type==="interval")return`${e.intervalN}${e.intervalUnit}`;if(!e.onceAt)return"";try{return new Date(e.onceAt).toISOString()}catch{return e.onceAt}}function mC({open:e,initial:t,onClose:n,onSaved:r}){const[i,l]=b.useState(()=>hf(t)),[s,o]=b.useState(!1);b.useEffect(()=>{e&&l(hf(t))},[e,t]);const u=(c,f)=>{l(h=>({...h,[c]:f}))},d=async c=>{if(c.preventDefault(),!i.name.trim())return;const f=hC(i);if(f){o(!0);try{const h={name:i.name.trim(),type:i.type,schedule:f,timezone:i.timezone,action:{type:i.actionType,target:i.actionTarget.trim(),...i.actionType==="agent"&&i.actionPrompt.trim()?{prompt:i.actionPrompt.trim()}:{}},budgetCheck:{maxConcurrent:i.maxConcurrent,skipIfBudgetLow:i.skipIfBudgetLow},enabled:i.enabled};t?await Q.put(`/schedules/${encodeURIComponent(t.id)}`,h):await Q.post("/schedules",h),r()}catch{}finally{o(!1)}}};return a.jsx(Tn,{open:e,onClose:n,title:t?`Edit ${t.name}`:"New schedule",actions:a.jsxs("button",{type:"submit",form:"mobile-schedule-form",className:"mobile-btn",style:{width:"100%"},disabled:s,children:[a.jsx(yt,{size:14})," ",t?"Save":"Create"]}),children:a.jsxs("form",{id:"mobile-schedule-form",onSubmit:d,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Name *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Weekly review",value:i.name,onChange:c=>u("name",c.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Type"}),a.jsx("select",{className:"mobile-input",value:i.type,onChange:c=>u("type",c.target.value),children:aC.map(c=>a.jsx("option",{value:c,children:c},c))}),i.type==="cron"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Day of week"}),a.jsx("select",{className:"mobile-input",value:i.cronDow,onChange:c=>u("cronDow",c.target.value),children:sg.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))}),a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Hour"}),a.jsx("select",{className:"mobile-input",value:String(i.cronHour),onChange:c=>u("cronHour",parseInt(c.target.value,10)),children:lg.map(c=>a.jsx("option",{value:String(c.value),children:c.label},c.value))})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Minute"}),a.jsx("select",{className:"mobile-input",value:String(i.cronMinute),onChange:c=>u("cronMinute",parseInt(c.target.value,10)),children:cC.map(c=>a.jsx("option",{value:String(c),children:String(c).padStart(2,"0")},c))})]})]})]}),i.type==="interval"&&a.jsxs("div",{className:"mobile-form-row",children:[a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Every"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,value:i.intervalN,onChange:c=>u("intervalN",parseInt(c.target.value,10)||1)})]}),a.jsxs("div",{style:{flex:1},children:[a.jsx("label",{className:"mobile-field-label",children:"Unit"}),a.jsx("select",{className:"mobile-input",value:i.intervalUnit,onChange:c=>u("intervalUnit",c.target.value),children:dC.map(c=>a.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),i.type==="once"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Run at"}),a.jsx("input",{className:"mobile-input",type:"datetime-local",value:i.onceAt,onChange:c=>u("onceAt",c.target.value)})]}),a.jsx("label",{className:"mobile-field-label",children:"Timezone"}),a.jsx("select",{className:"mobile-input",value:ff.includes(i.timezone)?i.timezone:"UTC",onChange:c=>u("timezone",c.target.value),children:ff.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Action type"}),a.jsx("select",{className:"mobile-input",value:i.actionType,onChange:c=>u("actionType",c.target.value),children:uC.map(c=>a.jsx("option",{value:c,children:c},c))}),a.jsx("label",{className:"mobile-field-label",children:"Target"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:i.actionType==="webhook"?"https://...":i.actionType==="agent"?"agent or task ref":"echo hello",value:i.actionTarget,onChange:c=>u("actionTarget",c.target.value)}),i.actionType==="agent"&&a.jsxs(a.Fragment,{children:[a.jsx("label",{className:"mobile-field-label",children:"Prompt"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"What should the agent do?",value:i.actionPrompt,onChange:c=>u("actionPrompt",c.target.value)})]}),a.jsxs("fieldset",{className:"mobile-budget-card",children:[a.jsx("legend",{children:"Budget pre-flight"}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.skipIfBudgetLow,onChange:c=>u("skipIfBudgetLow",c.target.checked)}),a.jsx("span",{children:"Skip if too many bg tasks are running"})]}),a.jsx("label",{className:"mobile-field-label",children:"Cap"}),a.jsx("input",{className:"mobile-input",type:"number",min:1,max:64,value:i.maxConcurrent,onChange:c=>u("maxConcurrent",parseInt(c.target.value,10)||6),disabled:!i.skipIfBudgetLow})]}),a.jsxs("label",{className:"mobile-checkbox-row",children:[a.jsx("input",{type:"checkbox",checked:i.enabled,onChange:c=>u("enabled",c.target.checked)}),a.jsx("span",{children:"Enabled"})]})]})})}function pC(e){const t=Date.now()-new Date(e).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(e).toLocaleDateString()}function mf(e,t){try{return new Date(e).toLocaleString(void 0,{timeZone:t||void 0,weekday:"short",hour:"numeric",minute:"2-digit",month:"short",day:"numeric"})}catch{return new Date(e).toLocaleString()}}function og(e){if(typeof e!="string")return null;const t=e.trim().split(/\s+/);if(t.length!==5)return null;const[n,r,,,i]=t,l=parseInt(n,10),s=parseInt(r,10);return!Number.isFinite(l)||!Number.isFinite(s)||n!==String(l)||r!==String(s)?null:{minute:l,hour:s,dow:i==="*"?"*":Number.isFinite(parseInt(i,10))?i:"*"}}function gC(e){if(typeof e!="string")return null;const t=/^(\d+)([smhd])$/i.exec(e.trim());return t?{n:parseInt(t[1],10),unit:t[2].toLowerCase()}:null}function yC(e){if(!e)return"";try{const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}catch{return""}}function pf(e){var l,s;if(e.type!=="cron")return e.schedule;const t=og(e.schedule);if(!t)return e.schedule;const n=((l=sg.find(o=>o.value===t.dow))==null?void 0:l.label)||t.dow,r=((s=lg.find(o=>o.value===t.hour))==null?void 0:s.label)||`${t.hour}`,i=String(t.minute).padStart(2,"0");return n==="Every day"?`Every day ${r} :${i}`:`Every ${n} ${r} :${i}`}const xC=["all","tasks","agents","artifacts","projects","settings"],vC={tasks:es,agents:Or,plans:Gn,projects:Nu,settings:Mr};function kC({open:e,onClose:t,onNavigate:n}){const[r,i]=b.useState(""),[l,s]=b.useState("all"),[o,u]=b.useState([]),[d,c]=b.useState(!1),f=b.useRef(null);b.useEffect(()=>{e&&(i(""),u([]),requestAnimationFrame(()=>{var p;return(p=f.current)==null?void 0:p.focus()}))},[e]),b.useEffect(()=>{if(!r.trim()){u([]);return}const p=setTimeout(async()=>{c(!0);try{const x=await Q.get(`/search?q=${encodeURIComponent(r)}&scope=${l}`);u(x.results||[])}catch{u([])}finally{c(!1)}},250);return()=>clearTimeout(p)},[r,l]);const h=p=>{const x=p.item,S=x.id||x.slug||x.name||"";n(p.type,S),t()},m=o.reduce((p,x)=>(p[x.type]||(p[x.type]=[]),p[x.type].push(x),p),{});return a.jsx(Tn,{open:e,onClose:t,title:"Search",children:a.jsxs("div",{className:"mobile-search-container",children:[a.jsxs("div",{className:"mobile-search-input-row",children:[a.jsx(sd,{size:16,style:{color:"var(--text-muted)",flexShrink:0}}),a.jsx("input",{ref:f,className:"mobile-search-field",type:"text",placeholder:"Search…",value:r,onChange:p=>i(p.target.value),enterKeyHint:"search",onKeyDown:p=>{p.key==="Escape"&&t(),p.key==="Enter"&&o.length>0&&h(o[0])}}),r&&a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>i(""),"aria-label":"Clear",children:a.jsx(tr,{size:16})})]}),a.jsx("div",{className:"mobile-search-scopes",children:xC.map(p=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${l===p?"active":""}`,onClick:()=>s(p),children:p==="all"?"All":p.charAt(0).toUpperCase()+p.slice(1)},p))}),a.jsxs("div",{className:"mobile-search-results",children:[d&&a.jsx("div",{className:"mobile-search-loading",children:"Searching…"}),!d&&r&&o.length===0&&a.jsxs("div",{className:"mobile-empty",children:[a.jsx(sd,{size:32}),a.jsx("p",{children:"No results found"})]}),!d&&!r&&a.jsx("div",{className:"mobile-empty",children:a.jsx("p",{children:"Type to search across tasks, agents, plans, and more."})}),Object.entries(m).map(([p,x])=>{const S=vC[p]||Gn;return a.jsxs("div",{className:"mobile-search-group",children:[a.jsxs("h4",{className:"mobile-search-group-title",children:[a.jsx(S,{size:12})," ",p.charAt(0).toUpperCase()+p.slice(1)," (",x.length,")"]}),x.map((y,g)=>{const v=y.item;return a.jsxs("button",{type:"button",className:"mobile-search-result-item",onClick:()=>h(y),children:[a.jsx("span",{className:"mobile-search-result-title",children:v.title||v.name||v.slug||"(unnamed)"}),v.description&&a.jsx("span",{className:"mobile-search-result-meta",children:v.description.slice(0,80)})]},g)})]},p)})]})]})})}const wC=[{id:"dark",label:"Dark",Icon:J1},{id:"light",label:"Light",Icon:ox},{id:"system",label:"System",Icon:Z1}],bC=[{name:"Purple",accent:"#8b5cf6"},{name:"Blue",accent:"#3b82f6"},{name:"Green",accent:"#10b981"},{name:"Orange",accent:"#f97316"},{name:"Red",accent:"#ef4444"},{name:"Pink",accent:"#ec4899"},{name:"Cyan",accent:"#06b6d4"},{name:"Mono",accent:"#6b7280"}];function SC(e){if(e<=0)return"expired";const t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,"0")}`}function CC({settings:e,snapshot:t,onRefresh:n}){var z,N,P,M,T,k;const[r,i]=b.useState(e),[l,s]=b.useState(!1),[o,u]=b.useState(!1),[d,c]=b.useState(null),[f,h]=b.useState(!1),[m,p]=b.useState(Date.now());b.useEffect(()=>{i(e),s(!1),e.theme&&fi(e.theme)},[e]),b.useEffect(()=>{if(!d)return;const j=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(j)},[d]);const x=j=>{i(I=>{const $={...I,theme:{...I.theme,...j}};return ns($.theme),fi($.theme),$}),s(!0)},S=(j,I)=>{i($=>({...$,[j]:I})),s(!0)},y=async()=>{u(!0);try{const j=await Q.put("/settings",r);i(j.data),s(!1),ns(j.data.theme),fi(j.data.theme),n()}catch{}finally{u(!1)}},g=async()=>{h(!0);try{const j=await Q.post("/pair/start");c(j)}catch{}finally{h(!1)}},v=d?d.expiresAt-m:0,C=d!=null&&v<=0;return a.jsxs("div",{className:"mobile-view",children:[l&&a.jsxs("div",{className:"mobile-settings-save-bar",children:[a.jsx("span",{children:"Unsaved changes"}),a.jsxs("button",{type:"button",className:"mobile-btn",disabled:o,onClick:y,children:[a.jsx(Lm,{size:14})," ",o?"Saving…":"Save"]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Appearance"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Theme"}),a.jsx("div",{className:"mobile-theme-btns",children:wC.map(({id:j,label:I,Icon:$})=>a.jsxs("button",{type:"button",className:`mobile-theme-btn ${r.theme.mode===j?"active":""}`,onClick:()=>x({mode:j}),children:[a.jsx($,{size:14})," ",I]},j))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Accent color"}),a.jsx("div",{className:"mobile-accent-swatches",children:bC.map(j=>a.jsx("button",{type:"button",className:`mobile-accent-swatch ${r.theme.accent===j.accent?"active":""}`,style:{background:j.accent},onClick:()=>x({accent:j.accent}),title:j.name},j.name))})]}),a.jsxs("div",{className:"mobile-setting-row",style:{flexDirection:"column",alignItems:"flex-start",gap:8},children:[a.jsxs("span",{className:"mobile-setting-label",children:["Font size: ",r.theme.fontSize,"px"]}),a.jsx("input",{type:"range",min:12,max:20,value:r.theme.fontSize,onChange:j=>x({fontSize:Number(j.target.value)}),style:{width:"100%"}})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Compact mode"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.compactMode,onChange:j=>x({compactMode:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Animations"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:r.theme.animations,onChange:j=>x({animations:j.target.checked})}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Chat Defaults"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Default Agent"}),a.jsx("select",{className:"mobile-input",value:r.defaultAgent||"odin",onChange:j=>S("defaultAgent",j.target.value),children:((t==null?void 0:t.agents)||[]).map(j=>a.jsxs("option",{value:j.name,children:["@",j.name]},j.name))}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Default Model"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"(auto)",value:r.defaultModel||"",onChange:j=>S("defaultModel",j.target.value)})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Notifications"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agent completion"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onAgentComplete,onChange:j=>{i(I=>({...I,notifications:{...I.notifications,onAgentComplete:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plan approval"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!r.notifications.onPlanApproval,onChange:j=>{i(I=>({...I,notifications:{...I.notifications,onPlanApproval:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Agent Behavior"}),a.jsxs("div",{className:"mobile-card",children:[a.jsx("label",{className:"mobile-field-label",children:"Max parallel agents"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:1,max:20,value:((z=r.agents)==null?void 0:z.maxParallel)??6,onChange:j=>{i(I=>({...I,agents:{...I.agents,maxParallel:Math.max(1,Math.min(20,parseInt(j.target.value,10)||6))}})),s(!0)}}),a.jsx("label",{className:"mobile-field-label",style:{marginTop:8},children:"Stuck threshold (ms)"}),a.jsx("input",{className:"mobile-input",type:"number",inputMode:"numeric",min:6e4,max:36e5,step:6e4,value:((N=r.agents)==null?void 0:N.stuckThresholdMs)??6e5,onChange:j=>{i(I=>({...I,agents:{...I.agents,stuckThresholdMs:Math.max(6e4,parseInt(j.target.value,10)||6e5)}})),s(!0)}}),a.jsxs("div",{className:"mobile-setting-row",style:{marginTop:8},children:[a.jsx("span",{className:"mobile-setting-label",children:"Auto-restart stuck agents"}),a.jsxs("label",{className:"mobile-toggle",children:[a.jsx("input",{type:"checkbox",checked:!!((P=r.agents)!=null&&P.autoRestart),onChange:j=>{i(I=>({...I,agents:{...I.agents,autoRestart:j.target.checked}})),s(!0)}}),a.jsx("span",{className:"mobile-toggle-slider"})]})]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"Tailscale Serve"}),a.jsx("div",{className:"mobile-card",children:a.jsxs("p",{className:"muted",style:{fontSize:13},children:["Use ",a.jsx("code",{children:"bizar service"})," commands in the terminal to configure Tailscale serve."]})})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsxs("h3",{className:"mobile-section-title",children:[a.jsx(sx,{size:14})," Companion App"]}),a.jsxs("div",{className:"mobile-card",children:[!d&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,disabled:f,style:{width:"100%"},children:[a.jsx(nx,{size:14})," ",f?"Generating…":"Generate QR Code"]}),d&&!C&&a.jsxs("div",{style:{textAlign:"center"},children:[a.jsx("div",{style:{background:"#fff",padding:12,borderRadius:12,display:"inline-block"},children:a.jsx(rg,{value:d.qrPayload,size:180,level:"M"})}),a.jsxs("div",{style:{marginTop:8,fontSize:12},children:["Expires in ",a.jsx("strong",{children:SC(v)})]}),a.jsx("div",{className:"mono",style:{fontSize:10,wordBreak:"break-all",marginTop:4},children:d.publicUrl})]}),d&&C&&a.jsxs("button",{type:"button",className:"mobile-btn",onClick:g,style:{width:"100%"},children:[a.jsx(Ot,{size:14})," Generate new QR"]})]})]}),a.jsxs("section",{className:"mobile-section",children:[a.jsx("h3",{className:"mobile-section-title",children:"About"}),a.jsxs("div",{className:"mobile-card",children:[a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Version"}),a.jsx("span",{className:"mobile-setting-value mono",children:((M=r.about)==null?void 0:M.version)||"—"})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Agents"}),a.jsx("span",{className:"mobile-setting-value",children:((T=t==null?void 0:t.agents)==null?void 0:T.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Tasks"}),a.jsx("span",{className:"mobile-setting-value",children:((k=t==null?void 0:t.tasks)==null?void 0:k.length)||0})]}),a.jsxs("div",{className:"mobile-setting-row",children:[a.jsx("span",{className:"mobile-setting-label",children:"Plans"}),a.jsx("span",{className:"mobile-setting-value",children:(t==null?void 0:t.artifacts.length)||0})]})]})]}),a.jsx("div",{className:"mobile-view-footer",children:a.jsx("a",{href:"/?desktop=1",className:"mobile-btn mobile-btn-secondary",children:"Switch to Desktop"})})]})}const jC=["languages","framework","design","testing","devops","data","security","integration"];function NC({snapshot:e,onBack:t}){const[n,r]=b.useState([]),[i,l]=b.useState(!0),[s,o]=b.useState(""),[u,d]=b.useState(""),[c,f]=b.useState(null),h=async()=>{try{const x=await Q.get("/skills");r(x.skills||[])}catch{}finally{l(!1)}};b.useEffect(()=>{h()},[]);const m=async(x,S)=>{try{await Q.patch(`/skills/${encodeURIComponent(x)}`,{enabled:S}),r(y=>y.map(g=>g.id===x?{...g,enabled:S}:g)),(c==null?void 0:c.id)===x&&f(y=>y&&{...y,enabled:S})}catch{}},p=n.filter(x=>{if(u&&x.category!==u)return!1;if(s){const S=s.toLowerCase();return x.name.toLowerCase().includes(S)||x.description.toLowerCase().includes(S)}return!0});return a.jsxs("div",{className:"mobile-view",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search skills…",value:s,onChange:x=>o(x.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>h(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsxs("div",{className:"mobile-search-scopes",children:[a.jsx("button",{type:"button",className:`mobile-scope-chip ${u?"":"active"}`,onClick:()=>d(""),children:"All"}),jC.map(x=>a.jsx("button",{type:"button",className:`mobile-scope-chip ${u===x?"active":""}`,onClick:()=>d(x),children:x},x))]}),i?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):p.length===0?a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Jl,{size:40}),a.jsx("p",{children:"No skills found."})]}):a.jsx("div",{className:"mobile-card-list",children:p.map(x=>a.jsxs("button",{type:"button",className:"mobile-list-item mobile-list-item-interactive",onClick:()=>f(x),children:[a.jsx("div",{className:"mobile-list-icon",children:a.jsx(Jl,{size:16})}),a.jsxs("div",{className:"mobile-list-content",children:[a.jsx("span",{className:"mobile-list-title",children:x.name}),a.jsxs("span",{className:"mobile-list-meta",children:[x.category," · v",x.version]})]}),a.jsx("span",{className:`mobile-list-badge ${x.enabled?"badge-on":"badge-off"}`,children:x.enabled?"on":"off"})]},x.id))}),c&&a.jsx(_t,{open:!0,onClose:()=>f(null),title:c.name,actions:a.jsxs("button",{type:"button",className:`mobile-btn ${c.enabled?"mobile-btn-secondary":""}`,style:{width:"100%"},onClick:()=>{c&&m(c.id,!c.enabled)},children:[a.jsx(Mm,{size:14})," ",c.enabled?"Disable":"Enable"]}),children:a.jsxs("div",{className:"mobile-agent-detail",children:[a.jsx("p",{className:"mobile-agent-detail-desc",children:c.description||"No description."}),a.jsxs("div",{className:"mobile-agent-detail-meta",children:[a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Category"}),a.jsx("span",{children:c.category})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Version"}),a.jsx("span",{className:"mono",children:c.version})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Source"}),a.jsx("span",{children:c.source})]}),c.tags.length>0&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Tags"}),a.jsx("span",{children:c.tags.join(", ")})]})]})]})})]})}const EC=["queued","doing","blocked","done"],dl={queued:"Queued",doing:"Doing",blocked:"Blocked",done:"Done"},gf={queued:"doing",doing:"done",blocked:"queued",done:"queued"};function TC(e){const t=e.metadata??{};return!!(t.sessionId||t.bgInstanceId)}function zC(e){var n;const t=e.metadata??{};return!!((n=t.artifactIds)!=null&&n.length||t.artifactId)}function yf({snapshot:e,onRefresh:t,selectedTaskId:n,onCloseDetail:r,onOpenChat:i,onOpenArtifact:l}){var fe,Ye;const[s,o]=b.useState(e.tasks||[]),[u,d]=b.useState(!e.tasks),[c,f]=b.useState(""),[h,m]=b.useState("queued"),[p,x]=b.useState(null),[S,y]=b.useState(!1),[g,v]=b.useState(null),[C,z]=b.useState([]),[N,P]=b.useState(""),[M,T]=b.useState(null),[k,j]=b.useState(!1),[I,$]=b.useState(""),[H,L]=b.useState("updated");b.useEffect(()=>{var B;if(e.tasks&&(o(e.tasks),d(!1)),n){const ie=(B=e.tasks)==null?void 0:B.find(re=>re.id===n);ie&&x(ie)}},[e.tasks,n]),b.useEffect(()=>{if(n){const B=s.find(ie=>ie.id===n);B&&x(B)}},[n,s]);const te=async()=>{try{const B=await Q.get("/tasks");o(Array.isArray(B)?B:[])}catch{}finally{d(!1)}},J=async(B,ie)=>{o(re=>re.map(be=>be.id===B?{...be,status:ie}:be)),(p==null?void 0:p.id)===B&&x(re=>re&&{...re,status:ie});try{await Q.patch(`/tasks/${encodeURIComponent(B)}/status`,{status:ie})}catch{await te()}},D=async B=>{if(confirm("Delete this task?"))try{await Q.del(`/tasks/${encodeURIComponent(B)}`),o(ie=>ie.filter(re=>re.id!==B)),(p==null?void 0:p.id)===B&&x(null)}catch{await te()}},V=async B=>{try{await Q.post(`/tasks/${encodeURIComponent(B)}/archive`),o(ie=>ie.filter(re=>re.id!==B)),(p==null?void 0:p.id)===B&&x(null)}catch{}},ne=[...s.filter(B=>{var ie,re;if(c.trim()){const be=c.toLowerCase();if(!(B.title||"").toLowerCase().includes(be)&&!(B.description||"").toLowerCase().includes(be))return!1}if(I.trim()){const be=I==="mine"?((re=(ie=e.settings)==null?void 0:ie.data)==null?void 0:re.defaultAgent)||IC(e):I.replace(/^@/,"");if((B.assignee||"").toLowerCase()!==be.toLowerCase())return!1}return!0})].sort((B,ie)=>{switch(H){case"priority":{const re={high:0,normal:1,low:2};return(re[B.priority]??1)-(re[ie.priority]??1)}case"created":return new Date(ie.createdAt).getTime()-new Date(B.createdAt).getTime();case"updated":default:return new Date(ie.updatedAt).getTime()-new Date(B.updatedAt).getTime()}}),ae=ne.filter(B=>B.status===h),E=e.agents||[],ye=async(B,ie,re,be)=>{try{const zn=await Q.post("/tasks",{title:B,description:ie,assignee:re||null,priority:be});o(In=>[zn,...In]),y(!1)}catch{}},qe=async B=>{j(!0),P(""),T(null),v(B);try{const re=((await Q.get(`/tasks/${encodeURIComponent(B)}/artifacts`)).artifacts||[]).map(be=>be.id);if(z(re),re.length>0){const[be,zn]=await Promise.all([Q.get(`/artifacts/${encodeURIComponent(re[0])}`),fetch(Q.urlWithToken(`/artifacts/${encodeURIComponent(re[0])}/content`)).then(In=>In.text())]);T(be),P(zn)}}catch{}finally{j(!1)}};return u?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading…"})}):a.jsxs("div",{className:"mobile-view mobile-view-tasks",children:[a.jsxs("div",{className:"mobile-tasks-toolbar",children:[a.jsx("input",{className:"mobile-search-input",type:"text",placeholder:"Search tasks…",value:c,onChange:B=>f(B.target.value),style:{flex:1}}),a.jsx("button",{type:"button",className:"mobile-icon-btn",onClick:()=>te(),"aria-label":"Refresh",children:a.jsx(Ot,{size:16})})]}),a.jsxs("div",{className:"mobile-tasks-filters",children:[a.jsxs("select",{className:"mobile-filter-select",value:I,onChange:B=>$(B.target.value),children:[a.jsx("option",{value:"",children:"All"}),a.jsx("option",{value:"mine",children:"Mine"}),E.map(B=>a.jsxs("option",{value:`@${B.name}`,children:["@",B.name]},B.name))]}),a.jsxs("select",{className:"mobile-filter-select",value:H,onChange:B=>L(B.target.value),children:[a.jsx("option",{value:"updated",children:"Updated"}),a.jsx("option",{value:"created",children:"Created"}),a.jsx("option",{value:"priority",children:"Priority"})]})]}),a.jsx("div",{className:"mobile-kanban-tabs",children:EC.map(B=>{const ie=ne.filter(re=>re.status===B).length;return a.jsxs("button",{type:"button",className:`mobile-kanban-tab ${h===B?"active":""}`,onClick:()=>m(B),children:[dl[B]," (",ie,")"]},B)})}),a.jsxs("div",{className:"mobile-card-list",children:[ae.length===0&&a.jsxs("div",{className:"mobile-empty mobile-empty-compact",children:[a.jsxs("p",{children:["No ",dl[h].toLowerCase()," tasks."]}),a.jsx("p",{className:"muted",children:"Create one or switch columns."})]}),ae.map(B=>{var ie;return a.jsxs("button",{type:"button",className:"mobile-task-card",onClick:()=>x(B),children:[a.jsx("div",{className:"priority-dot",style:{background:dx[B.priority]||"var(--info)"}}),a.jsxs("div",{className:"task-content",children:[a.jsx("div",{className:"task-title",children:B.title}),a.jsxs("div",{className:"task-meta",children:[B.assignee?`@${B.assignee}`:"unassigned"," · ",jr(B.updatedAt||B.createdAt),(ie=B.dependencies)!=null&&ie.length?` · ${B.dependencies.length} deps`:""]})]})]},B.id)})]}),a.jsx("button",{type:"button",className:"mobile-fab",onClick:()=>y(!0),"aria-label":"Add task",children:a.jsx(yt,{size:24})}),a.jsx(_t,{open:!!p,onClose:()=>{x(null),r==null||r()},title:"Task Detail",actions:p&&a.jsxs("div",{className:"mobile-task-detail-actions",children:[p.status!=="done"&&a.jsxs("button",{type:"button",className:"mobile-btn",style:{flex:1},onClick:()=>{p&&J(p.id,gf[p.status])},children:["Move to ",dl[gf[p.status]||"queued"]]}),a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{p&&V(p.id)},children:[a.jsx(F1,{size:14})," Archive"]}),TC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{i==null||i(p.id)},children:[a.jsx(Bn,{size:14})," Chat"]}),zC(p)&&a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",onClick:()=>{qe(p.id)},children:[a.jsx(Gn,{size:14})," Artifact"]}),a.jsx("button",{type:"button",className:"mobile-btn mobile-btn-danger",onClick:()=>{p&&D(p.id)},children:a.jsx($i,{size:14})})]}),children:p&&a.jsxs("div",{className:"mobile-task-detail",children:[a.jsxs("div",{className:"mobile-task-detail-header",children:[a.jsx("span",{className:`mobile-task-status-badge status-${p.status}`,children:dl[p.status]||p.status}),a.jsx("span",{className:`mobile-task-priority priority-${p.priority}`,children:p.priority})]}),a.jsx("h3",{className:"mobile-task-detail-title",children:p.title}),p.description&&a.jsx("p",{className:"mobile-task-detail-desc",children:p.description}),a.jsxs("div",{className:"mobile-task-detail-meta",children:[p.assignee&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Assignee"}),a.jsxs("span",{children:["@",p.assignee]})]}),p.dueDate&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Due"}),a.jsx("span",{children:new Date(p.dueDate).toLocaleDateString()})]}),p.timeSpent!=null&&a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Time spent"}),a.jsxs("span",{children:[Math.round(p.timeSpent/6e4),"min"]})]}),(fe=p.dependencies)!=null&&fe.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Dependencies"}),a.jsx("span",{children:p.dependencies.length})]}):null,(Ye=p.comments)!=null&&Ye.length?a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Comments"}),a.jsx("span",{children:p.comments.length})]}):null,a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Created"}),a.jsx("span",{children:jr(p.createdAt)})]}),a.jsxs("div",{className:"mobile-task-detail-row",children:[a.jsx("span",{children:"Updated"}),a.jsx("span",{children:jr(p.updatedAt)})]})]})]})}),a.jsx(PC,{open:S,onClose:()=>y(!1),onCreate:ye,agents:E}),a.jsx(_t,{open:!!g,onClose:()=>{v(null),P(""),T(null)},title:(M==null?void 0:M.name)||"Artifact",actions:C.length>1?a.jsx("div",{className:"mobile-task-detail-actions",children:C.map((B,ie)=>a.jsxs("button",{type:"button",className:"mobile-btn mobile-btn-secondary",style:{flex:1},onClick:()=>{j(!0),Promise.all([Q.get(`/artifacts/${encodeURIComponent(B)}`),fetch(Q.urlWithToken(`/artifacts/${encodeURIComponent(B)}/content`)).then(re=>re.text())]).then(([re,be])=>{T(re),P(be),j(!1)}).catch(()=>j(!1))},children:["Artifact ",ie+1]},B))}):null,children:a.jsx("div",{className:"mobile-artifact-viewer",children:k?a.jsx("div",{className:"mobile-loading",children:a.jsx("p",{children:"Loading artifact…"})}):N?a.jsx("iframe",{srcDoc:N,className:"mobile-artifact-iframe",sandbox:"allow-scripts allow-forms allow-popups allow-same-origin",title:(M==null?void 0:M.name)||"Artifact",loading:"lazy"}):a.jsxs("div",{className:"mobile-empty",children:[a.jsx(Gn,{size:32}),a.jsx("p",{className:"muted",children:"No artifact content available."})]})})})]})}function IC(e){var t,n;return((n=(t=e.settings)==null?void 0:t.data)==null?void 0:n.defaultAgent)||"odin"}function PC({open:e,onClose:t,onCreate:n,agents:r}){const[i,l]=b.useState(""),[s,o]=b.useState(""),[u,d]=b.useState(""),[c,f]=b.useState("normal"),h=m=>{m.preventDefault(),i.trim()&&(n(i.trim(),s.trim(),u,c),l(""),o(""),d(""),f("normal"))};return a.jsx(Tn,{open:e,onClose:t,title:"New Task",actions:a.jsxs("button",{type:"submit",form:"new-task-form",className:"mobile-btn",style:{width:"100%"},children:[a.jsx(yt,{size:14})," Create Task"]}),children:a.jsxs("form",{id:"new-task-form",onSubmit:h,className:"mobile-task-form",children:[a.jsx("label",{className:"mobile-field-label",children:"Title *"}),a.jsx("input",{className:"mobile-input",type:"text",placeholder:"Task title",value:i,onChange:m=>l(m.target.value),autoFocus:!0,required:!0}),a.jsx("label",{className:"mobile-field-label",children:"Description"}),a.jsx("textarea",{className:"mobile-input",rows:3,placeholder:"Optional description",value:s,onChange:m=>o(m.target.value)}),a.jsx("label",{className:"mobile-field-label",children:"Assignee"}),a.jsxs("select",{className:"mobile-input",value:u,onChange:m=>d(m.target.value),children:[a.jsx("option",{value:"",children:"Unassigned"}),r.map(m=>a.jsxs("option",{value:m.name,children:["@",m.name]},m.name))]}),a.jsx("label",{className:"mobile-field-label",children:"Priority"}),a.jsxs("select",{className:"mobile-input",value:c,onChange:m=>f(m.target.value),children:[a.jsx("option",{value:"low",children:"Low"}),a.jsx("option",{value:"normal",children:"Normal"}),a.jsx("option",{value:"high",children:"High"})]})]})})}const AC=[{id:"activity",label:"Activity",icon:ma},{id:"chat",label:"Chat",icon:Bn},{id:"tasks",label:"Tasks",icon:es},{id:"settings",label:"Settings",icon:Dm},{id:"more",label:"More",icon:Y1}];function MC(e){const t=e.meta??{},n=typeof t.taskId=="string"?t.taskId:null,r=typeof t.slug=="string"?t.slug:null,i=typeof t.agent=="string"?t.agent:null;if(n)return{id:"task-detail",taskId:n};if(r)return{id:"artifacts?-detail",slug:r};if(i)return{id:"agent-detail",name:i};const l=e.link??"";return l.startsWith("/artifacts?/")?{id:"artifacts?-detail",slug:decodeURIComponent(l.slice(12))}:l.startsWith("/tasks/")?{id:"task-detail",taskId:decodeURIComponent(l.slice(7))}:l.startsWith("/agents/")?{id:"agent-detail",name:decodeURIComponent(l.slice(8))}:null}function HC(){const[e,t]=b.useState("activity"),[n,r]=b.useState([]),[i,l]=b.useState(!1),[s,o]=b.useState(null),[u,d]=b.useState(null),[c,f]=b.useState(null),[h,m]=b.useState(null),[p,x]=b.useState(!0),[S,y]=b.useState(0),g=b.useMemo(()=>n[n.length-1]??{id:e},[e,n]),v=b.useCallback(k=>{r(j=>[...j,k])},[]),C=b.useCallback(()=>{r(k=>k.slice(0,-1))},[]),z=b.useCallback(k=>{r([]),t(k)},[]),N=b.useCallback(async()=>{var k;try{const j=await Q.get("/snapshot");d(j),(k=j.settings)!=null&&k.data&&f(j.settings.data),m(null)}catch(j){throw m(j.message||"Dashboard server unreachable."),j}},[]);b.useEffect(()=>{let k=!1;return Promise.all([Q.get("/snapshot").catch(()=>null),Q.get("/settings").catch(()=>null),Q.probeAuthStatus().catch(()=>null)]).then(([j,I])=>{var H;if(k)return;const $=(I==null?void 0:I.data)??((H=j==null?void 0:j.settings)==null?void 0:H.data)??null;j&&d(j),$&&f($),m(!j&&!$?"Dashboard server unreachable.":null)}).catch(j=>{k||m(j.message||"Dashboard server unreachable.")}).finally(()=>{k||x(!1)}),()=>{k=!0}},[]),b.useEffect(()=>{c!=null&&c.theme&&(ns(c.theme),fi(c.theme))},[c==null?void 0:c.theme]),b.useEffect(()=>{var I;if(((I=c==null?void 0:c.theme)==null?void 0:I.mode)!=="system")return;const k=window.matchMedia("(prefers-color-scheme: light)"),j=()=>{c!=null&&c.theme&&(ns(c.theme),fi(c.theme))};return k.addEventListener("change",j),()=>k.removeEventListener("change",j)},[c==null?void 0:c.theme]),b.useEffect(()=>{const k=()=>{y(I=>I+1),N().catch(()=>{})},j=()=>{document.visibilityState==="visible"&&k()};return window.addEventListener("online",k),window.addEventListener("pageshow",k),document.addEventListener("visibilitychange",j),()=>{window.removeEventListener("online",k),window.removeEventListener("pageshow",k),document.removeEventListener("visibilitychange",j)}},[N]),b.useEffect(()=>{const k=new Fm,j=k.on(I=>{if(I.type==="snapshot"&&"data"in I&&I.data)d($=>({...$??{},...I.data}));else if(I.type==="change")N().catch(()=>{});else if(I.type==="tasks:change"){const $=I.task;d(H=>{if(!H)return H;const L=(H.tasks||[]).map(J=>J.id===$.id?$:J),te=L.some(J=>J.id===$.id);return{...H,tasks:te?L:[$,...L]}})}else I.type==="tasks:delete"?d($=>$&&{...$,tasks:($.tasks||[]).filter(H=>H.id!==I.id)}):I.type==="settings:change"?I.settings&&f(I.settings):I.type==="project:change"||I.type==="agents:change"||I.type==="schedules:change"||I.type==="artifact:change"?N().catch(()=>{}):(I.type==="agent:status"||I.type==="agent:restarted")&&d($=>{if(!$)return $;const H=($.agents||[]).map(L=>L.name===I.agent.name?I.agent:L);return{...$,agents:H}})});return()=>{j(),k.close()}},[N,S]);const P=b.useCallback(k=>{(k==="activity"||k==="chat"||k==="tasks"||k==="settings"||k==="more")&&z(k)},[z]),M=b.useCallback((k,j,I)=>{if(k==="notification"){const $=MC({link:j||null,meta:I??null});$&&v($);return}if(k==="task"&&j){v({id:"task-detail",taskId:j});return}if(k==="artifacts?"&&j){v({id:"artifacts?-detail",slug:j});return}if(k==="agent"&&j){v({id:"agent-detail",name:j});return}if(k==="project"){z("activity");return}k==="setting"&&z("settings")},[z,v]),T=()=>{if(!u||!c)return null;if(n.length>0){const k=n[n.length-1];switch(k.id){case"artifacts?":return a.jsx(oC,{snapshot:u,onBack:C,onOpenArtifact:j=>v({id:"artifacts?-detail",slug:j})});case"agents":return a.jsx(df,{snapshot:u,onBack:C,onOpenAgent:j=>v({id:"agent-detail",name:j}),onRefresh:N});case"skills":return a.jsx(NC,{snapshot:u,onBack:C});case"mods":return a.jsx(tC,{snapshot:u,onBack:C});case"schedules":return a.jsx(fC,{snapshot:u,onBack:C});case"history":return a.jsx(eC,{onBack:C});case"config":return a.jsx(J2,{onBack:C});case"artifacts?-detail":return a.jsx(iC,{slug:k.slug,onBack:C});case"agent-detail":return a.jsx(df,{snapshot:u,onBack:C,onOpenAgent:()=>{},onRefresh:N,selectedAgent:k.name});case"task-detail":return a.jsx(yf,{snapshot:u,onRefresh:N,selectedTaskId:k.taskId,onCloseDetail:C,onOpenChat:j=>{o(j),z("chat")}});default:return null}}switch(e){case"activity":return a.jsx(Q2,{snapshot:u,onRefresh:N});case"chat":return a.jsx(Z2,{snapshot:u,settings:c,initialTaskId:s,onClearTaskId:()=>o(null)});case"tasks":return a.jsx(yf,{snapshot:u,onRefresh:N,onOpenChat:k=>{o(k),z("chat")}});case"settings":return a.jsx(CC,{settings:c,snapshot:u,onRefresh:N});case"more":return a.jsx(nC,{snapshot:u,onNavigate:k=>{(k==="artifacts?"||k==="agents"||k==="skills"||k==="mods"||k==="schedules"||k==="history"||k==="config")&&v({id:k})}});default:return null}};return p?a.jsxs("div",{className:"mobile-loading",children:[a.jsx($m,{size:"lg"}),a.jsx("p",{children:"Loading Bizar…"})]}):h||!u||!c?a.jsxs("div",{className:"mobile-loading",children:[a.jsx("h2",{children:"Dashboard unavailable"}),a.jsx("p",{children:h||"Dashboard server unreachable."}),a.jsx("p",{className:"muted",children:"Make sure the Bizar dashboard server is running."})]}):a.jsxs("div",{className:"mobile-app",children:[a.jsx(V2,{activeTab:g.id,snapshot:u,onSearch:()=>l(!0),onNavigate:M}),a.jsx("main",{className:"mobile-content",children:T()}),n.length===0&&a.jsx(F2,{tabs:AC,activeTab:e,onChange:P}),n.length>0&&a.jsx("button",{type:"button",className:"mobile-back-btn",onClick:C,"aria-label":"Go back",children:"← Back"}),a.jsx(kC,{open:i,onClose:()=>l(!1),onNavigate:M})]})}export{F1 as $,ma as A,Or as B,U1 as C,ax as D,Cx as E,Nu as F,E2 as G,ga as H,G1 as I,z2 as J,Sx as K,k2 as L,Bn as M,Lm as N,RC as O,yt as P,Zl as Q,Ot as R,es as S,ux as T,Am as U,ix as V,od as W,tr as X,lb as Y,x2 as Z,Ae as _,Q as a,hx as a0,OC as a1,dx as a2,ld as a3,Gn as a4,ex as a5,_C as a6,DC as a7,fi as a8,rx as a9,J1 as aa,ox as ab,Z1 as ac,Q1 as ad,ns as ae,Fm as af,sx as ag,rg as ah,nx as ai,$1 as aj,N2 as ak,W1 as al,$C as am,FC as an,R1 as ao,HC as ap,Cs as b,X as c,id as d,Jl as e,pa as f,Mr as g,sd as h,Eu as i,a as j,ts as k,yx as l,rd as m,H1 as n,jr as o,$m as p,Rm as q,b as r,cx as s,$i as t,px as u,Mm as v,Im as w,q1 as x,S2 as y,lx as z};
354
+ //# sourceMappingURL=mobile-Dl1q7Cyq.js.map