/home/techb158/balavpn.abdallabala.com/.next/static/chunks/app/dashboard
Edit: /home/techb158/balavpn.abdallabala.com/.next/static/chunks/app/dashboard/page-b904031ab69c78e7.js (49924B)
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5105],{63:(e,s,a)=>{"use strict";var t=a(7260);a.o(t,"useRouter")&&a.d(s,{useRouter:function(){return t.useRouter}}),a.o(t,"useSearchParams")&&a.d(s,{useSearchParams:function(){return t.useSearchParams}})},646:(e,s,a)=>{Promise.resolve().then(a.bind(a,3399))},3399:(e,s,a)=>{"use strict";a.r(s),a.d(s,{default:()=>F});var t=a(5155),l=a(2115),n=a(63),i=a(6282);class r extends l.Component{static getDerivedStateFromError(e){return{error:e}}render(){if(this.state.error){let{fallback:e}=this.props;return e?"function"==typeof e?e(this.state.error):e:(0,t.jsxs)("div",{className:"empty-state",children:[(0,t.jsx)("div",{className:"empty-icon",children:"!"}),(0,t.jsxs)("p",{children:["Something went wrong in ",this.props.name||"this section","."]}),(0,t.jsx)("p",{className:"muted",style:{fontSize:12,marginTop:4},children:this.state.error.message}),(0,t.jsx)("button",{className:"button secondary small",style:{marginTop:12},onClick:()=>{var e,s;this.setState({error:null}),null==(e=(s=this.props).onRetry)||e.call(s)},children:"Retry"})]})}return this.props.children}constructor(e){super(e),this.state={error:null}}}let c=["Overview","Projects","Risks","Mitigations","Gate","Integrations","Audit"],d=["Technical","Governance","Legal","Ethical","Operational"],o=["Design","Development","Testing","Deployment"],u=["OPEN","IN_MITIGATION","ACCEPTED","CLOSED"],m=["NOT_STARTED","IN_PROGRESS","DONE","REJECTED"];function h(e){let{toasts:s}=e;return s.length?(0,t.jsx)("div",{className:"toast-container",children:s.map(e=>(0,t.jsx)("div",{className:"toast ".concat(e.type),children:e.message},e.id))}):null}function j(e){let{value:s,onChange:a,placeholder:l}=e;return(0,t.jsxs)("div",{className:"search-wrap",children:[(0,t.jsx)("span",{className:"search-icon",children:"⌕"}),(0,t.jsx)("input",{className:"input",value:s,onChange:e=>a(e.target.value),placeholder:l||"Search..."})]})}function x(e,s,a){return s?[...e].sort((e,t)=>{let l=e[s],n=t[s];if(null==l)return 1;if(null==n)return -1;let i="number"==typeof l?l-n:String(l).localeCompare(String(n));return"asc"===a?i:-i}):e}function p(e){let{children:s,className:a}=e;return(0,t.jsx)("span",{className:"badge ".concat(a||""),children:s})}function v(e){let{label:s,children:a}=e;return(0,t.jsxs)("div",{style:{marginBottom:10},children:[(0,t.jsx)("label",{style:{display:"block",fontSize:12,color:"var(--muted)",marginBottom:3},children:s}),a]})}function g(e){let{value:s,onChange:a,type:l="text",min:n,max:i,style:r}=e;return(0,t.jsx)("input",{className:"input",type:l,value:s,onChange:e=>a(e.target.value),min:n,max:i,style:{width:"100%",...r}})}function y(e){let{value:s,onChange:a,options:l}=e;return(0,t.jsxs)("select",{className:"input",value:s,onChange:e=>a(e.target.value),style:{width:"100%"},children:[(0,t.jsx)("option",{value:"",children:"— Select —"}),(l||[]).map(e=>{let s="object"==typeof e?e.value:e,a="object"==typeof e?e.label:e;return(0,t.jsx)("option",{value:s,children:a},s)})]})}function b(e){let{label:s,onConfirm:a,onCancel:l,deleting:n}=e;return(0,t.jsx)("div",{className:"modal-overlay",onClick:l,children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:380},children:[(0,t.jsxs)("h3",{children:["Delete ",s,"?"]}),(0,t.jsx)("p",{style:{fontSize:13,color:"var(--muted)"},children:"This cannot be undone."}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:l,children:"Cancel"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff"},onClick:a,disabled:n,children:n?"Deleting...":"Delete"})]})]})})}function N(e){let{project:s,dashboard:a}=e,n=(0,l.useMemo)(()=>{var e,s,t,l,n,i,r,c,d,o,u,m,h,j,x,p,v,g,y;return a?[{label:"Overall Score",value:null!=(p=null==(e=a.summary)?void 0:e.overallScore)?p:"-",cls:(null==(s=a.summary)?void 0:s.overallScore)>=75?"bad":(null==(t=a.summary)?void 0:t.overallScore)>=50?"warn":"good",sub:"Risk level: ".concat((null==(l=a.summary)?void 0:l.riskLevel)||"-")},{label:"Deployment Gate",value:null!=(v=null==(n=a.summary)?void 0:n.gateStatus)?v:"-",cls:(null==(i=a.summary)?void 0:i.gateStatus)==="Ready"?"good":(null==(r=a.summary)?void 0:r.gateStatus)==="Warning"?"warn":"bad",sub:(null==(c=a.gate)?void 0:c.message)||""},{label:"Open Risks",value:null!=(g=null==(d=a.summary)?void 0:d.openRisks)?g:0,cls:((null==(o=a.summary)?void 0:o.openRisks)||0)>5?"bad":((null==(u=a.summary)?void 0:u.openRisks)||0)>2?"warn":"good",sub:"".concat((null==(m=a.summary)?void 0:m.totalRisks)||0," total risks")},{label:"Mitigation",value:"".concat(null!=(y=null==(h=a.summary)?void 0:h.mitigationCompletion)?y:0,"%"),cls:40>((null==(j=a.summary)?void 0:j.mitigationCompletion)||0)?"bad":70>((null==(x=a.summary)?void 0:x.mitigationCompletion)||0)?"warn":"good",sub:"Average active-risk completion"}]:[]},[a]);return a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))"},children:n.map(e=>(0,t.jsxs)("div",{className:"metric-card",children:[(0,t.jsx)("h3",{children:e.label}),(0,t.jsx)("div",{className:"metric-value ".concat(e.cls),children:e.value}),(0,t.jsx)("div",{className:"metric-sub",children:e.sub})]},e.label))}),(0,t.jsxs)("div",{className:"grid",style:{gridTemplateColumns:"1fr 1fr",marginTop:18},children:[(0,t.jsxs)("div",{className:"panel",children:[(0,t.jsx)("h2",{children:"Dimensions"}),(a.dimensions||[]).map(e=>(0,t.jsxs)("div",{style:{marginBottom:12},children:[(0,t.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[(0,t.jsx)("span",{style:{fontSize:13},children:e.name}),(0,t.jsx)("strong",{style:{fontSize:13},children:e.score})]}),(0,t.jsx)("div",{className:"bar-wrap",children:(0,t.jsx)("div",{className:"bar-fill",style:{width:"".concat(Math.min(e.score,100),"%"),background:e.score>=50?"var(--danger)":e.score>=25?"var(--warn)":"var(--accent)"}})})]},e.name))]}),(0,t.jsxs)("div",{className:"panel",children:[(0,t.jsx)("h2",{children:"Lifecycle"}),(a.lifecycle||[]).map(e=>(0,t.jsxs)("div",{style:{marginBottom:12},children:[(0,t.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[(0,t.jsx)("span",{style:{fontSize:13},children:e.name}),(0,t.jsxs)("span",{className:"muted",style:{fontSize:12},children:[e.openRisks," open"]})]}),(0,t.jsx)("div",{className:"bar-wrap",children:(0,t.jsx)("div",{className:"bar-fill",style:{width:"".concat(Math.min(e.riskScore||0,100),"%"),background:(e.riskScore||0)>=50?"var(--danger)":(e.riskScore||0)>=25?"var(--warn)":"var(--accent)"}})})]},e.name))]})]})]}):(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"Loading dashboard data..."})})}function f(e){let{project:s,onClose:a,onSaved:n,toast:r}=e,[c,u]=(0,l.useState)(!1),[m,h]=(0,l.useState)({title:"",description:"",dimension:"",domain:"",lifecyclePhase:"",probability:50,impact:50,detectability:50,ownerDisplayName:""}),j=e=>s=>h(a=>({...a,[e]:s})),x=async()=>{if(!m.title.trim())return void r.add("Title is required","error");if(!m.dimension)return void r.add("Dimension is required","error");u(!0);try{await i.FH.post("/api/projects/".concat(s.id,"/risks"),m),r.add("Risk created"),n()}catch(e){r.add(e.message||"Failed to create risk","error")}finally{u(!1)}};return(0,t.jsx)("div",{className:"modal-overlay",onClick:a,children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:500},children:[(0,t.jsx)("h2",{children:"New Risk"}),(0,t.jsx)(v,{label:"Title *",children:(0,t.jsx)(g,{value:m.title,onChange:j("title")})}),(0,t.jsx)(v,{label:"Description",children:(0,t.jsx)("textarea",{className:"input",value:m.description,onChange:e=>j("description")(e.target.value),rows:3,style:{width:"100%",resize:"vertical"}})}),(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[(0,t.jsx)(v,{label:"Dimension *",children:(0,t.jsx)(y,{value:m.dimension,onChange:j("dimension"),options:d})}),(0,t.jsx)(v,{label:"Domain",children:(0,t.jsx)(g,{value:m.domain,onChange:j("domain")})})]}),(0,t.jsx)(v,{label:"Lifecycle Phase",children:(0,t.jsx)(y,{value:m.lifecyclePhase,onChange:j("lifecyclePhase"),options:o})}),(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:8},children:[(0,t.jsx)(v,{label:"Probability",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:m.probability,onChange:j("probability")})}),(0,t.jsx)(v,{label:"Impact",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:m.impact,onChange:j("impact")})}),(0,t.jsx)(v,{label:"Detectability",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:m.detectability,onChange:j("detectability")})})]}),(0,t.jsx)(v,{label:"Owner",children:(0,t.jsx)(g,{value:m.ownerDisplayName,onChange:j("ownerDisplayName")})}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:a,children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:x,disabled:c,children:c?"Saving...":"Create Risk"})]})]})})}function C(e){let{project:s,dashboard:a,toast:n,onRefresh:r}=e,[c,m]=(0,l.useState)(""),[h,N]=(0,l.useState)("normalizedScore"),[C,k]=(0,l.useState)("desc"),[S,w]=(0,l.useState)(0),[P,D]=(0,l.useState)(null),[T,R]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[E,F]=(0,l.useState)({}),[L,O]=(0,l.useState)(null),[z,M]=(0,l.useState)(null),[H,_]=(0,l.useState)(!1),W=(0,l.useMemo)(()=>(null==a?void 0:a.topRisks)?x(a.topRisks,h,C):[],[a,h,C]),G=(0,l.useMemo)(()=>{if(!c)return W;let e=c.toLowerCase();return W.filter(s=>(s.title||"").toLowerCase().includes(e)||(s.dimension||"").toLowerCase().includes(e)||(s.ownerDisplayName||"").toLowerCase().includes(e))},[W,c]),q=G.slice(0,(S+1)*20),B=async(e,s)=>{O(e);try{await i.FH.patch("/api/risks/".concat(e),{status:s}),n.add("Risk status updated to ".concat(s)),D(null),r()}catch(e){n.add(e.message,"error")}finally{O(null)}},J=async()=>{if(!E.title.trim())return void n.add("Title is required","error");O("edit");try{await i.FH.patch("/api/risks/".concat(P.id),E),n.add("Risk updated"),D(null),r()}catch(e){n.add(e.message||"Failed to update","error")}finally{O(null)}},U=async()=>{_(!0);try{await i.FH.del("/api/risks/".concat(z.id)),n.add("Risk deleted"),M(null),D(null),r()}catch(e){n.add(e.message||"Failed to delete","error")}finally{_(!1)}};return a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:12},children:[(0,t.jsx)(j,{value:c,onChange:m,placeholder:"Search risks by title, dimension, owner..."}),(0,t.jsx)("button",{className:"button small",onClick:()=>R(!0),children:"+ New Risk"})]}),(0,t.jsx)("div",{className:"table-wrap",children:(0,t.jsxs)("table",{className:"table",children:[(0,t.jsx)("thead",{children:(0,t.jsx)("tr",{children:[{key:"id",label:"ID"},{key:"title",label:"Risk"},{key:"dimension",label:"Dimension"},{key:"lifecyclePhase",label:"Phase"},{key:"normalizedScore",label:"Score"},{key:"residualScore",label:"Residual"},{key:"status",label:"Status"},{key:"ownerDisplayName",label:"Owner"}].map(e=>(0,t.jsxs)("th",{className:"sortable",onClick:()=>{var s;h===(s=e.key)?k(e=>"asc"===e?"desc":"asc"):(N(s),k("asc"))},children:[e.label," ",h===e.key?"asc"===C?"▲":"▼":""]},e.key))})}),(0,t.jsx)("tbody",{children:q.map(e=>{var s,a,l;return(0,t.jsxs)("tr",{onClick:()=>{var s,a,t;D(e),F({title:e.title||"",description:e.description||"",dimension:e.dimension||"",domain:e.domain||"",lifecyclePhase:e.lifecyclePhase||"",probability:null!=(s=e.probability)?s:50,impact:null!=(a=e.impact)?a:50,detectability:null!=(t=e.detectability)?t:50,ownerDisplayName:e.ownerDisplayName||""}),I(!1),M(null)},children:[(0,t.jsx)("td",{style:{fontFamily:"monospace",fontSize:12},children:null==(s=e.id)?void 0:s.slice(0,8)}),(0,t.jsx)("td",{children:(0,t.jsx)("strong",{children:e.title})}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(a=e.dimension)?void 0:a.toLowerCase(),children:e.dimension})}),(0,t.jsx)("td",{style:{fontSize:12},children:e.lifecyclePhase}),(0,t.jsx)("td",{children:(0,t.jsx)("strong",{children:e.normalizedScore})}),(0,t.jsx)("td",{children:(0,t.jsx)("span",{style:{color:e.residualScore>=50?"var(--danger)":e.residualScore>=25?"var(--warn)":"var(--accent)"},children:e.residualScore})}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(l=e.status)?void 0:l.toLowerCase().replace(/\s+/g,"-"),children:e.status})}),(0,t.jsx)("td",{children:(0,t.jsx)("span",{className:"muted",children:e.ownerDisplayName||"-"})})]},e.id)})})]})}),G.length>q.length&&(0,t.jsx)("div",{style:{textAlign:"center",marginTop:12},children:(0,t.jsxs)("button",{className:"button secondary small",onClick:()=>w(e=>e+1),children:["Show more (",G.length-q.length," remaining)"]})}),!G.length&&(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"No risks match your search"})}),T&&(0,t.jsx)(f,{project:s,onClose:()=>R(!1),onSaved:()=>{R(!1),r()},toast:n}),P&&!z&&(0,t.jsx)("div",{className:"modal-overlay",onClick:()=>D(null),children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:520},children:[(0,t.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,t.jsx)("h2",{style:{margin:0},children:P.title}),(0,t.jsx)("button",{className:"button secondary small",onClick:()=>I(!A),children:A?"View":"Edit"})]}),A?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{style:{marginTop:12},children:[(0,t.jsx)(v,{label:"Title *",children:(0,t.jsx)(g,{value:E.title,onChange:e=>F(s=>({...s,title:e}))})}),(0,t.jsx)(v,{label:"Description",children:(0,t.jsx)("textarea",{className:"input",value:E.description,onChange:e=>F(s=>({...s,description:e.target.value})),rows:2,style:{width:"100%",resize:"vertical"}})}),(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[(0,t.jsx)(v,{label:"Dimension",children:(0,t.jsx)(y,{value:E.dimension,onChange:e=>F(s=>({...s,dimension:e})),options:d})}),(0,t.jsx)(v,{label:"Domain",children:(0,t.jsx)(g,{value:E.domain,onChange:e=>F(s=>({...s,domain:e}))})})]}),(0,t.jsx)(v,{label:"Lifecycle Phase",children:(0,t.jsx)(y,{value:E.lifecyclePhase,onChange:e=>F(s=>({...s,lifecyclePhase:e})),options:o})}),(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:8},children:[(0,t.jsx)(v,{label:"Probability",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:E.probability,onChange:e=>F(s=>({...s,probability:Number(e)}))})}),(0,t.jsx)(v,{label:"Impact",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:E.impact,onChange:e=>F(s=>({...s,impact:Number(e)}))})}),(0,t.jsx)(v,{label:"Detectability",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:E.detectability,onChange:e=>F(s=>({...s,detectability:Number(e)}))})})]}),(0,t.jsx)(v,{label:"Owner",children:(0,t.jsx)(g,{value:E.ownerDisplayName,onChange:e=>F(s=>({...s,ownerDisplayName:e}))})})]}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:()=>D(null),children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:J,disabled:"edit"===L,children:"edit"===L?"Saving...":"Save Changes"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff",marginLeft:"auto"},onClick:()=>M(P),children:"Delete"})]})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12,fontSize:13,marginTop:12},children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Dimension"}),(0,t.jsx)("br",{}),P.dimension]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Phase"}),(0,t.jsx)("br",{}),P.lifecyclePhase]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Probability"}),(0,t.jsx)("br",{}),P.probability]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Impact"}),(0,t.jsx)("br",{}),P.impact]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Detectability"}),(0,t.jsx)("br",{}),P.detectability]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Score"}),(0,t.jsx)("br",{}),(0,t.jsx)("strong",{children:P.normalizedScore})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Residual"}),(0,t.jsx)("br",{}),P.residualScore]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"muted",children:"Owner"}),(0,t.jsx)("br",{}),P.ownerDisplayName||"-"]})]}),P.description&&(0,t.jsxs)("div",{style:{marginTop:12,fontSize:13},children:[(0,t.jsx)("span",{className:"muted",children:"Description"}),(0,t.jsx)("br",{}),P.description]}),(0,t.jsxs)("div",{style:{marginTop:16},children:[(0,t.jsx)("span",{className:"muted",style:{fontSize:12},children:"Update status:"}),(0,t.jsx)("div",{style:{display:"flex",gap:6,marginTop:6,flexWrap:"wrap"},children:u.map(e=>(0,t.jsx)("button",{className:"button small ".concat("OPEN"===e?"secondary":""),onClick:()=>B(P.id,e),disabled:L===P.id,children:e.replace("_"," ")},e))})]}),(0,t.jsx)("div",{className:"modal-actions",children:(0,t.jsx)("button",{className:"button secondary small",onClick:()=>D(null),children:"Close"})})]})]})}),z&&(0,t.jsx)(b,{label:"this risk",onConfirm:U,onCancel:()=>M(null),deleting:H})]}):(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"Loading..."})})}function k(e){let{project:s,risks:a,onClose:n,onSaved:r,toast:c}=e,[d,o]=(0,l.useState)(!1),[u,h]=(0,l.useState)({riskId:"",title:"",description:"",status:"NOT_STARTED",progressPercent:0,effectivenessPercent:0,dueDate:"",ownerDisplayName:""}),j=e=>s=>h(a=>({...a,[e]:s})),x=async()=>{if(!u.title.trim())return void c.add("Title is required","error");if(!u.riskId)return void c.add("Please select a risk","error");o(!0);try{let e={...u,progressPercent:Number(u.progressPercent),effectivenessPercent:Number(u.effectivenessPercent)};e.dueDate?e.dueDate=new Date(e.dueDate).toISOString():delete e.dueDate,await i.FH.post("/api/risks/".concat(u.riskId,"/mitigations"),e),c.add("Mitigation created"),r()}catch(e){c.add(e.message||"Failed to create mitigation","error")}finally{o(!1)}};return(0,t.jsx)("div",{className:"modal-overlay",onClick:n,children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:500},children:[(0,t.jsx)("h2",{children:"New Mitigation"}),(0,t.jsx)(v,{label:"Risk *",children:(0,t.jsx)(y,{value:u.riskId,onChange:j("riskId"),options:(a||[]).map(e=>({value:e.id,label:e.title}))})}),(0,t.jsx)(v,{label:"Title *",children:(0,t.jsx)(g,{value:u.title,onChange:j("title")})}),(0,t.jsx)(v,{label:"Description",children:(0,t.jsx)("textarea",{className:"input",value:u.description,onChange:e=>j("description")(e.target.value),rows:2,style:{width:"100%",resize:"vertical"}})}),(0,t.jsx)(v,{label:"Status",children:(0,t.jsx)(y,{value:u.status,onChange:j("status"),options:m})}),(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[(0,t.jsx)(v,{label:"Progress %",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:u.progressPercent,onChange:j("progressPercent")})}),(0,t.jsx)(v,{label:"Effectiveness %",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:u.effectivenessPercent,onChange:j("effectivenessPercent")})})]}),(0,t.jsx)(v,{label:"Due Date",children:(0,t.jsx)(g,{type:"date",value:u.dueDate,onChange:j("dueDate")})}),(0,t.jsx)(v,{label:"Owner",children:(0,t.jsx)(g,{value:u.ownerDisplayName,onChange:j("ownerDisplayName")})}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:n,children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:x,disabled:d,children:d?"Saving...":"Create Mitigation"})]})]})})}function S(e){let{project:s,dashboard:a,toast:n,onRefresh:r}=e,[c,d]=(0,l.useState)(""),[o,u]=(0,l.useState)("progressPercent"),[h,N]=(0,l.useState)("asc"),[f,C]=(0,l.useState)(!1),[S,w]=(0,l.useState)(null),[P,D]=(0,l.useState)(!1),[T,R]=(0,l.useState)({}),[A,I]=(0,l.useState)(null),[E,F]=(0,l.useState)(null),[L,O]=(0,l.useState)(!1),z=(0,l.useMemo)(()=>(null==a?void 0:a.mitigations)?x(a.mitigations,o,h):[],[a,o,h]),M=(0,l.useMemo)(()=>(null==a?void 0:a.topRisks)?a.topRisks:[],[a]),H=(0,l.useMemo)(()=>{if(!c)return z;let e=c.toLowerCase();return z.filter(s=>(s.title||"").toLowerCase().includes(e)||(s.riskTitle||"").toLowerCase().includes(e))},[z,c]),_=async()=>{if(!T.title.trim())return void n.add("Title is required","error");I("edit");try{let e={...T,progressPercent:Number(T.progressPercent),effectivenessPercent:Number(T.effectivenessPercent)};e.dueDate?e.dueDate=new Date(e.dueDate).toISOString():e.dueDate=null,await i.FH.patch("/api/mitigations/".concat(S.id),e),n.add("Mitigation updated"),w(null),r()}catch(e){n.add(e.message||"Failed to update","error")}finally{I(null)}},W=async()=>{O(!0);try{await i.FH.del("/api/mitigations/".concat(E.id)),n.add("Mitigation deleted"),F(null),w(null),r()}catch(e){n.add(e.message||"Failed to delete","error")}finally{O(!1)}};return a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:12},children:[(0,t.jsx)(j,{value:c,onChange:d,placeholder:"Search mitigations..."}),(0,t.jsx)("button",{className:"button small",onClick:()=>C(!0),children:"+ New Mitigation"})]}),(0,t.jsx)("div",{className:"table-wrap",children:(0,t.jsxs)("table",{className:"table",children:[(0,t.jsx)("thead",{children:(0,t.jsx)("tr",{children:[{key:"title",label:"Title"},{key:"riskTitle",label:"Risk"},{key:"status",label:"Status"},{key:"progressPercent",label:"Progress"},{key:"effectivenessPercent",label:"Effectiveness"},{key:"ownerDisplayName",label:"Owner"}].map(e=>(0,t.jsxs)("th",{className:"sortable",onClick:()=>{var s;o===(s=e.key)?N(e=>"asc"===e?"desc":"asc"):(u(s),N("asc"))},children:[e.label," ",o===e.key?"asc"===h?"▲":"▼":""]},e.key))})}),(0,t.jsx)("tbody",{children:H.slice(0,50).map(e=>{var s;return(0,t.jsxs)("tr",{onClick:()=>{var s,a;w(e),R({title:e.title||"",description:e.description||"",status:e.status||"NOT_STARTED",progressPercent:null!=(s=e.progressPercent)?s:0,effectivenessPercent:null!=(a=e.effectivenessPercent)?a:0,dueDate:e.dueDate?e.dueDate.slice(0,10):"",ownerDisplayName:e.ownerDisplayName||""}),D(!0),F(null)},style:{cursor:"pointer"},children:[(0,t.jsx)("td",{children:(0,t.jsx)("strong",{children:e.title})}),(0,t.jsx)("td",{children:(0,t.jsx)("span",{className:"muted",children:e.riskTitle})}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(s=e.status)?void 0:s.toLowerCase().replace(/\s+/g,"-"),children:e.status})}),(0,t.jsx)("td",{children:(0,t.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,t.jsx)("div",{className:"bar-wrap",style:{flex:1,maxWidth:80},children:(0,t.jsx)("div",{className:"bar-fill",style:{width:"".concat(e.progressPercent||0,"%"),background:(e.progressPercent||0)>=80?"var(--accent)":(e.progressPercent||0)>=30?"var(--warn)":"var(--danger)"}})}),e.progressPercent||0,"%"]})}),(0,t.jsxs)("td",{children:[e.effectivenessPercent||0,"%"]}),(0,t.jsx)("td",{children:(0,t.jsx)("span",{className:"muted",children:e.ownerDisplayName||"-"})})]},e.id)})})]})}),!H.length&&(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"No mitigations found"})}),f&&(0,t.jsx)(k,{project:s,risks:M,onClose:()=>C(!1),onSaved:()=>{C(!1),r()},toast:n}),S&&!E&&(0,t.jsx)("div",{className:"modal-overlay",onClick:()=>w(null),children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:500},children:[(0,t.jsx)("h2",{style:{margin:0},children:P?"Edit Mitigation":S.title}),(0,t.jsxs)("div",{style:{marginTop:12},children:[(0,t.jsx)(v,{label:"Title *",children:(0,t.jsx)(g,{value:T.title,onChange:e=>R(s=>({...s,title:e}))})}),(0,t.jsx)(v,{label:"Description",children:(0,t.jsx)("textarea",{className:"input",value:T.description,onChange:e=>R(s=>({...s,description:e.target.value})),rows:2,style:{width:"100%",resize:"vertical"}})}),(0,t.jsx)(v,{label:"Status",children:(0,t.jsx)(y,{value:T.status,onChange:e=>R(s=>({...s,status:e})),options:m})}),(0,t.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[(0,t.jsx)(v,{label:"Progress %",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:T.progressPercent,onChange:e=>R(s=>({...s,progressPercent:Number(e)}))})}),(0,t.jsx)(v,{label:"Effectiveness %",children:(0,t.jsx)(g,{type:"number",min:0,max:100,value:T.effectivenessPercent,onChange:e=>R(s=>({...s,effectivenessPercent:Number(e)}))})})]}),(0,t.jsx)(v,{label:"Due Date",children:(0,t.jsx)(g,{type:"date",value:T.dueDate,onChange:e=>R(s=>({...s,dueDate:e}))})}),(0,t.jsx)(v,{label:"Owner",children:(0,t.jsx)(g,{value:T.ownerDisplayName,onChange:e=>R(s=>({...s,ownerDisplayName:e}))})})]}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:()=>w(null),children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:_,disabled:"edit"===A,children:"edit"===A?"Saving...":"Save Changes"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff",marginLeft:"auto"},onClick:()=>F(S),children:"Delete"})]})]})}),E&&(0,t.jsx)(b,{label:"this mitigation",onConfirm:W,onCancel:()=>F(null),deleting:L})]}):(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"Loading..."})})}function w(e){var s,a,n;let{project:r,dashboard:c,toast:d,onRefresh:o}=e,[u,m]=(0,l.useState)(!1),[h,j]=(0,l.useState)(!1),[x,b]=(0,l.useState)({decision:"APPROVED",reviewerName:"",reason:""}),[N,f]=(0,l.useState)(!1),C=(null==c||null==(s=c.gate)?void 0:s.criteria)||[],k=(null==c||null==(a=c.summary)?void 0:a.gateStatus)||"Unknown",S=null==c||null==(n=c.gate)?void 0:n.id,w="Ready"===k?"good":"Warning"===k?"warn":"bad",P=async()=>{m(!0);try{await i.FH.post("/api/projects/".concat(r.id,"/gate/evaluate"),{}),d.add("Gate evaluated"),o()}catch(e){d.add(e.message||"Evaluation failed","error")}finally{m(!1)}},D=async()=>{if(!x.reviewerName.trim())return void d.add("Reviewer name is required","error");f(!0);try{await i.FH.post("/api/gates/".concat(S,"/decisions"),x),d.add("Decision submitted"),j(!1),o()}catch(e){d.add(e.message||"Failed to submit decision","error")}finally{f(!1)}};return c?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dash-header",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{children:"Deployment Gate"}),(0,t.jsx)("p",{className:"muted",children:"Gate evaluation for AI deployment readiness"})]}),(0,t.jsx)("div",{className:"dash-actions",children:(0,t.jsx)("div",{className:"metric-value ".concat(w),style:{fontSize:28},children:k})})]}),(0,t.jsx)("div",{className:"table-wrap",children:(0,t.jsxs)("table",{className:"table",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{children:"Criterion"}),(0,t.jsx)("th",{children:"Required"}),(0,t.jsx)("th",{children:"Actual"}),(0,t.jsx)("th",{children:"Status"})]})}),(0,t.jsx)("tbody",{children:C.map(e=>{var s;return(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("strong",{children:e.name})}),(0,t.jsx)("td",{children:e.required}),(0,t.jsx)("td",{children:e.actual}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(s=e.status)?void 0:s.toLowerCase(),children:e.status})})]},e.name)})})]})}),!C.length&&(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"No gate criteria evaluated yet"})}),(0,t.jsxs)("div",{style:{marginTop:16,display:"flex",gap:8,flexWrap:"wrap"},children:[(0,t.jsx)("button",{className:"button small",onClick:P,disabled:u,children:u?"Evaluating...":"Evaluate Gate"}),S&&(0,t.jsx)("button",{className:"button secondary small",onClick:()=>j(!0),children:"Add Decision"}),(0,t.jsx)("a",{href:"/api/projects/".concat(null==r?void 0:r.id,"/gate/history"),className:"button secondary small",target:"_blank",children:"History (API)"})]}),h&&(0,t.jsx)("div",{className:"modal-overlay",onClick:()=>j(!1),children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:400},children:[(0,t.jsx)("h2",{children:"Gate Decision"}),(0,t.jsx)(v,{label:"Decision",children:(0,t.jsx)(y,{value:x.decision,onChange:e=>b(s=>({...s,decision:e})),options:["APPROVED","REJECTED","ACCEPTED","NEEDS_CHANGES"]})}),(0,t.jsx)(v,{label:"Reviewer Name *",children:(0,t.jsx)(g,{value:x.reviewerName,onChange:e=>b(s=>({...s,reviewerName:e}))})}),(0,t.jsx)(v,{label:"Reason",children:(0,t.jsx)("textarea",{className:"input",value:x.reason,onChange:e=>b(s=>({...s,reason:e.target.value})),rows:3,style:{width:"100%",resize:"vertical"}})}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:()=>j(!1),children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:D,disabled:N,children:N?"Saving...":"Submit Decision"})]})]})})]}):(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"Loading..."})})}function P(e){var s;let{project:a,dashboard:n,onClose:r,onSaved:c,toast:d}=e,[o,u]=(0,l.useState)(!1),[m,h]=(0,l.useState)({provider:"TRELLO",workspaceName:"",baseUrl:"",authMode:"API_KEY"}),j=e=>s=>h(a=>({...a,[e]:s})),x=(null==n||null==(s=n.gate)?void 0:s.workspaceId)||(null==a?void 0:a.workspaceId),p=async()=>{if(!m.workspaceName.trim())return void d.add("Workspace name is required","error");u(!0);try{await i.FH.post("/api/workspaces/".concat(x,"/integrations"),m),d.add("Integration created"),c()}catch(e){d.add(e.message||"Failed to create integration","error")}finally{u(!1)}};return(0,t.jsx)("div",{className:"modal-overlay",onClick:r,children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:450},children:[(0,t.jsx)("h2",{children:"New Integration"}),(0,t.jsx)(v,{label:"Provider",children:(0,t.jsx)(y,{value:m.provider,onChange:j("provider"),options:["TRELLO","JIRA","ASANA","MICROSOFT_PLANNER"]})}),(0,t.jsx)(v,{label:"Workspace Name *",children:(0,t.jsx)(g,{value:m.workspaceName,onChange:j("workspaceName")})}),(0,t.jsx)(v,{label:"Base URL",children:(0,t.jsx)(g,{value:m.baseUrl,onChange:j("baseUrl")})}),(0,t.jsx)(v,{label:"Auth Mode",children:(0,t.jsx)(y,{value:m.authMode,onChange:j("authMode"),options:["API_KEY","OAUTH","BASIC"]})}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:r,children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:p,disabled:o,children:o?"Saving...":"Create Integration"})]})]})})}function D(e){let{project:s,dashboard:a,toast:n,onRefresh:i}=e,[r,c]=(0,l.useState)(!1),d=(null==a?void 0:a.integrations)||[];return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dash-header",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{children:"Integrations"}),(0,t.jsx)("p",{className:"muted",children:"Connect Trello, Jira, Asana, or Microsoft Planner"})]}),(0,t.jsx)("div",{className:"dash-actions",children:(0,t.jsx)("button",{className:"button small",onClick:()=>c(!0),children:"+ New Integration"})})]}),(0,t.jsx)("div",{className:"grid",style:{gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))"},children:["TRELLO","JIRA","ASANA","MICROSOFT_PLANNER"].map(e=>{let s=d.find(s=>s.provider===e);return(0,t.jsxs)("div",{className:"panel",style:{textAlign:"center"},children:[(0,t.jsx)("div",{style:{fontSize:32,marginBottom:8},children:"TRELLO"===e?"⊞":"JIRA"===e?"◆":"ASANA"===e?"◇":"▣"}),(0,t.jsx)("h3",{style:{margin:"0 0 4px"},children:e.replace("_"," ")}),(0,t.jsx)("p",{className:"muted",style:{fontSize:12,margin:"0 0 12px"},children:s?s.workspaceName:"Not configured"}),(0,t.jsx)("div",{style:{display:"flex",gap:6,justifyContent:"center"},children:s?(0,t.jsx)("a",{href:"/api/integrations/".concat(s.id),className:"button secondary small",target:"_blank",children:"Manage"}):(0,t.jsx)("button",{className:"button secondary small",onClick:()=>c(!0),children:"Configure"})})]},e)})}),r&&(0,t.jsx)(P,{project:s,dashboard:a,onClose:()=>c(!1),onSaved:()=>{c(!1),i()},toast:n}),!d.length&&(0,t.jsx)("div",{style:{marginTop:12},children:(0,t.jsx)("a",{href:"/api/integration-providers",className:"button secondary small",target:"_blank",children:"Integration providers (API)"})})]})}function T(e){let{project:s,toast:a}=e,[n,r]=(0,l.useState)([]),[c,d]=(0,l.useState)(!0),[o,u]=(0,l.useState)(null),m=(0,l.useCallback)(async()=>{if(s){d(!0),u(null);try{let e=await i.FH.get("/api/projects/".concat(s.id,"/audit"));r(e.auditEvents||[])}catch(e){u(e.message||"Failed to load audit log")}finally{d(!1)}}},[s]);return((0,l.useEffect)(()=>{m()},[m]),c)?(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"Loading audit log..."})}):o?(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:o})}):n.length?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dash-header",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{children:"Audit Log"}),(0,t.jsx)("p",{className:"muted",children:"Project activity history"})]}),(0,t.jsx)("div",{className:"dash-actions",children:(0,t.jsx)("button",{className:"button secondary small",onClick:m,children:"Refresh"})})]}),(0,t.jsx)("div",{className:"table-wrap",children:(0,t.jsxs)("table",{className:"table",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{children:"Date"}),(0,t.jsx)("th",{children:"Action"}),(0,t.jsx)("th",{children:"Entity"}),(0,t.jsx)("th",{children:"Actor"}),(0,t.jsx)("th",{children:"Details"})]})}),(0,t.jsx)("tbody",{children:n.map(e=>{var s,a;return(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{style:{fontSize:12,whiteSpace:"nowrap"},children:new Date(e.createdAt).toLocaleString()}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(s=e.action)?void 0:s.toLowerCase().replace(/\s+/g,"-"),children:e.action})}),(0,t.jsxs)("td",{style:{fontSize:12},children:[e.entityType," ",(0,t.jsxs)("span",{className:"muted",children:["(",null==(a=e.entityId)?void 0:a.slice(0,8),")"]})]}),(0,t.jsx)("td",{style:{fontSize:12},children:e.actorUserId||"system"}),(0,t.jsx)("td",{style:{fontSize:12,maxWidth:300,overflow:"hidden",textOverflow:"ellipsis"},children:e.afterJson?JSON.stringify(e.afterJson).slice(0,80):"-"})]},e.id)})})]})})]}):(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"No audit events recorded yet"})})}function R(e){let{projects:s,workspaceId:a,currentProjectId:n,onSwitch:r,onRefresh:c,toast:d}=e,[o,u]=(0,l.useState)(null),[m,h]=(0,l.useState)(null),[j,x]=(0,l.useState)(!1),v=async()=>{u(!0);try{await i.FH.del("/api/projects/".concat(m.id)),d.add('Project "'.concat(m.name,'" deleted')),h(null),c()}catch(e){d.add(e.message||"Failed to delete project","error")}finally{u(!1)}};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dash-header",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{children:"All Projects"}),(0,t.jsxs)("p",{className:"muted",children:[s.length," project(s) in workspace"]})]}),(0,t.jsx)("div",{className:"dash-actions",children:(0,t.jsx)("button",{className:"button small",onClick:()=>x(!0),children:"+ New Project"})})]}),(0,t.jsx)("div",{className:"table-wrap",children:(0,t.jsxs)("table",{className:"table",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{children:"Name"}),(0,t.jsx)("th",{children:"Status"}),(0,t.jsx)("th",{children:"Type"}),(0,t.jsx)("th",{children:"Created"}),(0,t.jsx)("th",{children:"Actions"})]})}),(0,t.jsx)("tbody",{children:[...s].sort((e,s)=>new Date(s.createdAt)-new Date(e.createdAt)).map(e=>{var s;return(0,t.jsxs)("tr",{style:{background:e.id===n?"var(--surface-alt)":""},children:[(0,t.jsxs)("td",{children:[(0,t.jsx)("strong",{children:e.name}),e.id===n?(0,t.jsx)("span",{className:"muted",style:{fontSize:11,marginLeft:6},children:"(current)"}):"",e.description?(0,t.jsx)("div",{className:"muted",style:{fontSize:11},children:e.description}):""]}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(s=e.status)?void 0:s.toLowerCase(),children:e.status})}),(0,t.jsx)("td",{style:{fontSize:12},children:e.projectType}),(0,t.jsx)("td",{style:{fontSize:12},children:new Date(e.createdAt).toLocaleDateString()}),(0,t.jsxs)("td",{style:{textAlign:"right",whiteSpace:"nowrap"},children:[e.id!==n&&(0,t.jsx)("button",{className:"button secondary small",style:{marginRight:6},onClick:()=>r(e.id),children:"Open"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff"},onClick:()=>h(e),disabled:o===e.id,children:"Delete"})]})]},e.id)})})]})}),!s.length&&(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"No projects yet. Create one to get started."})}),j&&(0,t.jsx)(I,{workspaceId:a,onClose:()=>x(!1),onSaved:()=>{x(!1),c()},toast:d}),m&&(0,t.jsx)("div",{className:"modal-overlay",onClick:()=>h(null),children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:380},children:[(0,t.jsxs)("h3",{children:['Delete "',m.name,'"?']}),(0,t.jsx)("p",{style:{fontSize:13,color:"var(--muted)"},children:"This permanently deletes the project and all its risks, mitigations, and data."}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:()=>h(null),children:"Cancel"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff"},onClick:v,disabled:o,children:o?"Deleting...":"Delete Project"})]})]})})]})}function A(e){let{project:s,onClose:a,onSaved:n,toast:r}=e,[c,d]=(0,l.useState)(!1),[o,u]=(0,l.useState)({name:(null==s?void 0:s.name)||"",description:(null==s?void 0:s.description)||"",subtitle:(null==s?void 0:s.subtitle)||"",status:(null==s?void 0:s.status)||"Active"}),m=async()=>{if(!o.name.trim())return void r.add("Project name is required","error");d(!0);try{await i.FH.patch("/api/projects/".concat(s.id),o),r.add("Project updated"),n()}catch(e){r.add(e.message||"Failed to update project","error")}finally{d(!1)}};return(0,t.jsx)("div",{className:"modal-overlay",onClick:a,children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:450},children:[(0,t.jsx)("h2",{children:"Project Settings"}),(0,t.jsx)(v,{label:"Name *",children:(0,t.jsx)(g,{value:o.name,onChange:e=>u(s=>({...s,name:e}))})}),(0,t.jsx)(v,{label:"Subtitle",children:(0,t.jsx)(g,{value:o.subtitle,onChange:e=>u(s=>({...s,subtitle:e}))})}),(0,t.jsx)(v,{label:"Description",children:(0,t.jsx)("textarea",{className:"input",value:o.description,onChange:e=>u(s=>({...s,description:e.target.value})),rows:3,style:{width:"100%",resize:"vertical"}})}),(0,t.jsx)(v,{label:"Status",children:(0,t.jsx)(y,{value:o.status,onChange:e=>u(s=>({...s,status:e})),options:["Active","Archived","On Hold"]})}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:a,children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:m,disabled:c,children:c?"Saving...":"Save Changes"})]})]})})}function I(e){let{workspaceId:s,onClose:a,onSaved:n,toast:r}=e,[c,d]=(0,l.useState)(!1),[o,u]=(0,l.useState)({name:"",description:"",projectType:"AI-Enabler"}),m=async()=>{if(!o.name.trim())return void r.add("Project name is required","error");d(!0);try{await i.FH.post("/api/workspaces/".concat(s,"/projects"),o),r.add("Project created"),n()}catch(e){r.add(e.message||"Failed to create project","error")}finally{d(!1)}};return(0,t.jsx)("div",{className:"modal-overlay",onClick:a,children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:450},children:[(0,t.jsx)("h2",{children:"New Project"}),(0,t.jsx)(v,{label:"Name *",children:(0,t.jsx)(g,{value:o.name,onChange:e=>u(s=>({...s,name:e}))})}),(0,t.jsx)(v,{label:"Description",children:(0,t.jsx)("textarea",{className:"input",value:o.description,onChange:e=>u(s=>({...s,description:e.target.value})),rows:3,style:{width:"100%",resize:"vertical"}})}),(0,t.jsx)(v,{label:"Project Type",children:(0,t.jsx)(y,{value:o.projectType,onChange:e=>u(s=>({...s,projectType:e})),options:["AI-Enabler","GENERATIVE_AI","ML-Pipeline","Automation"]})}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:a,children:"Cancel"}),(0,t.jsx)("button",{className:"button small",onClick:m,disabled:c,children:c?"Saving...":"Create Project"})]})]})})}function E(e){let{projects:s,workspaceId:a,currentProjectId:n,onClose:r,onSwitch:c,onSaved:d,toast:o}=e,[u,m]=(0,l.useState)(null),[h,j]=(0,l.useState)(null),[x,v]=(0,l.useState)(!1),g=async()=>{m(!0);try{await i.FH.del("/api/projects/".concat(h.id)),o.add('Project "'.concat(h.name,'" deleted')),j(null),d()}catch(e){o.add(e.message||"Failed to delete project","error")}finally{m(!1)}};return(0,t.jsxs)("div",{className:"modal-overlay",onClick:r,children:[(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:700,maxHeight:"80vh",overflow:"auto"},children:[(0,t.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,t.jsx)("h2",{style:{margin:0},children:"All Projects"}),(0,t.jsx)("button",{className:"button small",onClick:()=>v(!0),children:"+ New Project"})]}),(0,t.jsxs)("p",{className:"muted",style:{fontSize:12,marginTop:4},children:[s.length," project(s) in workspace"]}),(0,t.jsx)("div",{className:"table-wrap",style:{marginTop:12},children:(0,t.jsxs)("table",{className:"table",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{children:"Name"}),(0,t.jsx)("th",{children:"Status"}),(0,t.jsx)("th",{children:"Type"}),(0,t.jsx)("th",{children:"Created"}),(0,t.jsx)("th",{})]})}),(0,t.jsx)("tbody",{children:[...s].sort((e,s)=>new Date(s.createdAt)-new Date(e.createdAt)).map(e=>{var s;return(0,t.jsxs)("tr",{style:{background:e.id===n?"var(--surface-alt)":""},children:[(0,t.jsxs)("td",{children:[(0,t.jsx)("strong",{children:e.name}),e.id===n?(0,t.jsx)("span",{className:"muted",style:{fontSize:11,marginLeft:6},children:"(current)"}):""]}),(0,t.jsx)("td",{children:(0,t.jsx)(p,{className:null==(s=e.status)?void 0:s.toLowerCase(),children:e.status})}),(0,t.jsx)("td",{style:{fontSize:12},children:e.projectType}),(0,t.jsx)("td",{style:{fontSize:12},children:new Date(e.createdAt).toLocaleDateString()}),(0,t.jsxs)("td",{style:{textAlign:"right",whiteSpace:"nowrap"},children:[e.id!==n&&(0,t.jsx)("button",{className:"button secondary small",style:{marginRight:6},onClick:()=>{c(e.id),r()},children:"Open"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff"},onClick:()=>j(e),disabled:u===e.id,children:"✕"})]})]},e.id)})})]})}),!s.length&&(0,t.jsx)("div",{className:"empty-state",children:(0,t.jsx)("p",{children:"No projects yet"})}),(0,t.jsx)("div",{className:"modal-actions",children:(0,t.jsx)("button",{className:"button secondary small",onClick:r,children:"Close"})})]}),h&&(0,t.jsx)("div",{className:"modal-overlay",onClick:()=>j(null),children:(0,t.jsxs)("div",{className:"modal",onClick:e=>e.stopPropagation(),style:{maxWidth:380},children:[(0,t.jsxs)("h3",{children:['Delete "',h.name,'"?']}),(0,t.jsx)("p",{style:{fontSize:13,color:"var(--muted)"},children:"This permanently deletes the project and all its risks, mitigations, and data."}),(0,t.jsxs)("div",{className:"modal-actions",children:[(0,t.jsx)("button",{className:"button secondary small",onClick:()=>j(null),children:"Cancel"}),(0,t.jsx)("button",{className:"button small",style:{background:"var(--danger)",color:"#fff"},onClick:g,disabled:u,children:u?"Deleting...":"Delete Project"})]})]})}),x&&(0,t.jsx)(I,{workspaceId:a,onClose:()=>v(!1),onSaved:()=>{v(!1),d()},toast:o})]})}function F(){let e=(0,n.useRouter)(),s=(0,n.useSearchParams)(),a=c.includes(s.get("tab"))?s.get("tab"):"Overview",[d,o]=(0,l.useState)(null),[u,m]=(0,l.useState)([]),[j,x]=(0,l.useState)(s.get("projectId")||null),[p,v]=(0,l.useState)(null),[g,y]=(0,l.useState)(!0),[b,f]=(0,l.useState)(null),[k,P]=(0,l.useState)(0),[F,L]=(0,l.useState)(!1),[O,z]=(0,l.useState)(!1),[M,H]=(0,l.useState)(null),{toasts:_,add:W}=function(){let[e,s]=(0,l.useState)([]);return{toasts:e,add:(0,l.useCallback)(function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success",t=Date.now()+Math.random();s(s=>[...s,{id:t,message:e,type:a}]),setTimeout(()=>s(e=>e.filter(e=>e.id!==t)),3e3)},[])}}(),G=(0,l.useCallback)(()=>P(e=>e+1),[]),q=(0,l.useCallback)(async a=>{y(!0),f(null);try{var t,l;let n=await i.FH.get("/api/auth/session");if(!(null==n?void 0:n.authenticated)){f("Not authenticated."),y(!1);return}let r=null==(t=n.memberships)?void 0:t[0];if(!r){f("No organization membership found."),y(!1);return}let c=r.organizationId,d=null==(l=(await i.FH.get("/api/workspaces?organizationId=".concat(c))).workspaces)?void 0:l[0];if(!d){f("No workspace found — create one to get started."),y(!1);return}H(d.id);let u=(await i.FH.get("/api/workspaces/".concat(d.id,"/projects"))).projects||[];if(!u.length){f("No project found — create a project to get started."),y(!1);return}m(u);let h=a?u.find(e=>e.id===a):null;if(h||(h=u[0]),h.id!==(s.get("projectId")||null)){let a=s.get("tab")||"Overview";e.replace("/dashboard?tab=".concat(a,"&projectId=").concat(h.id))}o(h);let j=await i.FH.get("/api/projects/".concat(h.id,"/dashboard"));v(j.dashboard),y(!1)}catch(e){f(e.message||"Failed to load dashboard data"),y(!1)}},[]);(0,l.useEffect)(()=>{q(j)},[q,k,j]);let B=s=>{x(s),e.push("/dashboard?tab=".concat(a,"&projectId=").concat(s))},[J,U]=(0,l.useState)(!1);return g&&"Integrations"!==a?(0,t.jsx)("div",{className:"shell-loading",children:(0,t.jsx)("div",{className:"spinner"})}):b&&"Integrations"!==a?(0,t.jsxs)("div",{className:"empty-state",children:[(0,t.jsx)("div",{className:"empty-icon",children:"!"}),(0,t.jsx)("p",{children:b}),(0,t.jsxs)("div",{style:{marginTop:12,display:"flex",gap:8,justifyContent:"center"},children:[(0,t.jsx)("button",{className:"button secondary small",onClick:()=>P(e=>e+1),children:"Retry"}),b.includes("No project found")&&M&&(0,t.jsx)("button",{className:"button small",onClick:()=>U(!0),children:"+ Create Project"})]}),J&&M&&(0,t.jsx)(I,{workspaceId:M,onClose:()=>U(!1),onSaved:()=>{U(!1),P(e=>e+1)},toast:{add:W}})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"dash-header",children:[(0,t.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10},children:(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,t.jsx)("select",{className:"input",value:(null==d?void 0:d.id)||"",onChange:e=>B(e.target.value),style:{fontSize:16,fontWeight:700,width:"auto",minWidth:200,border:"none",background:"transparent",cursor:"pointer"},children:u.map(e=>(0,t.jsxs)("option",{value:e.id,children:[e.name," ","Active"!==e.status?"(".concat(e.status,")"):""]},e.id))}),(0,t.jsx)("button",{className:"button secondary small",style:{fontSize:14,padding:"2px 8px"},onClick:()=>L(!0),title:"Project settings",children:"⚙"}),(0,t.jsx)("button",{className:"button secondary small",onClick:()=>z(!0),children:"Projects"})]}),(0,t.jsx)("p",{className:"muted",style:{margin:0},children:(null==d?void 0:d.subtitle)||(null==d?void 0:d.description)||""})]})}),(0,t.jsxs)("div",{className:"dash-actions",children:[(0,t.jsx)("a",{href:"/api/projects/".concat(null==d?void 0:d.id,"/reports/executive.html"),className:"button secondary small",target:"_blank",children:"Report"}),(0,t.jsx)("a",{href:"/api/projects/".concat(null==d?void 0:d.id,"/reports/risk-register.csv"),className:"button secondary small",target:"_blank",children:"CSV"})]})]}),(0,t.jsx)("div",{className:"tabs",children:c.map(s=>(0,t.jsx)("button",{className:"tab ".concat(a===s?"active":""),onClick:()=>e.push("/dashboard?tab=".concat(s).concat(d?"&projectId=".concat(d.id):"")),children:s},s))}),"Overview"===a&&(0,t.jsx)(r,{name:"Overview",children:(0,t.jsx)(N,{project:d,dashboard:p})},"overview"),"Projects"===a&&(0,t.jsx)(r,{name:"Projects",children:(0,t.jsx)(R,{projects:u,workspaceId:M,currentProjectId:null==d?void 0:d.id,onSwitch:B,onRefresh:G,toast:{add:W}})},"projects"),"Risks"===a&&(0,t.jsx)(r,{name:"Risks",children:(0,t.jsx)(C,{project:d,dashboard:p,toast:{add:W},onRefresh:G})},"risks"),"Mitigations"===a&&(0,t.jsx)(r,{name:"Mitigations",children:(0,t.jsx)(S,{project:d,dashboard:p,toast:{add:W},onRefresh:G})},"mitigations"),"Gate"===a&&(0,t.jsx)(r,{name:"Gate",children:(0,t.jsx)(w,{project:d,dashboard:p,toast:{add:W},onRefresh:G})},"gate"),"Integrations"===a&&(0,t.jsx)(r,{name:"Integrations",children:(0,t.jsx)(D,{project:d,dashboard:p,toast:{add:W},onRefresh:G})},"integrations"),"Audit"===a&&(0,t.jsx)(r,{name:"Audit",children:(0,t.jsx)(T,{project:d,toast:{add:W}})},"audit"),F&&(0,t.jsx)(A,{project:d,onClose:()=>L(!1),onSaved:()=>{L(!1),G()},toast:{add:W}}),O&&(0,t.jsx)(E,{projects:u,workspaceId:M,currentProjectId:null==d?void 0:d.id,onClose:()=>z(!1),onSwitch:B,onSaved:()=>{z(!1),G()},toast:{add:W}}),(0,t.jsx)(h,{toasts:_})]})}},6282:(e,s,a)=>{"use strict";async function t(e,s,a){var t;let l={method:e,headers:{"Content-Type":"application/json"}};a&&(l.body=JSON.stringify(a));let n=await fetch("".concat("").concat(s),l),i=(null==(t=n.headers.get("content-type"))?void 0:t.includes("application/json"))?await n.json():await n.text();if(!n.ok)throw Error((null==i?void 0:i.error)||(null==i?void 0:i.message)||"Request failed (".concat(n.status,")"));return i}a.d(s,{FH:()=>l,Ht:()=>n,ri:()=>i});let l={get:e=>t("GET",e),post:(e,s)=>t("POST",e,s),put:(e,s)=>t("PUT",e,s),patch:(e,s)=>t("PATCH",e,s),del:e=>t("DELETE",e)};async function n(){try{let e=await l.get("/api/auth/session");return e.user||e.actor||null}catch(e){return null}}async function i(){await l.post("/api/auth/logout"),window.location.href="/"}}},e=>{e.O(0,[8441,1255,7358],()=>e(e.s=646)),_N_E=e.O()}]);