function Te(e,a){for(var s=0;s<a.length;s++){const r=a[s];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const d=Object.getOwnPropertyDescriptor(r,i);d&&Object.defineProperty(e,i,d.get?d:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var Wt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ce(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var K={exports:{}},q={};/**
 * @license React
 * react-jsx-runtime.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var ae;function Ee(){if(ae)return q;ae=1;var e=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function s(r,i,d){var u=null;if(d!==void 0&&(u=""+d),i.key!==void 0&&(u=""+i.key),"key"in i){d={};for(var h in i)h!=="key"&&(d[h]=i[h])}else d=i;return i=d.ref,{$$typeof:e,type:r,key:u,ref:i!==void 0?i:null,props:d}}return q.Fragment=a,q.jsx=s,q.jsxs=s,q}var re;function $e(){return re||(re=1,K.exports=Ee()),K.exports}var t=$e(),z={exports:{}},$={};/**
 * @license React
 * react.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var ie;function Ae(){if(ie)return $;ie=1;var e=Symbol.for("react.transitional.element"),a=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),u=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),b=Symbol.for("react.suspense"),y=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),o=Symbol.for("react.activity"),c=Symbol.iterator;function p(n){return n===null||typeof n!="object"?null:(n=c&&n[c]||n["@@iterator"],typeof n=="function"?n:null)}var f={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},v=Object.assign,x={};function S(n,j,R){this.props=n,this.context=j,this.refs=x,this.updater=R||f}S.prototype.isReactComponent={},S.prototype.setState=function(n,j){if(typeof n!="object"&&typeof n!="function"&&n!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,n,j,"setState")},S.prototype.forceUpdate=function(n){this.updater.enqueueForceUpdate(this,n,"forceUpdate")};function g(){}g.prototype=S.prototype;function N(n,j,R){this.props=n,this.context=j,this.refs=x,this.updater=R||f}var w=N.prototype=new g;w.constructor=N,v(w,S.prototype),w.isPureReactComponent=!0;var T=Array.isArray;function k(){}var C={H:null,A:null,T:null,S:null},E=Object.prototype.hasOwnProperty;function I(n,j,R){var A=R.ref;return{$$typeof:e,type:n,key:j,ref:A!==void 0?A:null,props:R}}function U(n,j){return I(n.type,j,n.props)}function F(n){return typeof n=="object"&&n!==null&&n.$$typeof===e}function Ne(n){var j={"=":"=0",":":"=2"};return"$"+n.replace(/[=:]/g,function(R){return j[R]})}var se=/\/+/g;function W(n,j){return typeof n=="object"&&n!==null&&n.key!=null?Ne(""+n.key):j.toString(36)}function we(n){switch(n.status){case"fulfilled":return n.value;case"rejected":throw n.reason;default:switch(typeof n.status=="string"?n.then(k,k):(n.status="pending",n.then(function(j){n.status==="pending"&&(n.status="fulfilled",n.value=j)},function(j){n.status==="pending"&&(n.status="rejected",n.reason=j)})),n.status){case"fulfilled":return n.value;case"rejected":throw n.reason}}throw n}function J(n,j,R,A,_){var P=typeof n;(P==="undefined"||P==="boolean")&&(n=null);var O=!1;if(n===null)O=!0;else switch(P){case"bigint":case"string":case"number":O=!0;break;case"object":switch(n.$$typeof){case e:case a:O=!0;break;case m:return O=n._init,J(O(n._payload),j,R,A,_)}}if(O)return _=_(n),O=A===""?"."+W(n,0):A,T(_)?(R="",O!=null&&(R=O.replace(se,"$&/")+"/"),J(_,j,R,"",function(ke){return ke})):_!=null&&(F(_)&&(_=U(_,R+(_.key==null||n&&n.key===_.key?"":(""+_.key).replace(se,"$&/")+"/")+O)),j.push(_)),1;O=0;var M=A===""?".":A+":";if(T(n))for(var L=0;L<n.length;L++)A=n[L],P=M+W(A,L),O+=J(A,j,R,P,_);else if(L=p(n),typeof L=="function")for(n=L.call(n),L=0;!(A=n.next()).done;)A=A.value,P=M+W(A,L++),O+=J(A,j,R,P,_);else if(P==="object"){if(typeof n.then=="function")return J(we(n),j,R,A,_);throw j=String(n),Error("Objects are not valid as a React child (found: "+(j==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":j)+"). If you meant to render a collection of children, use an array instead.")}return O}function G(n,j,R){if(n==null)return n;var A=[],_=0;return J(n,A,"","",function(P){return j.call(R,P,_++)}),A}function ve(n){if(n._status===-1){var j=n._result;j=j(),j.then(function(R){(n._status===0||n._status===-1)&&(n._status=1,n._result=R)},function(R){(n._status===0||n._status===-1)&&(n._status=2,n._result=R)}),n._status===-1&&(n._status=0,n._result=j)}if(n._status===1)return n._result.default;throw n._result}var ne=typeof reportError=="function"?reportError:function(n){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var j=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof n=="object"&&n!==null&&typeof n.message=="string"?String(n.message):String(n),error:n});if(!window.dispatchEvent(j))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",n);return}console.error(n)},Se={map:G,forEach:function(n,j,R){G(n,function(){j.apply(this,arguments)},R)},count:function(n){var j=0;return G(n,function(){j++}),j},toArray:function(n){return G(n,function(j){return j})||[]},only:function(n){if(!F(n))throw Error("React.Children.only expected to receive a single React element child.");return n}};return $.Activity=o,$.Children=Se,$.Component=S,$.Fragment=s,$.Profiler=i,$.PureComponent=N,$.StrictMode=r,$.Suspense=b,$.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=C,$.__COMPILER_RUNTIME={__proto__:null,c:function(n){return C.H.useMemoCache(n)}},$.cache=function(n){return function(){return n.apply(null,arguments)}},$.cacheSignal=function(){return null},$.cloneElement=function(n,j,R){if(n==null)throw Error("The argument must be a React element, but you passed "+n+".");var A=v({},n.props),_=n.key;if(j!=null)for(P in j.key!==void 0&&(_=""+j.key),j)!E.call(j,P)||P==="key"||P==="__self"||P==="__source"||P==="ref"&&j.ref===void 0||(A[P]=j[P]);var P=arguments.length-2;if(P===1)A.children=R;else if(1<P){for(var O=Array(P),M=0;M<P;M++)O[M]=arguments[M+2];A.children=O}return I(n.type,_,A)},$.createContext=function(n){return n={$$typeof:u,_currentValue:n,_currentValue2:n,_threadCount:0,Provider:null,Consumer:null},n.Provider=n,n.Consumer={$$typeof:d,_context:n},n},$.createElement=function(n,j,R){var A,_={},P=null;if(j!=null)for(A in j.key!==void 0&&(P=""+j.key),j)E.call(j,A)&&A!=="key"&&A!=="__self"&&A!=="__source"&&(_[A]=j[A]);var O=arguments.length-2;if(O===1)_.children=R;else if(1<O){for(var M=Array(O),L=0;L<O;L++)M[L]=arguments[L+2];_.children=M}if(n&&n.defaultProps)for(A in O=n.defaultProps,O)_[A]===void 0&&(_[A]=O[A]);return I(n,P,_)},$.createRef=function(){return{current:null}},$.forwardRef=function(n){return{$$typeof:h,render:n}},$.isValidElement=F,$.lazy=function(n){return{$$typeof:m,_payload:{_status:-1,_result:n},_init:ve}},$.memo=function(n,j){return{$$typeof:y,type:n,compare:j===void 0?null:j}},$.startTransition=function(n){var j=C.T,R={};C.T=R;try{var A=n(),_=C.S;_!==null&&_(R,A),typeof A=="object"&&A!==null&&typeof A.then=="function"&&A.then(k,ne)}catch(P){ne(P)}finally{j!==null&&R.types!==null&&(j.types=R.types),C.T=j}},$.unstable_useCacheRefresh=function(){return C.H.useCacheRefresh()},$.use=function(n){return C.H.use(n)},$.useActionState=function(n,j,R){return C.H.useActionState(n,j,R)},$.useCallback=function(n,j){return C.H.useCallback(n,j)},$.useContext=function(n){return C.H.useContext(n)},$.useDebugValue=function(){},$.useDeferredValue=function(n,j){return C.H.useDeferredValue(n,j)},$.useEffect=function(n,j){return C.H.useEffect(n,j)},$.useEffectEvent=function(n){return C.H.useEffectEvent(n)},$.useId=function(){return C.H.useId()},$.useImperativeHandle=function(n,j,R){return C.H.useImperativeHandle(n,j,R)},$.useInsertionEffect=function(n,j){return C.H.useInsertionEffect(n,j)},$.useLayoutEffect=function(n,j){return C.H.useLayoutEffect(n,j)},$.useMemo=function(n,j){return C.H.useMemo(n,j)},$.useOptimistic=function(n,j){return C.H.useOptimistic(n,j)},$.useReducer=function(n,j,R){return C.H.useReducer(n,j,R)},$.useRef=function(n){return C.H.useRef(n)},$.useState=function(n){return C.H.useState(n)},$.useSyncExternalStore=function(n,j,R){return C.H.useSyncExternalStore(n,j,R)},$.useTransition=function(){return C.H.useTransition()},$.version="19.2.7",$}var le;function Re(){return le||(le=1,z.exports=Ae()),z.exports}var l=Re();const _e=Ce(l),Kt=Te({__proto__:null,default:_e},[l]);let te=null;function zt(e){te=e??null}function D(e,a={}){const s={...a.headers||{}};return te&&(s["X-Compose-Workspace-Id"]=te),fetch(e,{...a,headers:s})}const Pe="";let pe=null;function oe(e){pe=e||null}function Ie(){return pe||Pe||""}function Y(e={}){const a=Ie();return a?{...e,"x-compose-token":a}:e}const Oe=[{id:"agents",label:"Agents",icon:"◇"},{id:"roadmap",label:"Roadmap",icon:"⚡"},{id:"builds",label:"Builds",icon:"⏵"},{id:"ideas",label:"Ideas",icon:"✦"}];function Le({active:e,onSelect:a}){return t.jsx("nav",{className:"m-bottom-nav",role:"tablist","aria-label":"Mobile navigation",children:Oe.map(s=>t.jsxs("button",{type:"button",className:"m-nav-btn",role:"tab","aria-pressed":e===s.id?"true":"false","aria-label":s.label,"data-tab":s.id,"data-testid":`mobile-nav-${s.id}`,onClick:()=>a(s.id),children:[t.jsx("span",{className:"m-nav-icon","aria-hidden":"true",children:s.icon}),t.jsx("span",{className:"m-nav-label",children:s.label})]},s.id))})}async function Me(e,a={}){const s=await D(e,a);let r=null;try{r=await s.json()}catch{}if(!s.ok){const i=r&&r.error||`HTTP ${s.status}`;throw new Error(i)}return r}function De(){const[e,a]=l.useState([]),[s,r]=l.useState(!0),[i,d]=l.useState(null),u=l.useRef(!0),h=l.useCallback(async()=>{try{const b=await Me("/api/agents/tree");if(!u.current)return;a(Array.isArray(b==null?void 0:b.agents)?b.agents:[]),d(null)}catch(b){if(!u.current)return;d(b.message)}finally{u.current&&r(!1)}},[]);return l.useEffect(()=>(u.current=!0,h(),()=>{u.current=!1}),[h]),l.useEffect(()=>{if(typeof window>"u"||typeof WebSocket>"u")return;let b=null,y=!1,m=null;function o(){if(!y){try{const p=window.location.protocol==="https:"?"wss:":"ws:";b=new WebSocket(`${p}//${window.location.host}/ws/vision`)}catch{c();return}b.onmessage=p=>{try{const f=JSON.parse(p.data);if(!f||!f.type)return;(f.type==="agentSpawned"||f.type==="agentStopped"||f.type==="agentStatusChanged"||f.type==="agentTreeUpdated")&&h()}catch{}},b.onclose=()=>{y||c()},b.onerror=()=>{try{b.close()}catch{}}}}function c(){m&&clearTimeout(m),m=setTimeout(o,3e3)}return o(),()=>{y=!0,m&&clearTimeout(m);try{b&&(b.onclose=null,b.close())}catch{}}},[h]),{agents:e,loading:s,error:i,refetch:h}}async function ce(e,a={}){const s=await D(e,a);let r=null;try{r=await s.json()}catch{}if(!s.ok){const i=r&&r.error||`HTTP ${s.status}`;throw new Error(i)}return r}function Ue(){const[e,a]=l.useState([]),[s,r]=l.useState(!0),[i,d]=l.useState(null),u=l.useRef(!0),h=l.useCallback(async()=>{try{const y=await ce("/api/vision/gates");if(!u.current)return;a(Array.isArray(y==null?void 0:y.gates)?y.gates:[]),d(null)}catch(y){if(!u.current)return;d(y.message)}finally{u.current&&r(!1)}},[]);l.useEffect(()=>(u.current=!0,h(),()=>{u.current=!1}),[h]),l.useEffect(()=>{if(typeof window>"u"||typeof WebSocket>"u")return;let y=null,m=!1,o=null;function c(){if(!m){try{const f=window.location.protocol==="https:"?"wss:":"ws:";y=new WebSocket(`${f}//${window.location.host}/ws/vision`)}catch{p();return}y.onmessage=f=>{try{const v=JSON.parse(f.data);if(!v||!v.type)return;(v.type==="gateCreated"||v.type==="gateResolved"||v.type==="gateUpdated")&&h()}catch{}},y.onclose=()=>{m||p()},y.onerror=()=>{try{y.close()}catch{}}}}function p(){o&&clearTimeout(o),o=setTimeout(c,3e3)}return c(),()=>{m=!0,o&&clearTimeout(o);try{y&&(y.onclose=null,y.close())}catch{}}},[h]);const b=l.useCallback(async(y,{outcome:m,reason:o,summary:c}={})=>{if(!["approve","revise","kill"].includes(m))throw new Error(`outcome must be approve|revise|kill (got ${m})`);const p=[];o&&p.push(o),c&&p.push(c);const f=p.join(" — ")||void 0,v={outcome:m};f&&(v.comment=f);const x=await ce(`/api/vision/gates/${encodeURIComponent(y)}/resolve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});return h(),x},[h]);return{gates:e,loading:s,error:i,refetch:h,resolve:b}}const X={},Fe=typeof import.meta<"u"&&(X==null?void 0:X.VITE_AGENT_PORT)||"4002",He=5e3;function be(e){return typeof window>"u"||!window.location?e:`${window.location.protocol}//${window.location.hostname}:${Fe}${e}`}async function ue(e,a){const s=await fetch(be(e),{method:"POST",headers:Y({"Content-Type":"application/json"}),body:JSON.stringify(a||{})});let r=null;try{r=await s.json()}catch{}if(!s.ok){const i=r&&r.error||`HTTP ${s.status}`;throw new Error(i)}return r}function Je(){const[e,a]=l.useState(!1),[s,r]=l.useState(null),[i,d]=l.useState(!0),[u,h]=l.useState(null),[b,y]=l.useState(!1),m=l.useRef(!0),o=l.useCallback(async()=>{try{const v=await(await fetch(be("/api/agent/session/status"))).json().catch(()=>({}));if(!m.current)return;a(!!v.active),r(v.sessionId||null),h(null)}catch(f){if(!m.current)return;h(f.message)}finally{m.current&&d(!1)}},[]);l.useEffect(()=>{m.current=!0,o();const f=setInterval(o,He);return()=>{m.current=!1,clearInterval(f)}},[o]);const c=l.useCallback(async f=>{const v=(f||"").trim();if(!v)throw new Error("message is empty");y(!0);try{const S=await ue(s?"/api/agent/message":"/api/agent/session",{prompt:v});return o(),S}finally{y(!1)}},[s,o]),p=l.useCallback(async()=>ue("/api/agent/interrupt",{}),[]);return{active:e,sessionId:s,loading:i,error:u,sending:b,sendMessage:c,interrupt:p,refresh:o}}const V={},qe=typeof import.meta<"u"&&(V==null?void 0:V.VITE_AGENT_PORT)||"4002";function Be(e){return typeof window>"u"||!window.location?e:`${window.location.protocol}//${window.location.hostname}:${qe}${e}`}function Ye(e){if(!e)return"";const a=typeof e=="string"?Date.parse(e):Number(e);if(!a||Number.isNaN(a))return"";const s=Date.now()-a;return s<5e3?"just now":s<6e4?`${Math.floor(s/1e3)}s ago`:s<36e5?`${Math.floor(s/6e4)}m ago`:`${Math.floor(s/36e5)}h ago`}function Ge({agent:e,onOpen:a,onAfterKill:s}){const[r,i]=l.useState(!1),[d,u]=l.useState(null),h=e.agentId||e.id,b=e.status||"unknown",y=e.lastActivityAt||e.lastEventAt||e.startedAt||null,m=l.useCallback(async c=>{if(c==null||c.stopPropagation(),!!h){i(!0),u(null);try{const p=await D(Be(`/api/agent/${encodeURIComponent(h)}/stop`),{method:"POST",headers:Y({"Content-Type":"application/json"}),body:JSON.stringify({})});if(!p.ok){let f=null;try{f=await p.json()}catch{}throw new Error(f&&f.error||`HTTP ${p.status}`)}s==null||s(h)}catch(p){u(p.message)}finally{i(!1)}}},[h,s]),o=l.useCallback(()=>a==null?void 0:a(e),[a,e]);return t.jsxs("div",{className:"m-agent-card","data-testid":`mobile-agent-card-${h}`,role:"button",tabIndex:0,onClick:o,onKeyDown:c=>{c.key==="Enter"&&o()},children:[t.jsxs("div",{className:"m-agent-card-row",children:[t.jsx("div",{className:"m-agent-card-id",title:h,children:h||"(no id)"}),t.jsx("span",{className:"m-status-pill","data-status":b,children:b})]}),t.jsxs("div",{className:"m-agent-card-meta",children:[t.jsx("span",{className:"m-agent-card-time",children:Ye(y)}),t.jsx("button",{type:"button",className:"m-btn m-btn-danger m-btn-sm","data-testid":`mobile-agent-kill-${h}`,disabled:r||b!=="running",onClick:m,children:r?"Killing…":"Kill"})]}),d&&t.jsx("div",{className:"m-agent-card-error",children:d})]})}const Q={};function We(e){if(typeof window>"u"||!window.location)return e;const a=typeof import.meta<"u"&&(Q==null?void 0:Q.VITE_AGENT_PORT)||"4002";return`${window.location.protocol}//${window.location.hostname}:${a}${e}`}const Ke=3e4,ze=5,Xe=3e4;function Ve({url:e,onEvent:a,onOpen:s,onClose:r,onError:i,onRetry:d,onStall:u,onExhausted:h,namedEvents:b=["hydrate"],maxBackoffMs:y=Ke,maxRetries:m=ze,stallTimeoutMs:o=Xe}){if(!e)throw new Error("createAgentStream: url is required");if(typeof EventSource>"u")return{close(){}};let c=null,p=!1,f=0,v=null,x=null;function S(){x&&clearTimeout(x),!p&&(x=setTimeout(()=>{u==null||u({elapsedMs:o})},o))}function g(){x&&(clearTimeout(x),x=null)}function N(k,C){if(S(),!!a)try{const E=JSON.parse(C);a(E,k)}catch{}}function w(){if(g(),p||v)return;if(f>=m){const C=new Error(`agent-stream: failed after ${m} retries`);i==null||i(C),p=!0;try{c==null||c.close()}catch{}c=null,r==null||r(),h==null||h();return}const k=Math.min(y,1e3*Math.pow(2,f));f+=1,d==null||d({attempt:f,maxRetries:m,nextBackoffMs:k}),v=setTimeout(()=>{v=null,T()},k)}function T(){if(!p){try{c=new EventSource(e)}catch(k){i==null||i(k),w();return}c.onopen=()=>{f=0,g(),s==null||s()},c.onmessage=k=>N("message",k.data);for(const k of b)c.addEventListener(k,C=>N(k,C.data));c.onerror=k=>{i==null||i(k instanceof Error?k:new Error("agent-stream error"));try{c==null||c.close()}catch{}c=null,r==null||r(),w()}}}return T(),{close(){p=!0,g(),v&&(clearTimeout(v),v=null);try{c==null||c.close()}catch{}c=null},reconnect(){p=!1,f=0,g(),v&&(clearTimeout(v),v=null);try{c==null||c.close()}catch{}c=null,T()}}}function Qe(){return typeof window>"u"||!window.location?"":We("/api/agent/stream")}function Ze(e){return!e||typeof e!="object"?null:e.agentId||e.agent_id||e.id||null}function ye({url:e,agentId:a,max:s=500,enabled:r=!0}={}){const[i,d]=l.useState([]),[u,h]=l.useState(!1),b=l.useRef(null),y=l.useMemo(()=>e||Qe(),[e]);return l.useEffect(()=>{if(!r||!y)return;const o=Ve({url:y,onOpen:()=>h(!0),onClose:()=>h(!1),onEvent:c=>{d(p=>{const f=p.length>=s?p.slice(p.length-s+1):p.slice();return f.push(c),f})}});return b.current=o,()=>{try{o.close()}catch{}}},[y,r,s]),{events:l.useMemo(()=>a?i.filter(o=>Ze(o)===a):i,[i,a]),allEvents:i,connected:u}}const Z={},et=typeof import.meta<"u"&&(Z==null?void 0:Z.VITE_AGENT_PORT)||"4002";function tt(e){return typeof window>"u"||!window.location?e:`${window.location.protocol}//${window.location.hostname}:${et}${e}`}function st(e,a){if(typeof e=="string")return e;if(e!=null&&e.type&&(e!=null&&e.message))return`[${e.type}] ${typeof e.message=="string"?e.message:JSON.stringify(e.message)}`;if(e!=null&&e.type)return`[${e.type}] ${JSON.stringify(e).slice(0,240)}`;try{return JSON.stringify(e)}catch{return`(unserializable #${a})`}}function nt({agent:e,onClose:a}){const s=(e==null?void 0:e.agentId)||(e==null?void 0:e.id),{events:r}=ye({agentId:s}),i=l.useRef(null),[d,u]=l.useState(!1),[h,b]=l.useState(null);l.useEffect(()=>{var m;(m=i.current)==null||m.scrollIntoView({behavior:"smooth"})},[r.length]);const y=l.useCallback(async()=>{if(s){u(!0),b(null);try{const m=await D(tt(`/api/agent/${encodeURIComponent(s)}/stop`),{method:"POST",headers:Y({"Content-Type":"application/json"}),body:JSON.stringify({})});if(!m.ok){let o=null;try{o=await m.json()}catch{}throw new Error(o&&o.error||`HTTP ${m.status}`)}}catch(m){b(m.message)}finally{u(!1)}}},[s]);return e?t.jsxs("div",{className:"m-overlay","data-testid":"mobile-agent-detail",role:"dialog","aria-modal":"true",children:[t.jsxs("header",{className:"m-overlay-header",children:[t.jsxs("div",{className:"m-overlay-header-inner",children:[t.jsx("div",{className:"m-overlay-title",title:s,children:s}),t.jsx("span",{className:"m-status-pill","data-status":e.status,children:e.status||"unknown"})]}),t.jsxs("div",{className:"m-overlay-actions",children:[t.jsx("button",{type:"button",className:"m-btn m-btn-danger m-btn-sm",disabled:d,onClick:y,"data-testid":"mobile-agent-detail-kill",children:d?"Killing…":"Kill"}),t.jsx("button",{type:"button",className:"m-btn m-btn-sm",onClick:a,"data-testid":"mobile-agent-detail-close",children:"Close"})]})]}),t.jsxs("div",{className:"m-overlay-body m-agent-log",children:[r.length===0?t.jsx("div",{className:"m-empty",children:"No live events for this agent yet."}):r.map((m,o)=>t.jsx("div",{className:"m-agent-log-line",children:st(m,o)},o)),t.jsx("div",{ref:i})]}),h&&t.jsx("div",{className:"m-agent-card-error",children:h})]}):null}function at({session:e}){const{active:a,sessionId:s,sending:r,sendMessage:i}=e,[d,u]=l.useState(""),[h,b]=l.useState(null),y=l.useCallback(async m=>{if(m==null||m.preventDefault(),!!d.trim()){b(null);try{await i(d),u("")}catch(o){b(o.message)}}},[d,i]);return t.jsxs("div",{className:"m-session-card","data-testid":"mobile-interactive-session",children:[t.jsxs("div",{className:"m-session-card-row",children:[t.jsx("div",{className:"m-session-card-title",children:"Interactive session"}),t.jsx("span",{className:"m-status-pill","data-status":a?"in_progress":"planned",children:a?"active":"ready"})]}),t.jsx("div",{className:"m-session-card-id",children:s?`id: ${s}`:"No active session"}),t.jsxs("form",{className:"m-session-card-form",onSubmit:y,children:[t.jsx("input",{type:"text",className:"m-input",placeholder:a?"Message Claude…":"Start a new session…",value:d,onChange:m=>u(m.target.value),"data-testid":"mobile-interactive-session-input",disabled:r}),t.jsx("button",{type:"submit",className:"m-btn m-btn-primary m-btn-sm",disabled:r||!d.trim(),"data-testid":"mobile-interactive-session-send",children:r?"Sending…":"Send"})]}),h&&t.jsx("div",{className:"m-agent-card-error",children:h})]})}function rt({gate:e,onOpen:a}){const s=e.id,r=e.flowId||e.flow||"",i=e.stepId||e.step||"",d=e.summary||e.comment||"",u=e.toPhase||e.fromPhase||"";return t.jsxs("div",{className:"m-gate-card","data-testid":`mobile-gate-card-${s}`,role:"button",tabIndex:0,onClick:()=>a==null?void 0:a(e),onKeyDown:h=>{h.key==="Enter"&&(a==null||a(e))},children:[t.jsxs("div",{className:"m-gate-card-row",children:[t.jsx("div",{className:"m-gate-card-title",children:r||s}),u&&t.jsx("span",{className:"m-status-pill","data-status":"in_progress",children:u})]}),t.jsx("div",{className:"m-gate-card-step",children:i}),d&&t.jsx("div",{className:"m-gate-card-summary",children:d})]})}const it=[{id:"approve",label:"Approve",kind:"primary"},{id:"revise",label:"Revise",kind:"warn"},{id:"kill",label:"Kill",kind:"danger"}];function lt({gate:e,onResolve:a,onClose:s}){const[r,i]=l.useState(null),[d,u]=l.useState(""),[h,b]=l.useState(""),[y,m]=l.useState(!1),[o,c]=l.useState(null),p=l.useCallback(async f=>{if(f==null||f.preventDefault(),!r){c("Pick an outcome");return}if(r==="kill"&&!d.trim()){c("Reason is required when killing a gate");return}m(!0),c(null);try{await a(e.id,{outcome:r,reason:d.trim(),summary:h.trim()}),s==null||s()}catch(v){c(v.message)}finally{m(!1)}},[e,r,d,h,a,s]);return t.jsx("div",{className:"m-sheet-backdrop","data-testid":"mobile-gate-sheet",onClick:s,children:t.jsxs("div",{className:"m-sheet",role:"dialog","aria-modal":"true",onClick:f=>f.stopPropagation(),children:[t.jsxs("div",{className:"m-sheet-header",children:[t.jsx("div",{className:"m-sheet-title",children:"Resolve gate"}),t.jsxs("div",{className:"m-sheet-subtitle",children:[e.flowId,":",e.stepId]})]}),t.jsxs("form",{onSubmit:p,className:"m-sheet-body",children:[t.jsx("div",{className:"m-sheet-outcomes",role:"radiogroup","aria-label":"Outcome",children:it.map(f=>t.jsx("button",{type:"button",role:"radio","aria-checked":r===f.id,className:`m-btn m-btn-${f.kind} ${r===f.id?"m-btn-active":""}`,"data-testid":`mobile-gate-outcome-${f.id}`,onClick:()=>i(f.id),children:f.label},f.id))}),t.jsxs("label",{className:"m-field",children:[t.jsxs("span",{className:"m-field-label",children:["Reason ",r==="kill"?"(required)":"(optional)"]}),t.jsx("textarea",{className:"m-textarea","data-testid":"mobile-gate-reason",value:d,onChange:f=>u(f.target.value),rows:2})]}),t.jsxs("label",{className:"m-field",children:[t.jsx("span",{className:"m-field-label",children:"Summary (optional)"}),t.jsx("textarea",{className:"m-textarea","data-testid":"mobile-gate-summary",value:h,onChange:f=>b(f.target.value),rows:2})]}),o&&t.jsx("div",{className:"m-agent-card-error",children:o}),t.jsxs("div",{className:"m-sheet-actions",children:[t.jsx("button",{type:"button",className:"m-btn m-btn-sm",onClick:s,disabled:y,children:"Cancel"}),t.jsx("button",{type:"submit",className:"m-btn m-btn-primary m-btn-sm",disabled:y||!r,"data-testid":"mobile-gate-submit",children:y?"Submitting…":"Submit"})]})]})]})})}function ot(){const{agents:e,loading:a,refetch:s}=De(),{gates:r,loading:i,resolve:d}=Ue(),u=Je(),[h,b]=l.useState(null),[y,m]=l.useState(null),o=l.useCallback(()=>{s(),b(null)},[s]);return t.jsxs("section",{"data-testid":"mobile-tab-agents",className:"m-agents-tab",children:[t.jsxs("div",{className:"m-section","data-testid":"mobile-section-spawned",children:[t.jsx("h2",{className:"m-section-title",children:"Spawned agents"}),a?t.jsx("div",{className:"m-empty",children:"Loading agents…"}):e.length===0?t.jsx("div",{className:"m-empty",children:"No spawned agents."}):t.jsx("div",{className:"m-stack",children:e.map(c=>t.jsx(Ge,{agent:c,onOpen:b,onAfterKill:o},c.agentId||c.id))})]}),t.jsxs("div",{className:"m-section","data-testid":"mobile-section-session",children:[t.jsx("h2",{className:"m-section-title",children:"Interactive session"}),t.jsx(at,{session:u})]}),t.jsxs("div",{className:"m-section","data-testid":"mobile-section-gates",children:[t.jsx("h2",{className:"m-section-title",children:"Pending gates"}),i?t.jsx("div",{className:"m-empty",children:"Loading gates…"}):r.length===0?t.jsx("div",{className:"m-empty",children:"No pending gates."}):t.jsx("div",{className:"m-stack",children:r.map(c=>t.jsx(rt,{gate:c,onOpen:m},c.id))})]}),h&&t.jsx(nt,{agent:h,onClose:()=>b(null)}),y&&t.jsx(lt,{gate:y,onResolve:d,onClose:()=>m(null)})]})}function ct({url:e,onMessage:a,onOpen:s,onClose:r,onError:i,maxBackoffMs:d=3e4}){let u=null,h=0,b=!1,y=null;function m(){if(!b){try{u=new WebSocket(e)}catch(c){i==null||i(c),o();return}u.onopen=()=>{h=0,s==null||s(u)},u.onmessage=c=>a==null?void 0:a(c),u.onclose=()=>{r==null||r(),o()},u.onerror=c=>{i==null||i(c)}}}function o(){if(b||y)return;const c=Math.min(d,1e3*Math.pow(2,h++));y=setTimeout(()=>{y=null,m()},c)}return m(),{get socket(){return u},isOpen(){return(u==null?void 0:u.readyState)===1},send(c){(u==null?void 0:u.readyState)===1&&u.send(c)},close(){if(b=!0,y&&(clearTimeout(y),y=null),u){try{u.onclose=null,u.onerror=null,u.close()}catch{}u=null}}}}function ut(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/vision`}function dt(){const[e,a]=l.useState([]),[s,r]=l.useState(!0),[i,d]=l.useState(null),[u,h]=l.useState(!1),b=l.useRef(e);b.current=e;const y=l.useCallback(async()=>{try{const c=await(await D("/api/vision/items")).json(),p=Array.isArray(c==null?void 0:c.items)?c.items:Array.isArray(c)?c:[];a(p),d(null)}catch(o){d((o==null?void 0:o.message)||"Failed to load items")}finally{r(!1)}},[]);l.useEffect(()=>{let o=!1;y();const c=ct({url:ut(),onOpen:()=>{o||h(!0)},onClose:()=>{o||h(!1)},onMessage:p=>{var x,S;if(o)return;let f;try{f=JSON.parse(p.data)}catch{return}if(!f||typeof f!="object")return;const v=f.type;v==="itemUpdated"&&((x=f.item)!=null&&x.id)?a(g=>{const N=g.findIndex(T=>T.id===f.item.id);if(N===-1)return[...g,f.item];const w=g.slice();return w[N]={...w[N],...f.item},w}):v==="itemCreated"&&((S=f.item)!=null&&S.id)?a(g=>g.some(N=>N.id===f.item.id)?g:[...g,f.item]):v==="itemDeleted"&&f.id?a(g=>g.filter(N=>N.id!==f.id)):v==="state"&&Array.isArray(f.items)?a(f.items):(v==="visionUpdated"||v==="roadmapUpdated")&&y()}});return()=>{o=!0;try{c.close()}catch{}}},[y]);const m=l.useCallback(async(o,c)=>{if(!o||!c||typeof c!="object")return{ok:!1,error:"invalid patch"};const p=b.current;if(!p.find(x=>x.id===o))return{ok:!1,error:"item not found"};const v=p.map(x=>x.id===o?{...x,...c}:x);a(v);try{const x=await D(`/api/vision/items/${o}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)}),S=await x.json().catch(()=>({}));if(!x.ok)return a(p),{ok:!1,error:(S==null?void 0:S.error)||`HTTP ${x.status}`};const g=(S==null?void 0:S.item)||(S==null?void 0:S.updated)||null;return g&&g.id===o&&a(N=>N.map(w=>w.id===o?{...w,...g}:w)),{ok:!0,item:g||v.find(N=>N.id===o)}}catch(x){return a(p),{ok:!1,error:(x==null?void 0:x.message)||"Network error"}}},[]);return{items:e,loading:s,error:i,connected:u,refetch:y,applyOptimisticEdit:m}}const mt=[{value:"planned",label:"planned"},{value:"in_progress",label:"in progress"},{value:"blocked",label:"blocked"},{value:"complete",label:"complete"},{value:"parked",label:"parked"},{value:"killed",label:"killed"}];function ft({statuses:e=[],onToggleStatus:a,group:s="",groupOptions:r=[],onChangeGroup:i,keyword:d="",onChangeKeyword:u}){return t.jsxs("div",{className:"m-filter-bar","data-testid":"mobile-filter-bar",children:[t.jsx("div",{className:"m-filter-chips",role:"group","aria-label":"Status filter",children:mt.map(h=>{const b=e.includes(h.value);return t.jsx("button",{type:"button",className:"m-filter-chip","aria-pressed":b,"data-testid":`mobile-filter-status-${h.value}`,onClick:()=>a==null?void 0:a(h.value),children:h.label},h.value)})}),t.jsxs("div",{className:"m-filter-row",children:[t.jsxs("select",{className:"m-filter-select","data-testid":"mobile-filter-group",value:s,onChange:h=>i==null?void 0:i(h.target.value),"aria-label":"Group filter",children:[t.jsx("option",{value:"",children:"All groups"}),r.map(h=>t.jsx("option",{value:h,children:h},h))]}),t.jsx("input",{type:"search",className:"m-filter-keyword","data-testid":"mobile-filter-keyword",placeholder:"Search title or description",value:d,onChange:h=>u==null?void 0:u(h.target.value),"aria-label":"Keyword filter"})]})]})}const ht=new Set(["planned","in_progress","blocked","complete","partial","superseded","parked"]);function ge({status:e,children:a}){const s=typeof e=="string"?e.toLowerCase():"",r=ht.has(s)?s:"unknown",i=a??e??"unknown";return t.jsx("span",{className:"m-status-pill","data-status":r,children:i})}function pt(e,a=140){if(typeof e!="string")return"";const s=e.trim();return s.length<=a?s:s.slice(0,a-1).trimEnd()+"…"}function bt({item:e,onSelect:a}){if(!e)return null;const s=e.title||e.id||"Untitled",r=e.status||"unknown",i=e.group||"",d=pt(e.description||"");return t.jsxs("button",{type:"button",className:"m-item-card","data-testid":`mobile-item-card-${e.id}`,onClick:()=>a==null?void 0:a(e),children:[t.jsxs("div",{className:"m-item-card-row",children:[t.jsx("div",{className:"m-item-card-title",children:s}),t.jsx(ge,{status:r})]}),t.jsxs("div",{className:"m-item-card-meta",children:[i?t.jsx("span",{className:"m-item-card-group","data-testid":"mobile-item-group",children:i}):null,e.id?t.jsx("span",{className:"m-item-card-id",children:e.id}):null]}),d?t.jsx("div",{className:"m-item-card-desc",children:d}):null]})}const yt=["planned","in_progress","blocked","complete","partial","parked","killed","superseded"];function gt({item:e,onClose:a,onSave:s}){const r=l.useMemo(()=>({status:(e==null?void 0:e.status)||"planned",group:(e==null?void 0:e.group)||"",confidence:(e==null?void 0:e.confidence)??""}),[e]),[i,d]=l.useState(r.status),[u,h]=l.useState(r.group),[b,y]=l.useState(r.confidence),[m,o]=l.useState(!1);if(l.useEffect(()=>{d(r.status),h(r.group),y(r.confidence)},[e==null?void 0:e.id,r.status,r.group,r.confidence]),!e)return null;const c=i!==r.status||u!==r.group||String(b)!==String(r.confidence),p=async()=>{if(!c||m)return;const f={};if(i!==r.status&&(f.status=i),u!==r.group&&(f.group=u),String(b)!==String(r.confidence)){const v=b===""?null:Number(b);v!==null&&Number.isFinite(v)?f.confidence=v:b===""&&(f.confidence=null)}o(!0);try{await(s==null?void 0:s(e.id,f))}finally{o(!1)}};return t.jsx("div",{className:"m-sheet-overlay",role:"dialog","aria-modal":"true","data-testid":"mobile-item-sheet",children:t.jsxs("div",{className:"m-sheet",children:[t.jsxs("header",{className:"m-sheet-header",children:[t.jsx("button",{type:"button",className:"m-sheet-close",onClick:a,"data-testid":"mobile-item-sheet-close","aria-label":"Close",children:"×"}),t.jsxs("div",{className:"m-sheet-title-row",children:[t.jsx("div",{className:"m-sheet-title",children:e.title||e.id}),t.jsx(ge,{status:i})]})]}),t.jsxs("div",{className:"m-sheet-body",children:[e.description?t.jsxs("section",{className:"m-sheet-section",children:[t.jsx("div",{className:"m-sheet-label",children:"Description"}),t.jsx("p",{className:"m-sheet-desc",children:e.description})]}):null,t.jsxs("section",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-sheet-status",children:"Status"}),t.jsx("select",{id:"m-sheet-status",className:"m-sheet-input","data-testid":"mobile-item-sheet-status",value:i,onChange:f=>d(f.target.value),children:yt.map(f=>t.jsx("option",{value:f,children:f},f))})]}),t.jsxs("section",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-sheet-group",children:"Group"}),t.jsx("input",{id:"m-sheet-group",type:"text",className:"m-sheet-input","data-testid":"mobile-item-sheet-group",value:u,onChange:f=>h(f.target.value)})]}),t.jsxs("section",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-sheet-confidence",children:"Confidence (0–5)"}),t.jsx("input",{id:"m-sheet-confidence",type:"number",min:"0",max:"5",step:"1",className:"m-sheet-input","data-testid":"mobile-item-sheet-confidence",value:b,onChange:f=>y(f.target.value)})]})]}),t.jsxs("footer",{className:"m-sheet-footer",children:[t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-secondary",onClick:a,"data-testid":"mobile-item-sheet-cancel",children:"Cancel"}),t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-primary",onClick:p,disabled:!c||m,"data-testid":"mobile-item-sheet-save",children:m?"Saving…":"Save"})]})]})})}function je({message:e,kind:a="error",durationMs:s=3e3,onDismiss:r}){return l.useEffect(()=>{if(!e)return;const i=setTimeout(()=>r==null?void 0:r(),s);return()=>clearTimeout(i)},[e,s,r]),e?t.jsx("div",{className:"m-toast",role:"status","data-kind":a,"data-testid":"mobile-toast",children:e}):null}function jt(e){const a=new Set;for(const s of e){const r=((s==null?void 0:s.group)||"").trim();r&&a.add(r)}return Array.from(a).sort()}function xt(e,a){if(!a)return!0;const s=a.toLowerCase(),r=(e.title||"").toLowerCase(),i=(e.description||"").toLowerCase();return r.includes(s)||i.includes(s)}function Nt(){const{items:e,loading:a,error:s,applyOptimisticEdit:r}=dt(),[i,d]=l.useState([]),[u,h]=l.useState(""),[b,y]=l.useState(""),[m,o]=l.useState(null),[c,p]=l.useState(null),f=l.useMemo(()=>jt(e),[e]),v=l.useMemo(()=>e.filter(N=>!(i.length&&!i.includes(N.status)||u&&N.group!==u||!xt(N,b))),[e,i,u,b]),x=l.useMemo(()=>e.find(N=>N.id===m)||null,[e,m]),S=N=>{d(w=>w.includes(N)?w.filter(T=>T!==N):[...w,N])},g=async(N,w)=>{const T=await r(N,w);T!=null&&T.ok?o(null):p((T==null?void 0:T.error)||"Save failed")};return t.jsxs("section",{className:"m-roadmap","data-testid":"mobile-tab-roadmap",children:[t.jsx(ft,{statuses:i,onToggleStatus:S,group:u,groupOptions:f,onChangeGroup:h,keyword:b,onChangeKeyword:y}),s?t.jsx("div",{className:"m-roadmap-error","data-testid":"mobile-roadmap-error",children:s}):null,a?t.jsx("div",{className:"m-roadmap-skeleton","data-testid":"mobile-roadmap-loading",children:Array.from({length:4}).map((N,w)=>t.jsx("div",{className:"m-skel-card"},w))}):v.length===0?t.jsx("div",{className:"m-roadmap-empty","data-testid":"mobile-roadmap-empty",children:e.length===0?"No roadmap items yet.":"No items match the current filters."}):t.jsx("ul",{className:"m-roadmap-list","data-testid":"mobile-roadmap-list",children:v.map(N=>t.jsx("li",{children:t.jsx(bt,{item:N,onSelect:w=>o(w.id)})},N.id))}),x?t.jsx(gt,{item:x,onClose:()=>o(null),onSave:g}):null,t.jsx(je,{message:c,onDismiss:()=>p(null)})]})}const H="—";async function B(e,a={}){const s=await D(e,a);let r=null;try{r=await s.json()}catch{}if(!s.ok){const i=r&&r.error||`HTTP ${s.status}`;throw new Error(i)}return r}function wt(){const[e,a]=l.useState([]),[s,r]=l.useState([]),[i,d]=l.useState(!0),[u,h]=l.useState(null),[b,y]=l.useState([]),m=l.useRef(e);m.current=e;const o=l.useCallback((g,N)=>{const w=`t_${Date.now()}_${Math.random().toString(36).slice(2,6)}`;y(T=>[...T,{id:w,kind:g,message:N}]),setTimeout(()=>{y(T=>T.filter(k=>k.id!==w))},3500)},[]),c=l.useCallback(g=>{y(N=>N.filter(w=>w.id!==g))},[]),p=l.useCallback(async()=>{try{const g=await B("/api/ideabox");a(Array.isArray(g==null?void 0:g.ideas)?g.ideas:[]),r(Array.isArray(g==null?void 0:g.killed)?g.killed:[]),h(null)}catch(g){h(g.message),o("error",`Failed to load ideas: ${g.message}`)}finally{d(!1)}},[o]);l.useEffect(()=>{let g=!0;return(async()=>g&&await p())(),()=>{g=!1}},[p]),l.useEffect(()=>{if(typeof window>"u"||typeof WebSocket>"u")return;let g=null,N=!1,w=null;function T(){if(!N){try{const C=window.location.protocol==="https:"?"wss:":"ws:";g=new WebSocket(`${C}//${window.location.host}/ws/vision`)}catch{k();return}g.onmessage=C=>{try{const E=JSON.parse(C.data);E&&E.type==="ideaboxUpdated"&&p()}catch{}},g.onclose=()=>{N||k()},g.onerror=()=>{try{g.close()}catch{}}}}function k(){w&&clearTimeout(w),w=setTimeout(T,3e3)}return T(),()=>{N=!0,w&&clearTimeout(w);try{g&&(g.onclose=null,g.close())}catch{}}},[p]);const f=l.useCallback(async({title:g,description:N,source:w,tags:T,cluster:k})=>{if(!g||!g.trim()){const I=new Error("title is required");throw o("error",I.message),I}const C=`tmp_${Date.now()}`,E={id:C,num:0,title:g.trim(),description:N||"",source:w||"",tags:Array.isArray(T)?T:[],cluster:k||null,status:"NEW",priority:H,_pending:!0};a(I=>[E,...I]);try{const I=await B("/api/ideabox/ideas",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:g.trim(),description:N,source:w,tags:T,cluster:k})});return a(U=>U.map(F=>F.id===C?{...I}:F)),o("ok","Idea captured"),I}catch(I){throw a(U=>U.filter(F=>F.id!==C)),o("error",`Capture failed: ${I.message}`),I}},[o]),v=l.useCallback(async(g,{featureCode:N}={})=>{const w=m.current;a(T=>T.map(k=>k.id===g?{...k,_promoting:!0}:k));try{const T=await B(`/api/ideabox/ideas/${encodeURIComponent(g)}/promote`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({featureCode:N||""})});return o("ok",`Promoted${T!=null&&T.featureCode?` → ${T.featureCode}`:""}`),p(),T}catch(T){throw a(w),o("error",`Promote failed: ${T.message}`),T}},[o,p]),x=l.useCallback(async(g,{reason:N}={})=>{const w=m.current,T=w.find(k=>k.id===g);a(k=>k.filter(C=>C.id!==g)),T&&r(k=>[{...T,status:"KILLED",reason:N||""},...k]);try{const k=await B(`/api/ideabox/ideas/${encodeURIComponent(g)}/kill`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:N||""})});return o("ok","Idea killed"),p(),k}catch(k){throw a(w),r(C=>C.filter(E=>E.id!==g||E.status!=="KILLED")),o("error",`Kill failed: ${k.message}`),k}},[o,p]),S=l.useCallback(async(g,N)=>{if(!["P0","P1","P2",H].includes(N)){const k=new Error(`Invalid priority: ${N}`);throw o("error",k.message),k}const T=m.current;a(k=>k.map(C=>C.id===g?{...C,priority:N}:C));try{const k=await B(`/api/ideabox/ideas/${encodeURIComponent(g)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({priority:N})});return o("ok",`Priority → ${N===H?"Untriaged":N}`),k}catch(k){throw a(T),o("error",`Set priority failed: ${k.message}`),k}},[o]);return{ideas:e,killed:s,loading:i,error:u,toasts:b,dismissToast:c,refetch:p,createIdea:f,promote:v,kill:x,setPriority:S}}function vt(e,a={}){const{onSwipeLeft:s,onSwipeRight:r,onDrag:i,onDragEnd:d,threshold:u=80,axis:h="x"}=a,b=l.useRef({onSwipeLeft:s,onSwipeRight:r,onDrag:i,onDragEnd:d});b.current={onSwipeLeft:s,onSwipeRight:r,onDrag:i,onDragEnd:d},l.useEffect(()=>{const y=e&&e.current;if(!y)return;let m=0,o=0,c=null,p=!1,f=0;function v(g){if(!(g.button!==void 0&&g.button!==0)){c=g.pointerId,m=g.clientX,o=g.clientY,p=!0,f=0;try{y.setPointerCapture(g.pointerId)}catch{}}}function x(g){var T,k,C,E;if(!p||g.pointerId!==c)return;const N=g.clientX-m,w=g.clientY-o;if(h==="x"&&Math.abs(w)>Math.abs(N)&&Math.abs(w)>12){p=!1,(k=(T=b.current).onDragEnd)==null||k.call(T,0,!1);return}f=N,(E=(C=b.current).onDrag)==null||E.call(C,N)}function S(g){var T,k,C,E,I,U;if(!p||g&&g.pointerId!==c)return;const N=f;p=!1;try{y.releasePointerCapture(c)}catch{}c=null;let w=!1;N<=-u?((k=(T=b.current).onSwipeLeft)==null||k.call(T),w=!0):N>=u&&((E=(C=b.current).onSwipeRight)==null||E.call(C),w=!0),(U=(I=b.current).onDragEnd)==null||U.call(I,N,w)}return y.addEventListener("pointerdown",v),y.addEventListener("pointermove",x),y.addEventListener("pointerup",S),y.addEventListener("pointercancel",S),()=>{y.removeEventListener("pointerdown",v),y.removeEventListener("pointermove",x),y.removeEventListener("pointerup",S),y.removeEventListener("pointercancel",S)}},[e,u,h])}function St(e){return e==="P0"||e==="P1"||e==="P2"?e.toLowerCase():"untriaged"}function kt(e){return e==="P0"||e==="P1"||e==="P2"?e:"Untriaged"}function Tt({idea:e,onTap:a,onSwipeLeft:s,onSwipeRight:r}){const i=l.useRef(null),[d,u]=l.useState(0),[h,b]=l.useState(null),y=l.useCallback(p=>{u(p),p<=-40?b("kill"):p>=40?b("promote"):b(null)},[]),m=l.useCallback(()=>{u(0),b(null)},[]);vt(i,{onSwipeLeft:()=>s==null?void 0:s(e),onSwipeRight:()=>r==null?void 0:r(e),onDrag:y,onDragEnd:m,threshold:80});const o=St(e.priority),c=Array.isArray(e.tags)?e.tags:[];return t.jsxs("div",{className:"m-idea-row","data-testid":`idea-row-${e.id}`,children:[t.jsx("div",{className:"m-idea-action m-idea-action-left","aria-hidden":"true",children:"Promote"}),t.jsx("div",{className:"m-idea-action m-idea-action-right","aria-hidden":"true",children:"Kill"}),t.jsxs("article",{ref:i,className:`m-idea-card${h?` is-intent-${h}`:""}`,"data-testid":"idea-card","data-idea-id":e.id,"data-priority":o,style:{transform:`translateX(${d}px)`},role:"button",tabIndex:0,onClick:()=>{Math.abs(d)<4&&(a==null||a(e))},onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),a==null||a(e))},children:[t.jsxs("div",{className:"m-idea-head",children:[t.jsx("span",{className:"m-priority-badge","data-priority":o,"data-testid":`priority-badge-${e.id}`,children:kt(e.priority)}),e.cluster?t.jsx("span",{className:"m-idea-cluster",title:e.cluster,children:e.cluster}):null]}),t.jsx("h3",{className:"m-idea-title","data-testid":`idea-title-${e.id}`,children:e.title}),c.length>0?t.jsx("div",{className:"m-idea-tags",children:c.map(p=>t.jsx("span",{className:"m-idea-tag",children:p},p))}):null]})]})}function Ct({open:e,onClose:a,onSubmit:s,existingClusters:r=[]}){const[i,d]=l.useState(""),[u,h]=l.useState(""),[b,y]=l.useState(""),[m,o]=l.useState([]),[c,p]=l.useState(""),[f,v]=l.useState(!1),[x,S]=l.useState(null),g=l.useId(),N=l.useMemo(()=>{const E=new Set;for(const I of r)I&&typeof I=="string"&&E.add(I);return[...E].sort()},[r]);if(!e)return null;function w(){d(""),h(""),y(""),o([]),p(""),S(null),v(!1)}function T(){w(),a==null||a()}function k(){const E=b.trim();E&&(m.includes(E)||o([...m,E]),y(""))}async function C(E){if(E.preventDefault(),!i.trim()){S("Title is required");return}v(!0),S(null);try{await(s==null?void 0:s({title:i.trim(),description:u.trim()||void 0,tags:m.length?m:void 0,cluster:c.trim()||void 0})),T()}catch(I){S(I.message||"Failed to capture"),v(!1)}}return t.jsx("div",{className:"m-sheet-overlay","data-testid":"capture-sheet",role:"dialog","aria-modal":"true","aria-label":"Capture idea",onClick:E=>{E.target===E.currentTarget&&T()},children:t.jsxs("div",{className:"m-sheet",children:[t.jsxs("header",{className:"m-sheet-header",children:[t.jsx("button",{type:"button",className:"m-sheet-close","aria-label":"Close capture",onClick:T,disabled:f,children:"×"}),t.jsx("div",{className:"m-sheet-title-row",children:t.jsx("div",{className:"m-sheet-title",children:"Capture idea"})})]}),t.jsxs("form",{className:"m-sheet-body",onSubmit:C,children:[t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-capture-title",children:"Title"}),t.jsx("input",{id:"m-capture-title",type:"text",className:"m-sheet-input",value:i,onChange:E=>d(E.target.value),placeholder:"What's the idea?","data-testid":"capture-title",autoFocus:!0,required:!0})]}),t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-capture-desc",children:"Description (optional)"}),t.jsx("textarea",{id:"m-capture-desc",className:"m-sheet-input m-textarea",value:u,onChange:E=>h(E.target.value),rows:4,"data-testid":"capture-description"})]}),t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-capture-tag",children:"Tags (optional)"}),t.jsxs("div",{className:"m-tag-input-row",children:[t.jsx("input",{id:"m-capture-tag",type:"text",className:"m-sheet-input",value:b,onChange:E=>y(E.target.value),onKeyDown:E=>{(E.key==="Enter"||E.key===",")&&(E.preventDefault(),k())},placeholder:"Add tag and press Enter","data-testid":"capture-tag-input"}),t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-secondary m-tag-add",onClick:k,children:"Add"})]}),m.length>0?t.jsx("div",{className:"m-idea-tags","data-testid":"capture-tags",children:m.map(E=>t.jsxs("span",{className:"m-idea-tag",children:[E,t.jsx("button",{type:"button",className:"m-tag-remove","aria-label":`Remove tag ${E}`,onClick:()=>o(m.filter(I=>I!==E)),children:"×"})]},E))}):null]}),t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-capture-cluster",children:"Cluster (optional)"}),t.jsx("input",{id:"m-capture-cluster",type:"text",className:"m-sheet-input",value:c,onChange:E=>p(E.target.value),list:g,placeholder:"Group into a theme","data-testid":"capture-cluster"}),t.jsx("datalist",{id:g,children:N.map(E=>t.jsx("option",{value:E},E))})]}),x?t.jsx("div",{className:"m-form-error",role:"alert",children:x}):null]}),t.jsxs("footer",{className:"m-sheet-footer",children:[t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-secondary",onClick:T,disabled:f,"data-testid":"capture-cancel",children:"Cancel"}),t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-primary",disabled:f||!i.trim(),"data-testid":"capture-submit",onClick:C,children:f?"Saving…":"Capture"})]})]})})}const Et=[{value:"P0",label:"P0"},{value:"P1",label:"P1"},{value:"P2",label:"P2"},{value:H,label:"Untriaged"}];function $t({value:e,onChange:a,disabled:s=!1}){return t.jsx("div",{className:"m-priority-selector",role:"radiogroup","aria-label":"Priority",children:Et.map(r=>{const i=e===r.value,d=`m-priority-chip${i?" is-selected":""}`;return t.jsx("button",{type:"button",role:"radio","aria-checked":i?"true":"false",className:d,"data-priority":r.value===H?"untriaged":r.value.toLowerCase(),"data-testid":`priority-chip-${r.value===H?"untriaged":r.value.toLowerCase()}`,disabled:s,onClick:()=>a(r.value),children:r.label},r.value)})})}function At({idea:e,open:a,onClose:s,onPromote:r,onKill:i,onSetPriority:d}){const[u,h]=l.useState(!1);if(!a||!e)return null;const b=Array.isArray(e.tags)?e.tags:[],y=e.priority||H;async function m(o,c=!0){h(!0);try{await o(),c&&(s==null||s())}catch{}finally{h(!1)}}return t.jsx("div",{className:"m-sheet-overlay","data-testid":"idea-detail-sheet",role:"dialog","aria-modal":"true","aria-label":`Idea ${e.id}`,onClick:o=>{o.target===o.currentTarget&&(s==null||s())},children:t.jsxs("div",{className:"m-sheet",children:[t.jsxs("header",{className:"m-sheet-header",children:[t.jsx("button",{type:"button",className:"m-sheet-close","aria-label":"Close detail",onClick:s,disabled:u,children:"×"}),t.jsx("div",{className:"m-sheet-title-row",children:t.jsx("div",{className:"m-sheet-title",children:e.title})}),t.jsxs("div",{className:"m-detail-meta",children:[t.jsx("span",{className:"m-detail-meta-id",children:e.id}),t.jsx("span",{className:"m-detail-meta-status",children:e.status||"NEW"}),e.cluster?t.jsx("span",{className:"m-detail-meta-cluster",children:e.cluster}):null]})]}),t.jsxs("div",{className:"m-sheet-body",children:[e.description?t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("div",{className:"m-sheet-label",children:"Description"}),t.jsx("p",{className:"m-sheet-desc",children:e.description})]}):null,e.source?t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("div",{className:"m-sheet-label",children:"Source"}),t.jsx("p",{className:"m-sheet-desc",children:e.source})]}):null,b.length>0?t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("div",{className:"m-sheet-label",children:"Tags"}),t.jsx("div",{className:"m-idea-tags",children:b.map(o=>t.jsx("span",{className:"m-idea-tag",children:o},o))})]}):null,t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("div",{className:"m-sheet-label",children:"Priority"}),t.jsx($t,{value:y,disabled:u,onChange:o=>m(()=>d==null?void 0:d(e.id,o),!1)})]})]}),t.jsxs("footer",{className:"m-sheet-footer",children:[t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-secondary","data-testid":"detail-kill",disabled:u,onClick:()=>m(()=>i==null?void 0:i(e.id)),children:"Kill"}),t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-primary","data-testid":"detail-promote",disabled:u,onClick:()=>m(()=>r==null?void 0:r(e.id)),children:"Promote"})]})]})})}const Rt=[{id:"all",label:"All"},{id:"P0",label:"P0"},{id:"P1",label:"P1"},{id:"P2",label:"P2"},{id:"untriaged",label:"Untriaged"}],de={P0:3,P1:2,P2:1};function _t(e){return[...e].sort((a,s)=>{const r=de[a.priority]||0,i=de[s.priority]||0;if(r!==i)return i-r;const d=typeof a.num=="number"?a.num:0;return(typeof s.num=="number"?s.num:0)-d})}function Pt(){const{ideas:e,loading:a,toasts:s,dismissToast:r,createIdea:i,promote:d,kill:u,setPriority:h}=wt(),[b,y]=l.useState("all"),[m,o]=l.useState(!1),[c,p]=l.useState(null),f=l.useMemo(()=>{let x=e;return b==="untriaged"?x=x.filter(S=>!S.priority||S.priority===H||S.priority===""):b!=="all"&&(x=x.filter(S=>S.priority===b)),_t(x)},[e,b]),v=l.useMemo(()=>{const x=new Set;for(const S of e)S.cluster&&x.add(S.cluster);return[...x]},[e]);return t.jsxs("section",{className:"m-ideas-tab","data-testid":"mobile-tab-ideas",children:[t.jsxs("div",{className:"m-ideas-toolbar",children:[t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-primary m-capture-btn",onClick:()=>o(!0),"data-testid":"open-capture","aria-label":"Capture new idea",children:"+ Capture"}),t.jsx("div",{className:"m-filter-chips",role:"tablist","aria-label":"Priority filter",children:Rt.map(x=>t.jsx("button",{type:"button",role:"tab","aria-pressed":b===x.id?"true":"false","aria-selected":b===x.id?"true":"false",className:"m-filter-chip",onClick:()=>y(x.id),"data-testid":`filter-${x.id}`,children:x.label},x.id))})]}),a?t.jsx("div",{className:"m-ideas-list","data-testid":"ideas-loading",children:[0,1,2].map(x=>t.jsx("div",{className:"m-idea-skeleton","aria-hidden":"true"},x))}):f.length===0?t.jsxs("div",{className:"m-empty-state","data-testid":"ideas-empty",children:[t.jsx("div",{className:"m-empty-title",children:e.length===0?"No ideas yet":"Nothing matches this filter"}),t.jsx("div",{className:"m-empty-body",children:e.length===0?"Tap Capture to add your first idea.":"Try All to see everything."})]}):t.jsx("div",{className:"m-ideas-list","data-testid":"ideas-list",children:f.map(x=>t.jsx(Tt,{idea:x,onTap:S=>p(S),onSwipeLeft:S=>u(S.id),onSwipeRight:S=>d(S.id)},x.id))}),t.jsx(Ct,{open:m,onClose:()=>o(!1),onSubmit:i,existingClusters:v}),t.jsx(At,{idea:c,open:!!c,onClose:()=>p(null),onPromote:x=>d(x),onKill:x=>u(x),onSetPriority:(x,S)=>h(x,S)}),t.jsx("div",{className:"m-toast-stack","aria-live":"polite","data-testid":"toasts",children:s.map(x=>t.jsx("div",{className:"m-toast","data-kind":x.kind==="error"?"error":"ok",role:x.kind==="error"?"alert":"status",onClick:()=>r(x.id),children:x.message},x.id))})]})}async function ee(e,a={}){const s=await D(e,a);let r=null;try{r=await s.json()}catch{}if(!s.ok){const i=r&&r.error||`HTTP ${s.status}`,d=new Error(i);throw d.status=s.status,d.data=r,d}return r}function It(){const[e,a]=l.useState(null),[s,r]=l.useState(!0),[i,d]=l.useState(null),u=l.useRef(!0),h=l.useCallback(async()=>{try{const m=await ee("/api/build/state");if(!u.current)return;a((m==null?void 0:m.state)??null),d(null)}catch(m){if(!u.current)return;d(m.message)}finally{u.current&&r(!1)}},[]);l.useEffect(()=>(u.current=!0,h(),()=>{u.current=!1}),[h]),l.useEffect(()=>{if(typeof window>"u"||typeof WebSocket>"u")return;let m=null,o=!1,c=null;function p(){if(!o){try{const v=window.location.protocol==="https:"?"wss:":"ws:";m=new WebSocket(`${v}//${window.location.host}/ws/vision`)}catch{f();return}m.onmessage=v=>{try{const x=JSON.parse(v.data);if(!x||!x.type)return;x.type==="buildState"&&h()}catch{}},m.onclose=()=>{o||f()},m.onerror=()=>{try{m.close()}catch{}}}}function f(){c&&clearTimeout(c),c=setTimeout(p,3e3)}return p(),()=>{o=!0,c&&clearTimeout(c);try{m&&(m.onclose=null,m.close())}catch{}}},[h]);const b=l.useCallback(async({featureCode:m,mode:o="feature",description:c=""}={})=>{if(!m)throw new Error("featureCode required");const p=await ee("/api/build/start",{method:"POST",headers:Y({"Content-Type":"application/json"}),body:JSON.stringify({featureCode:m,mode:o,description:c})});return h(),p},[h]),y=l.useCallback(async({featureCode:m}={})=>{if(!m)throw new Error("featureCode required");const o=await ee("/api/build/abort",{method:"POST",headers:Y({"Content-Type":"application/json"}),body:JSON.stringify({featureCode:m})});return h(),o},[h]);return{active:e,loading:s,error:i,refetch:h,startBuild:b,abortBuild:y}}function Ot(e){if(!e)return"";const a=typeof e=="string"?Date.parse(e):Number(e);if(!a||Number.isNaN(a))return"";const s=Date.now()-a;return s<5e3?"just now":s<6e4?`${Math.floor(s/1e3)}s ago`:s<36e5?`${Math.floor(s/6e4)}m ago`:`${Math.floor(s/36e5)}h ago`}function Lt(e,a=3){return e?Array.isArray(e.logTail)?e.logTail.slice(-a):Array.isArray(e.recentLogs)?e.recentLogs.slice(-a):Array.isArray(e.steps)?e.steps.slice(-a).map(s=>`${s.id||s.name||""}: ${s.status||""}`.trim()):[]:[]}function Mt(e){return e==="completed"||e==="aborted"||e==="failed"||e==="done"}function Dt({active:e,onOpen:a,onAbort:s,aborting:r}){const[i,d]=l.useState(null),u=(e==null?void 0:e.featureCode)||"(unknown)",h=(e==null?void 0:e.mode)||"feature",b=(e==null?void 0:e.status)||"unknown",y=(e==null?void 0:e.startedAt)||(e==null?void 0:e.started_at)||null,m=Lt(e),o=l.useCallback(async p=>{if(p==null||p.stopPropagation(),!!(e!=null&&e.featureCode)){d(null);try{await(s==null?void 0:s({featureCode:e.featureCode}))}catch(f){d(f.message||"Failed to abort")}}},[e,s]),c=l.useCallback(()=>a==null?void 0:a(e),[a,e]);return t.jsxs("div",{className:"m-build-card","data-testid":"mobile-build-card","data-feature":u,role:"button",tabIndex:0,onClick:c,onKeyDown:p=>{p.key==="Enter"&&c()},children:[t.jsxs("div",{className:"m-build-card-row",children:[t.jsx("div",{className:"m-build-card-feature",title:u,children:u}),t.jsx("span",{className:"m-status-pill","data-status":b,children:b})]}),t.jsxs("div",{className:"m-build-card-meta",children:[t.jsx("span",{className:"m-build-card-mode","data-mode":h,children:h}),t.jsx("span",{className:"m-build-card-time",children:Ot(y)})]}),m.length>0&&t.jsx("div",{className:"m-build-card-tail",children:m.map((p,f)=>t.jsx("div",{className:"m-build-card-tail-line",children:String(p).slice(0,200)},f))}),t.jsx("div",{className:"m-build-card-actions",children:t.jsx("button",{type:"button",className:"m-btn m-btn-danger m-btn-sm","data-testid":"mobile-build-abort",disabled:r||Mt(b),onClick:o,children:r?"Aborting…":"Abort"})}),i&&t.jsx("div",{className:"m-agent-card-error",children:i})]})}function Ut(e,a){if(typeof e=="string")return e;if(e!=null&&e.type&&(e!=null&&e.message))return`[${e.type}] ${typeof e.message=="string"?e.message:JSON.stringify(e.message)}`;if(e!=null&&e.type)return`[${e.type}] ${JSON.stringify(e).slice(0,240)}`;try{return JSON.stringify(e)}catch{return`(unserializable #${a})`}}function Ft(e){return e==="completed"||e==="aborted"||e==="failed"||e==="done"}function Ht({active:e,onClose:a,onAbort:s}){const r=e==null?void 0:e.featureCode,{events:i}=ye({agentId:(e==null?void 0:e.flowId)||null}),d=l.useRef(null),[u,h]=l.useState(!1),[b,y]=l.useState(null);l.useEffect(()=>{var p;(p=d.current)==null||p.scrollIntoView({behavior:"smooth"})},[i.length]);const m=l.useCallback(async()=>{if(r){h(!0),y(null);try{await(s==null?void 0:s({featureCode:r}))}catch(p){y(p.message||"Failed to abort")}finally{h(!1)}}},[r,s]);if(!e)return null;const o=e.status||"unknown",c=e.mode||"feature";return t.jsxs("div",{className:"m-overlay","data-testid":"mobile-build-detail",role:"dialog","aria-modal":"true",children:[t.jsxs("header",{className:"m-overlay-header",children:[t.jsxs("div",{className:"m-overlay-header-inner",children:[t.jsx("div",{className:"m-overlay-title",title:r,children:r}),t.jsx("span",{className:"m-status-pill","data-status":o,children:o}),t.jsx("span",{className:"m-build-card-mode","data-mode":c,children:c})]}),t.jsxs("div",{className:"m-overlay-actions",children:[t.jsx("button",{type:"button",className:"m-btn m-btn-danger m-btn-sm",disabled:u||Ft(o),onClick:m,"data-testid":"mobile-build-detail-abort",children:u?"Aborting…":"Abort"}),t.jsx("button",{type:"button",className:"m-btn m-btn-sm",onClick:a,"data-testid":"mobile-build-detail-close",children:"Close"})]})]}),t.jsxs("div",{className:"m-overlay-body m-agent-log",children:[i.length===0?t.jsx("div",{className:"m-empty",children:"No live events yet."}):i.map((p,f)=>t.jsx("div",{className:"m-agent-log-line",children:Ut(p,f)},f)),t.jsx("div",{ref:d})]}),b&&t.jsx("div",{className:"m-agent-card-error",children:b})]})}async function Jt(){var e;try{const a=await D("/api/vision/items");if(!a.ok)return[];const s=await a.json(),r=Array.isArray(s==null?void 0:s.items)?s.items:Array.isArray(s)?s:[],i=new Set;for(const d of r){const u=((e=d==null?void 0:d.lifecycle)==null?void 0:e.featureCode)||(d==null?void 0:d.featureCode)||(d==null?void 0:d.id);u&&typeof u=="string"&&i.add(u)}return[...i].sort()}catch{return[]}}function qt({open:e,onClose:a,onSubmit:s}){const[r,i]=l.useState(""),[d,u]=l.useState("feature"),[h,b]=l.useState(""),[y,m]=l.useState(!1),[o,c]=l.useState(null),[p,f]=l.useState([]),v=l.useId();l.useEffect(()=>{if(!e)return;let w=!0;return Jt().then(T=>{w&&f(T)}),()=>{w=!1}},[e]);const x=l.useMemo(()=>p,[p]);if(!e)return null;function S(){i(""),u("feature"),b(""),c(null),m(!1)}function g(){S(),a==null||a()}async function N(w){if(w==null||w.preventDefault(),!r.trim()){c("Feature code is required");return}m(!0),c(null);try{await(s==null?void 0:s({featureCode:r.trim(),mode:d,description:h.trim()})),g()}catch(T){c(T.message||"Failed to start build"),m(!1)}}return t.jsx("div",{className:"m-sheet-overlay","data-testid":"mobile-start-build-sheet",role:"dialog","aria-modal":"true","aria-label":"Start build",onClick:w=>{w.target===w.currentTarget&&g()},children:t.jsxs("div",{className:"m-sheet",children:[t.jsxs("header",{className:"m-sheet-header",children:[t.jsx("button",{type:"button",className:"m-sheet-close","aria-label":"Close start build",onClick:g,disabled:y,children:"×"}),t.jsx("div",{className:"m-sheet-title-row",children:t.jsx("div",{className:"m-sheet-title",children:"Start build"})})]}),t.jsxs("form",{className:"m-sheet-body",onSubmit:N,children:[t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-build-feature",children:"Feature code"}),t.jsx("input",{id:"m-build-feature",type:"text",className:"m-sheet-input",value:r,onChange:w=>i(w.target.value),placeholder:"e.g. COMP-MOBILE","data-testid":"mobile-build-feature-input",list:v,autoFocus:!0,required:!0}),t.jsx("datalist",{id:v,children:x.map(w=>t.jsx("option",{value:w},w))})]}),t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("div",{className:"m-sheet-label",children:"Mode"}),t.jsxs("div",{className:"m-build-mode-row",role:"radiogroup","aria-label":"Build mode",children:[t.jsx("button",{type:"button",role:"radio","aria-checked":d==="feature",className:`m-priority-chip${d==="feature"?" is-selected":""}`,"data-testid":"mobile-build-mode-feature",onClick:()=>u("feature"),children:"Feature"}),t.jsx("button",{type:"button",role:"radio","aria-checked":d==="bug",className:`m-priority-chip${d==="bug"?" is-selected":""}`,"data-testid":"mobile-build-mode-bug",onClick:()=>u("bug"),children:"Bug"})]})]}),t.jsxs("div",{className:"m-sheet-section",children:[t.jsx("label",{className:"m-sheet-label",htmlFor:"m-build-desc",children:"Description (optional)"}),t.jsx("textarea",{id:"m-build-desc",className:"m-sheet-input m-textarea",value:h,onChange:w=>b(w.target.value),rows:4,"data-testid":"mobile-build-description"})]}),o?t.jsx("div",{className:"m-form-error",role:"alert",children:o}):null]}),t.jsxs("footer",{className:"m-sheet-footer",children:[t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-secondary",onClick:g,disabled:y,"data-testid":"mobile-build-cancel",children:"Cancel"}),t.jsx("button",{type:"button",className:"m-sheet-btn m-sheet-btn-primary",disabled:y||!r.trim(),"data-testid":"mobile-build-submit",onClick:N,children:y?"Starting…":"Start"})]})]})})}function me(e){return e==="completed"||e==="aborted"||e==="failed"||e==="done"}function Bt(){const{active:e,loading:a,error:s,startBuild:r,abortBuild:i}=It(),[d,u]=l.useState(!1),[h,b]=l.useState(!1),[y,m]=l.useState(!1),[o,c]=l.useState(null),p=!!(e&&e.featureCode&&!me(e.status)),f=l.useCallback(async({featureCode:x,mode:S,description:g})=>{try{await r({featureCode:x,mode:S,description:g}),c({kind:"ok",message:`Build started for ${x}`})}catch(N){const w=(N==null?void 0:N.status)===409?`A build for ${x} is already active`:(N==null?void 0:N.message)||"Failed to start build";throw c({kind:"error",message:w}),N}},[r]),v=l.useCallback(async({featureCode:x})=>{m(!0);try{await i({featureCode:x}),c({kind:"ok",message:`Aborted ${x}`}),b(!1)}catch(S){throw c({kind:"error",message:(S==null?void 0:S.message)||"Failed to abort"}),S}finally{m(!1)}},[i]);return t.jsxs("section",{"data-testid":"mobile-tab-builds",className:"m-builds-tab",children:[t.jsxs("div",{className:"m-section",children:[t.jsx("h2",{className:"m-section-title",children:"Current build"}),a?t.jsx("div",{className:"m-empty","data-testid":"mobile-build-loading",children:"Loading…"}):p?t.jsx(Dt,{active:e,onOpen:()=>b(!0),onAbort:v,aborting:y}):t.jsxs("div",{className:"m-empty-state","data-testid":"mobile-build-empty",children:[t.jsx("div",{className:"m-empty-title",children:"No active build"}),t.jsx("div",{className:"m-empty-body",children:e&&me(e.status)?`Last build: ${e.featureCode} (${e.status})`:"Start a build to track progress here."}),t.jsx("button",{type:"button",className:"m-btn m-btn-primary","data-testid":"mobile-build-start",onClick:()=>u(!0),children:"Start build"})]}),s&&t.jsxs("div",{className:"m-empty","data-testid":"mobile-build-error",children:["Error: ",s]})]}),p&&t.jsx("div",{className:"m-section",children:t.jsx("button",{type:"button",className:"m-btn m-btn-sm","data-testid":"mobile-build-start-secondary",onClick:()=>u(!0),children:"Start another build"})}),t.jsx(qt,{open:d,onClose:()=>u(!1),onSubmit:f}),h&&e&&t.jsx(Ht,{active:e,onClose:()=>b(!1),onAbort:v}),t.jsx(je,{message:o==null?void 0:o.message,kind:o==null?void 0:o.kind,onDismiss:()=>c(null)})]})}const xe=["agents","roadmap","builds","ideas"],fe="agents",he="compose:mobile:sensitiveToken";function Yt(e){const a=e.match(/^\/m(?:\/([^/?#]+))?\/?$/);if(!a)return fe;const s=a[1];return s&&xe.includes(s)?s:fe}function Gt(){const[e,a]=l.useState(()=>Yt(window.location.pathname));l.useEffect(()=>{try{const i=new URL(window.location.href),d=i.searchParams.get("token");if(d){try{localStorage.setItem(he,d)}catch{}oe(d),i.searchParams.delete("token"),window.history.replaceState({},"",i.pathname+(i.search?i.search:"")+i.hash)}else{let u=null;try{u=localStorage.getItem(he)}catch{}u&&oe(u)}}catch{}},[]),l.useEffect(()=>{if(!(typeof navigator>"u")&&"serviceWorker"in navigator)try{navigator.serviceWorker.register("/m-sw.js").catch(i=>{console.warn("[compose-mobile] SW registration failed:",i)})}catch(i){console.warn("[compose-mobile] SW registration threw:",i)}},[]);const s=l.useCallback(i=>{if(xe.includes(i)){a(i);try{const d=new URL(window.location.href);d.pathname=`/m/${i}`,window.history.replaceState({},"",d.pathname+d.search+d.hash)}catch{}}},[]);let r=null;return e==="agents"?r=t.jsx(ot,{}):e==="roadmap"?r=t.jsx(Nt,{}):e==="ideas"?r=t.jsx(Pt,{}):e==="builds"&&(r=t.jsx(Bt,{})),t.jsxs("div",{className:"m-root","data-testid":"mobile-root",children:[t.jsx("header",{className:"m-header",children:t.jsx("div",{className:"m-header-title",children:"Compose"})}),t.jsx("main",{className:"m-main","data-testid":"mobile-main","data-tab":e,children:r}),t.jsx(Le,{active:e,onSelect:s})]})}const Xt=Object.freeze(Object.defineProperty({__proto__:null,default:Gt},Symbol.toStringTag,{value:"Module"}));export{Xt as M,Kt as R,l as a,_e as b,Wt as c,Ve as d,ct as e,Y as f,Ce as g,We as h,t as j,Re as r,zt as s,D as w};
