@meyicloud/meyi-cost-ui 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,4 +18,4 @@ Cost - ${K(n.amount,e.currency)}`}):"-",helper:l,icon:a.jsx(js,{})}];return a.js
|
|
|
18
18
|
${K(t.amount,"USD")}`).join(`
|
|
19
19
|
`):"—"}function Vn({values:e}){const[t,s]=k.useState(!1);return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{type:"button",onClick:()=>s(r=>!r),className:"inline-flex items-center gap-2 text-primary",children:[a.jsx("span",{className:"rounded-full bg-primary/10 px-2 py-1 text-xs font-semibold",children:e.length}),a.jsx("span",{children:"›"})]}),t&&a.jsxs("div",{className:"absolute right-0 top-8 z-20 w-72 rounded-lg border bg-popover p-3 shadow-xl",children:[a.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[a.jsx("strong",{className:"text-xs",children:"Cost distribution"}),a.jsx("button",{onClick:()=>s(!1),children:a.jsx(Os,{className:"h-3.5 w-3.5"})})]}),e.length?e.map(r=>a.jsxs("div",{className:"flex justify-between gap-3 border-t py-2 text-xs",children:[a.jsx("span",{className:"min-w-0 truncate",title:r.label,children:r.label}),a.jsx("strong",{children:K(r.amount,"USD")})]},r.key)):a.jsx("p",{className:"text-xs text-muted-foreground",children:"No related values."})]})]})}function wa({page:e,pages:t,total:s,onChange:r}){const n=s?(e-1)*qe+1:0,o=Math.min(e*qe,s);return a.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t px-4 py-4 text-xs text-muted-foreground",children:[a.jsxs("span",{children:["Showing ",n,"–",o," of ",s]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{"aria-label":"Previous page",disabled:e<=1,onClick:()=>r(e-1),className:"rounded-md border p-1.5 disabled:opacity-40",children:a.jsx(Md,{className:"h-4 w-4"})}),a.jsxs("span",{children:["Page ",e," of ",t]}),a.jsx("button",{"aria-label":"Next page",disabled:e>=t,onClick:()=>r(e+1),className:"rounded-md border p-1.5 disabled:opacity-40",children:a.jsx(Dd,{className:"h-4 w-4"})})]})]})}function Rf({groupBy:e,report:t}){const[s,r]=k.useState(""),[n,o]=k.useState(1),[i,c]=k.useState(null),[l,d]=k.useState({percentage:!0,accounts:!0,regions:!0}),f=at[e],u=k.useMemo(()=>{const g=s.trim().toLowerCase();return g?t.summary.filter(x=>`${x.label} ${x.accountId||""}`.toLowerCase().includes(g)):t.summary},[t,s]),h=Math.max(1,Math.ceil(u.length/qe)),m=u.slice((n-1)*qe,n*qe),p=3+Number(l.percentage)+Number(l.accounts)+Number(l.regions);return k.useEffect(()=>{o(1)},[t,s,e]),a.jsxs(ce,{children:[a.jsxs(ve,{className:"flex flex-row flex-wrap items-center justify-between gap-3",children:[a.jsx(Ne,{className:"text-sm text-primary",children:"Cost and usage breakdown"}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs("label",{className:"flex items-center gap-2 rounded-full border bg-background px-4 py-2 text-sm",children:[a.jsx(_r,{className:"h-4 w-4 text-muted-foreground"}),a.jsx("input",{"aria-label":"Search breakdown",value:s,onChange:g=>r(g.target.value),placeholder:"Search...",className:"w-48 bg-transparent outline-none"})]}),a.jsxs("details",{className:"relative",children:[a.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-2 rounded-md border px-3 py-2 text-sm text-primary",children:[a.jsx(ra,{className:"h-4 w-4"}),"Column visibility"]}),a.jsx("div",{className:"absolute right-0 z-20 mt-1 w-48 rounded-md border bg-popover p-3 shadow-xl",children:Object.entries(l).map(([g,x])=>a.jsxs("label",{className:"flex gap-2 py-1 text-xs capitalize",children:[a.jsx("input",{type:"checkbox",checked:x,onChange:b=>d(y=>({...y,[g]:b.target.checked}))}),g]},g))})]})]})]}),a.jsx(le,{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b bg-primary/5 text-left text-xs uppercase text-primary",children:[a.jsx("th",{className:"px-4 py-4",children:f.item}),a.jsx("th",{className:"px-4",children:"Cost"}),l.percentage&&a.jsx("th",{className:"px-4",children:"Percentage"}),l.accounts&&a.jsx("th",{className:"px-4",children:"Accounts"}),l.regions&&a.jsx("th",{className:"px-4",children:"Regions"}),a.jsx("th",{className:"px-4 text-center",children:"Actions"})]})}),a.jsx("tbody",{children:m.length?m.map(g=>a.jsxs("tr",{className:"border-b last:border-0",children:[a.jsxs("td",{className:"max-w-72 px-4 py-4 font-medium",children:[a.jsx("div",{className:"truncate",title:g.label,children:g.label}),e==="account"&&a.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:g.accountId||g.key})]}),a.jsx("td",{className:"px-4 font-semibold",children:K(g.amount,t.currency)}),l.percentage&&a.jsxs("td",{className:"px-4",children:[a.jsx("span",{className:"mr-2 inline-block h-1.5 w-12 overflow-hidden rounded-full bg-primary/15 align-middle",children:a.jsx("span",{className:"block h-full bg-primary",style:{width:`${Math.min(g.percentage||0,100)}%`}})}),a.jsxs("strong",{className:"text-primary",children:[g.percentage?.toFixed(2),"%"]})]}),l.accounts&&a.jsx("td",{className:"px-4",children:a.jsx(Vn,{values:g.accounts||[]})}),l.regions&&a.jsx("td",{className:"px-4",children:a.jsx(Vn,{values:g.regions||[]})}),a.jsx("td",{className:"px-4 text-center",children:a.jsx("button",{type:"button",onClick:()=>c(g),title:"View cost details",className:"text-primary hover:opacity-70",children:a.jsx(Gd,{className:"h-4 w-4"})})})]},g.key||g.label)):a.jsx("tr",{children:a.jsx("td",{colSpan:p,className:"py-12 text-center text-muted-foreground",children:f.empty})})})]})}),a.jsx(wa,{page:n,pages:h,total:u.length,onChange:o}),i&&a.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>c(null),children:a.jsxs("div",{className:"max-h-[80vh] w-full max-w-2xl overflow-auto rounded-xl bg-card p-6 shadow-2xl",onClick:g=>g.stopPropagation(),children:[a.jsxs("div",{className:"flex justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-xs uppercase text-muted-foreground",children:f.item}),a.jsx("h3",{className:"mt-1 text-lg font-semibold",children:i.label})]}),a.jsx("button",{onClick:()=>c(null),children:a.jsx(Os,{})})]}),a.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[a.jsx(Le,{label:"Cost",value:K(i.amount,t.currency)}),a.jsx(Le,{label:"Accounts",value:String(i.accounts?.length||0)}),a.jsx(Le,{label:"Regions",value:String(i.regions?.length||0)})]}),a.jsxs("div",{className:"mt-5 grid gap-5 sm:grid-cols-2",children:[a.jsxs("div",{children:[a.jsx("h4",{className:"mb-2 text-sm font-semibold",children:"Accounts"}),(i.accounts||[]).map(g=>a.jsxs("div",{className:"flex justify-between border-t py-2 text-xs",children:[a.jsx("span",{children:g.label}),a.jsx("strong",{children:K(g.amount,t.currency)})]},g.key))]}),a.jsxs("div",{children:[a.jsx("h4",{className:"mb-2 text-sm font-semibold",children:"Regions"}),(i.regions||[]).map(g=>a.jsxs("div",{className:"flex justify-between border-t py-2 text-xs",children:[a.jsx("span",{children:g.label}),a.jsx("strong",{children:K(g.amount,t.currency)})]},g.key))]})]})]})})]})}function jf({rows:e,groupBy:t,comparison:s,granularity:r}){const[n,o]=k.useState(""),[i,c]=k.useState(1),l=k.useMemo(()=>{const m=n.trim().toLowerCase();return m?e.filter(p=>p.label.toLowerCase().includes(m)):e},[e,n]),d=Math.max(1,Math.ceil(l.length/qe)),f=l.slice((i-1)*qe,i*qe),u=Rt(s.currentStart,s.currentEnd,r),h=Rt(s.previousStart,s.previousEnd,r);return k.useEffect(()=>{c(1)},[n,t,s]),a.jsxs(ce,{children:[a.jsxs(ve,{className:"flex flex-row flex-wrap items-center justify-between gap-3",children:[a.jsx(Ne,{className:"text-sm text-primary",children:"Comparison Details"}),a.jsxs("label",{className:"flex items-center gap-2 rounded-full border bg-background px-4 py-2 text-sm",children:[a.jsx(_r,{className:"h-4 w-4 text-muted-foreground"}),a.jsx("input",{"aria-label":"Search comparison",value:n,onChange:m=>o(m.target.value),placeholder:"Search...",className:"w-48 bg-transparent outline-none"})]})]}),a.jsx(le,{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b bg-primary/5 text-left text-xs uppercase text-primary",children:[a.jsxs("th",{className:"px-4 py-4",children:[at[t].item," name"]}),a.jsxs("th",{className:"px-4",children:[u,a.jsx("small",{className:"block font-normal",children:"Cost"})]}),a.jsxs("th",{className:"px-4",children:[h,a.jsx("small",{className:"block font-normal",children:"Cost"})]}),a.jsx("th",{className:"px-4",children:"Difference"}),a.jsx("th",{className:"px-4",children:"Change %"})]})}),a.jsx("tbody",{children:f.length?f.map(m=>a.jsxs("tr",{className:"border-b",children:[a.jsx("td",{className:"max-w-80 px-4 py-4 font-medium",children:a.jsx("div",{className:"truncate",title:m.label,children:m.label})}),a.jsx("td",{className:"px-4",children:K(m.current?.amount||0,s.current.currency)}),a.jsx("td",{className:"px-4",children:K(m.previous?.amount||0,s.previous.currency)}),a.jsxs("td",{className:`px-4 font-medium ${m.difference<0?"text-red-500":"text-emerald-600"}`,children:[m.difference>=0?"+":"",K(m.difference,s.current.currency)]}),a.jsxs("td",{className:`px-4 font-medium ${m.change<0?"text-red-500":m.change>0?"text-emerald-600":"text-muted-foreground"}`,children:[m.change>0?"+":"",m.change.toFixed(1),"%"]})]},m.key)):a.jsx("tr",{children:a.jsx("td",{colSpan:5,className:"py-12 text-center text-muted-foreground",children:"No comparison data found."})})})]})}),a.jsx(wa,{page:i,pages:d,total:l.length,onChange:c})]})}function Nf(e){const{mode:t,groupBy:s,start:r,end:n,granularity:o,reportTagKey:i,options:c,filters:l,loading:d,filtersLoading:f,comparisonPeriods:u}=e;return a.jsxs("aside",{className:"space-y-4",children:[a.jsxs(ce,{className:"bg-primary/5",children:[a.jsx(ve,{children:a.jsx(Ne,{className:"text-sm uppercase text-primary",children:"Report parameters"})}),a.jsxs(le,{className:"space-y-4",children:[a.jsxs("div",{className:"flex gap-2",children:[a.jsx("button",{onClick:()=>e.onModeChange("standard"),className:`rounded-md px-4 py-2 text-xs font-semibold ${t==="standard"?"bg-primary text-primary-foreground":"border text-primary"}`,children:"Standard"}),a.jsx("button",{onClick:()=>e.onModeChange("compare"),className:`rounded-md px-4 py-2 text-xs font-semibold ${t==="compare"?"bg-primary text-primary-foreground":"border text-primary"}`,children:"Compare"})]}),t==="standard"&&a.jsxs(a.Fragment,{children:[a.jsxs("label",{className:"block text-xs text-muted-foreground",children:["Start date",a.jsx("input",{type:"date",value:r,onChange:h=>e.onStartChange(h.target.value),className:"mt-1 w-full rounded-md border bg-background p-2 text-sm text-foreground"})]}),a.jsxs("label",{className:"block text-xs text-muted-foreground",children:["End date",a.jsx("input",{type:"date",value:n,onChange:h=>e.onEndChange(h.target.value),className:"mt-1 w-full rounded-md border bg-background p-2 text-sm text-foreground"})]})]}),a.jsxs("label",{className:"block text-xs text-muted-foreground",children:["Granularity",a.jsxs("select",{value:o,onChange:h=>e.onGranularityChange(h.target.value),className:"mt-1 w-full rounded-md border bg-background p-2 text-sm text-foreground",children:[a.jsx("option",{value:"monthly",children:"Monthly"}),a.jsx("option",{value:"daily",children:"Daily"})]})]}),t==="compare"&&a.jsxs("p",{className:"rounded-md bg-background p-2 text-xs text-muted-foreground",children:["Current: ",u.currentStart," to ",u.currentEnd,a.jsx("br",{}),"Previous: ",u.previousStart," to ",u.previousEnd]}),s==="tag"&&a.jsxs("label",{className:"block text-xs text-muted-foreground",children:["Group by tag key",a.jsx("select",{value:i,onChange:h=>e.onReportTagKeyChange(h.target.value),className:"mt-1 w-full rounded-md border bg-background p-2 text-sm text-foreground",children:c.tagKeys.map(h=>a.jsx("option",{children:h},h))})]}),a.jsxs("button",{onClick:e.onRun,disabled:d,className:"flex w-full items-center justify-center gap-2 rounded-md bg-primary px-3 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:[a.jsx(St,{className:`h-4 w-4 ${d?"animate-spin":""}`}),"Run report"]})]})]}),a.jsxs(ce,{className:"bg-primary/5",children:[a.jsx(ve,{children:a.jsx(Ne,{className:"text-sm uppercase text-primary",children:"Filter by"})}),a.jsxs(le,{className:"space-y-3",children:[a.jsx(ns,{label:"Services",options:c.services,selected:l.services,onChange:h=>e.onFiltersChange(m=>({...m,services:h}))}),a.jsx(ns,{label:"Region",options:c.regions,selected:l.regions,onChange:h=>e.onFiltersChange(m=>({...m,regions:h}))}),a.jsx(ns,{label:"Linked Account",options:c.accounts,selected:l.accountIds,onChange:h=>e.onFiltersChange(m=>({...m,accountIds:h}))}),a.jsxs("select",{value:l.tagKey,onChange:h=>{const m=h.target.value;e.onFiltersChange(p=>({...p,tagKey:m,tagValues:[]})),m&&e.onLoadTagValues(m)},className:"w-full rounded-lg border bg-background px-3 py-3 text-sm text-primary",children:[a.jsx("option",{value:"",children:"Tag key"}),c.tagKeys.map(h=>a.jsx("option",{children:h},h))]}),l.tagKey&&a.jsx(ns,{label:"Tag values",options:c.tagValues.map(h=>({value:h,label:h})),selected:l.tagValues,onChange:h=>e.onFiltersChange(m=>({...m,tagValues:h}))}),a.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-2",children:[a.jsx("button",{onClick:e.onApply,disabled:f||d,className:"rounded-md bg-primary px-3 py-2 text-sm font-semibold text-primary-foreground disabled:opacity-50",children:"Apply Filters"}),a.jsx("button",{onClick:e.onReset,disabled:d,className:"rounded-md border bg-background px-3 py-2 text-sm text-primary disabled:opacity-50",children:"Reset"})]})]})]})]})}function Cf(){const[e,t]=k.useState("service"),[s,r]=k.useState("standard"),[n,o]=k.useState(vf),[i,c]=k.useState(wf),[l,d]=k.useState("monthly"),[f,u]=k.useState("Name"),[h,m]=k.useState({services:[],regions:[],accounts:[],tagKeys:[],tagValues:[]}),[p,g]=k.useState(Mt),[x,b]=k.useState(Mt),[y,S]=k.useState(null),[w,N]=k.useState(null),[j,_]=k.useState(!0),[R,E]=k.useState(!1),[D,L]=k.useState(null),[F,ee]=k.useState(null),V=k.useRef(0),Z=k.useMemo(()=>w?Sf(w):[],[w]),Q=zn(i,l),Y=(M,I,$,J)=>({start:I,end:$,groupBy:J,granularity:l,tagKey:f,services:M.services.join(","),regions:M.regions.join(","),accountIds:M.accountIds.join(","),filterTagKey:M.tagKey||void 0,tagValues:M.tagValues.join(",")}),de=async(M="")=>{E(!0);try{const I=F||await ie.getDataStatus();if(ee(I),!I.ready)return;const $=await ie.getFilterOptions({start:n,end:i,filterTagKey:M||void 0});m(J=>M?{...J,tagValues:$.tagValues}:$),!M&&$.tagKeys.length&&!$.tagKeys.includes(f)&&u($.tagKeys[0])}catch(I){L(I?.response?.data?.error||I.message||"Failed to load filter values")}finally{E(!1)}},fe=async(M=x,I=s,$=e)=>{const J=++V.current;_(!0),L(null),S(null),N(null);try{const G=await ie.getDataStatus();if(J===V.current&&ee(G),!G.ready)return;if(I==="compare"){const ue=zn(i,l),[be,ne]=await Promise.all([ie.getReports(Y(M,ue.currentStart,ue.currentEnd,$)),ie.getReports(Y(M,ue.previousStart,ue.previousEnd,$))]);J===V.current&&(S(be),N({current:be,previous:ne,...ue}))}else{const ue=await ie.getReports(Y(M,n,i,$));J===V.current&&S(ue)}}catch(G){J===V.current&&L(G?.response?.data?.error||G.message||"Failed to generate cost report")}finally{J===V.current&&_(!1)}};return k.useEffect(()=>{fe(x,s,e)},[e,s]),k.useEffect(()=>{de()},[]),{groupBy:e,mode:s,start:n,end:i,granularity:l,reportTagKey:f,options:h,draftFilters:p,report:y,comparison:w,loading:j,filtersLoading:R,error:D,dataStatus:F,comparedRows:Z,selectedComparisonPeriods:Q,setStart:o,setEnd:c,setGranularity:d,setReportTagKey:u,setDraftFilters:g,changeGroup:M=>{M!==e&&(_(!0),S(null),N(null),t(M))},changeMode:M=>{M!==s&&(_(!0),S(null),N(null),r(M))},applyFilters:()=>{const M={...p,services:[...p.services],regions:[...p.regions],accountIds:[...p.accountIds],tagValues:[...p.tagValues]};b(M),fe(M)},resetFilters:()=>{g(Mt),b(Mt),fe(Mt)},runReport:()=>{de(),fe()},loadOptions:de}}function _f(e){const{report:t,comparison:s,rows:r,groupBy:n,mode:o,start:i,end:c}=e,l=at[n];let d,f;o==="compare"&&s?(d=[[l.item,"Current Cost","Previous Cost","Difference","Change %"].join(","),...r.map(h=>[`"${h.label.replace(/"/g,'""')}"`,h.current?.amount||0,h.previous?.amount||0,h.difference,h.change.toFixed(2)].join(","))].join(`
|
|
20
20
|
`),f=`comparison-report-${n}-${Date.now()}.csv`):(d=[[l.item,"Cost","Percentage","Accounts","Regions"].join(","),...t.summary.map(h=>[`"${h.label.replace(/"/g,'""')}"`,h.amount,h.percentage||0,h.accounts?.length||0,h.regions?.length||0].join(","))].join(`
|
|
21
|
-
`),f=`${n}-summary-report-${Date.now()}.csv`);const u=document.createElement("a");u.href=URL.createObjectURL(new Blob([d],{type:"text/csv"})),u.download=f,u.click(),URL.revokeObjectURL(u.href)}async function kf(e){const{report:t,comparison:s,rows:r,groupBy:n,mode:o,start:i,end:c,granularity:l}=e,d=at[n],[{jsPDF:f},{default:u}]=await Promise.all([Promise.resolve().then(()=>require("./jspdf.es.min-C10id8ME.cjs")).then(g=>g.jspdf_es_min),Promise.resolve().then(()=>require("./jspdf.plugin.autotable-CvTok6mL.cjs"))]),h=new f({orientation:"landscape",unit:"pt",format:"a4"}),m=(g,x,b)=>{h.setFontSize(7),h.setTextColor(100),h.text(`Report generated · All costs in ${t.currency} · ${x} to ${b}`,40,h.internal.pageSize.height-18),h.text(`Page ${g.pageNumber}`,h.internal.pageSize.width-70,h.internal.pageSize.height-18)};if(o==="compare"&&s){h.setFontSize(18),h.setTextColor(25),h.text("Comparison Report",40,42),h.setFontSize(9),h.setTextColor(98,86,230),h.text("TOTAL COST",40,66),h.setTextColor(40),h.text(`Previous Cost: ${s.previous.totalCost}`,40,82),h.text(`Current Cost: ${s.current.totalCost}`,220,82),h.text(`Granularity: ${l}`,400,82),u(h,{startY:100,head:[[`${d.item} Name`,"Current Cost","Previous Cost","Current Period","Previous Period","Change %","Current Accounts","Previous Accounts","Current Regions","Previous Regions"]],body:r.map(g=>[g.label,g.current?.amount?.toFixed(2)||"0.00",g.previous?.amount?.toFixed(2)||"0.00",Rt(s.currentStart,s.currentEnd,l),Rt(s.previousStart,s.previousEnd,l),`${g.change.toFixed(4)}%`,Xe(g.current?.accounts),Xe(g.previous?.accounts),Xe(g.current?.regions),Xe(g.previous?.regions)]),styles:{fontSize:6,cellPadding:3,overflow:"linebreak"},headStyles:{fillColor:[242,237,255],textColor:[82,35,190]},didDrawPage:g=>m(g,s.previousStart,s.currentEnd),margin:{bottom:32}}),h.save(`comparison-report-${n}-${Date.now()}.pdf`);return}h.setFontSize(18),h.setTextColor(25),h.text(d.pdfTitle,40,42),h.setFontSize(9),h.setTextColor(98,86,230),h.text("REPORT METADATA",40,66),h.setTextColor(40),h.text(`Tenant ID: ${t.tenantId||"Current tenant"}`,40,82),h.text(`Date Range: ${i} to ${c}`,40,97),h.text(`Accrued Total Cost: ${K(t.totalCost,t.currency)}`,40,112),h.setTextColor(98,86,230),h.text("COST SUMMARY BREAKDOWN",40,136);const p=n==="account";u(h,{startY:146,head:[p?["Account ID","Account Name","Total Cost","Percentage","Regions"]:[`${d.item} Name`,"Total Cost","Percentage","Accounts","Regions"]],body:t.summary.map(g=>p?[g.accountId||g.key||"—",g.label,K(g.amount,t.currency),`${(g.percentage||0).toFixed(2)}%`,Xe(g.regions)]:[g.label,K(g.amount,t.currency),`${(g.percentage||0).toFixed(2)}%`,Xe(g.accounts),Xe(g.regions)]),styles:{fontSize:7,cellPadding:4,overflow:"linebreak"},headStyles:{fillColor:[242,237,255],textColor:[82,35,190]},didDrawPage:g=>m(g,i,c),margin:{bottom:32}}),h.save(`${n}-summary-report-${Date.now()}.pdf`)}function Ef(){const e=Cf(),{groupBy:t,mode:s,report:r,comparison:n,comparedRows:o,loading:i,error:c,dataStatus:l,granularity:d,start:f,end:u}=e,h=at[t],m=r?.summary[0],p=n?n.current.totalCost-n.previous.totalCost:0,g=n?.previous.totalCost?p/Math.abs(n.previous.totalCost)*100:0,x=r?{report:r,comparison:n,rows:o,groupBy:t,mode:s,start:f,end:u,granularity:d}:null,b=a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{onClick:()=>x&&void kf(x),disabled:!x||i,className:"flex items-center gap-2 rounded-md border bg-card px-3 py-1.5 text-sm disabled:opacity-50",children:[a.jsx(Yd,{className:"h-4 w-4"}),"PDF"]}),a.jsxs("button",{onClick:()=>x&&_f(x),disabled:!x||i,className:"flex items-center gap-2 rounded-md border bg-card px-3 py-1.5 text-sm disabled:opacity-50",children:[a.jsx(Cr,{className:"h-4 w-4"}),"CSV"]})]});return a.jsxs("div",{className:"flex w-full flex-col gap-5 p-2 md:p-6",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(ta,{className:"h-6 w-6 text-primary"}),"Cost reports"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Analyse live AWS cost by service, linked account, region, resource, or cost allocation tag"})]}),!i&&(l&&!l.ready||c&&!l)?a.jsx(Cs,{status:l,error:c}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex gap-1 overflow-x-auto border-b",children:Object.keys(at).map(y=>a.jsx("button",{onClick:()=>e.changeGroup(y),className:`border-b-2 px-4 py-3 text-sm font-medium ${t===y?"border-primary text-primary":"border-transparent text-muted-foreground"}`,children:at[y].tab},y))}),a.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1fr)_320px]",children:[a.jsxs("div",{className:"space-y-5",children:[c&&a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"h-4 w-4"}),c]}),i?a.jsx(yf,{}):s==="compare"&&n?a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"rounded-xl bg-primary/5 p-4",children:[a.jsxs("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-4",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"text-sm font-semibold",children:"Comparison Cost Summary"}),a.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Updated On: ",Bn(n.current.updatedAt)]})]}),b]}),a.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[a.jsx(Le,{label:"Period accrued total",value:`${K(n.current.totalCost,n.current.currency)} vs ${K(n.previous.totalCost,n.previous.currency)}`,helper:`${g>=0?"+":""}${g.toFixed(1)}% from previous period`,trend:g}),a.jsx(Le,{label:Rt(n.currentStart,n.currentEnd,d),value:K(n.current.totalCost,n.current.currency),helper:"Current period spending"}),a.jsx(Le,{label:Rt(n.previousStart,n.previousEnd,d),value:K(n.previous.totalCost,n.previous.currency),helper:"Previous period spending"}),a.jsx(Le,{label:d==="monthly"?"Monthly change":"Period change",value:`${p>=0?"+":""}${K(p,n.current.currency)}`,helper:`${g>=0?"+":""}${g.toFixed(1)}% from previous period`,trend:p})]})]}),a.jsx(bf,{rows:o,currency:n.current.currency}),a.jsx(jf,{rows:o,groupBy:t,comparison:n,granularity:d})]}):r?a.jsxs(a.Fragment,{children:[r.message&&a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border bg-muted/50 p-3 text-sm text-muted-foreground",children:[a.jsx(lt,{className:"h-4 w-4"}),r.message]}),a.jsxs("section",{className:"rounded-xl bg-primary/5 p-4",children:[a.jsxs("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-4",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"text-sm font-semibold",children:h.title}),a.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Updated On: ",Bn(r.updatedAt)]})]}),b]}),a.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[a.jsx(Le,{label:"Accrued cost",value:K(r.totalCost,r.currency)}),a.jsx(Le,{label:h.top,value:m?K(m.amount,r.currency):"-",accent:!0}),a.jsx(Le,{label:h.count,value:String(r.count||0),accent:!0})]})]}),a.jsxs(ce,{children:[a.jsx(ve,{children:a.jsx(Ne,{className:"text-sm",children:"Cost Trend"})}),a.jsx(le,{children:a.jsx(xf,{timeline:r.timeline||[],currency:r.currency||"USD",daily:d==="daily"})})]}),a.jsx(Rf,{groupBy:t,report:r})]}):null]}),a.jsx(Nf,{mode:s,groupBy:t,start:f,end:u,granularity:d,reportTagKey:e.reportTagKey,options:e.options,filters:e.draftFilters,loading:i,filtersLoading:e.filtersLoading,comparisonPeriods:e.selectedComparisonPeriods,onModeChange:e.changeMode,onStartChange:e.setStart,onEndChange:e.setEnd,onGranularityChange:e.setGranularity,onReportTagKeyChange:e.setReportTagKey,onFiltersChange:e.setDraftFilters,onLoadTagValues:y=>{e.loadOptions(y)},onRun:e.runReport,onApply:e.applyFilters,onReset:e.resetFilters})]})]})]})}const Wn={READY:"bg-emerald-500/10 text-emerald-600 border-emerald-500/30",RUNNING:"bg-blue-500/10 text-blue-600 border-blue-500/30",WAITING_FOR_DATA:"bg-amber-500/10 text-amber-600 border-amber-500/30",WAITING_FOR_TABLE:"bg-amber-500/10 text-amber-600 border-amber-500/30",FAILED:"bg-destructive/10 text-destructive border-destructive/30",PENDING:"bg-muted text-muted-foreground border-border"},Pf={INFO:"text-muted-foreground",WARN:"text-amber-600",ERROR:"text-destructive"},os=e=>e?new Date(e).toLocaleString():"—";function Tf({status:e}){return a.jsx("span",{className:`rounded-full border px-2 py-0.5 text-xs font-medium ${Wn[e]||Wn.PENDING}`,children:e.replace(/_/g," ")})}function De({label:e,value:t,mono:s}){return a.jsxs("div",{className:"flex flex-col gap-0.5",children:[a.jsx("span",{className:"text-xs text-muted-foreground",children:e}),a.jsx("span",{className:`break-all text-sm ${s?"font-mono text-xs":""}`,children:t||"—"})]})}function Af(){const[e,t]=k.useState([]),[s,r]=k.useState([]),[n,o]=k.useState(!0),[i,c]=k.useState(null),l=k.useCallback(async()=>{o(!0),c(null);try{const d=await re.get("/cur-discovery",{params:{logLimit:100}});t(d.data?.jobs||[]),r(d.data?.logs||[])}catch(d){c(d?.response?.data?.error||d?.message||"Unable to load CUR discovery status")}finally{o(!1)}},[]);return k.useEffect(()=>{l()},[l]),a.jsxs("div",{className:"flex w-full flex-col gap-6 p-2 md:p-6",children:[a.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(_r,{className:"h-6 w-6 text-primary"}),"CUR Discovery"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Progress of the scheduled job that locates this tenant’s Cost and Usage Report table. Cost data becomes available after it reports Ready."})]}),a.jsx("button",{onClick:()=>{l()},disabled:n,className:"rounded-lg border p-2 hover:bg-muted disabled:opacity-50","aria-label":"Refresh",children:a.jsx(St,{className:`h-4 w-4 ${n?"animate-spin":""}`})})]}),i&&a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"h-4 w-4"}),i]}),!n&&!i&&!e.length&&a.jsx(ce,{children:a.jsx(le,{className:"py-10 text-center text-sm text-muted-foreground",children:"No discovery job exists for this tenant yet. One is created automatically once the AWS connection is verified and the Cost plugin is entitled."})}),e.map(d=>a.jsxs(ce,{children:[a.jsxs(ve,{className:"flex flex-row flex-wrap items-center gap-3",children:[a.jsx(Zo,{className:"h-4 w-4 text-primary"}),a.jsxs(Ne,{className:"text-sm",children:["Connection ",d.connectionId]}),a.jsx(Tf,{status:d.status}),a.jsxs("span",{className:"text-xs text-muted-foreground",children:["attempt ",d.attemptCount]}),a.jsxs("span",{className:"ms-auto text-xs text-muted-foreground",children:["next check ",os(d.nextRunAt)]})]}),a.jsxs(le,{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:[a.jsx(De,{label:"Source",value:d.curS3Uri||`s3://${d.bucket}/${d.prefix}`,mono:!0}),a.jsx(De,{label:"Tenant partition",value:d.tenantPartition,mono:!0}),a.jsx(De,{label:"Region",value:d.region}),a.jsx(De,{label:"Glue database",value:d.database,mono:!0}),a.jsx(De,{label:"Discovered table",value:d.table,mono:!0}),a.jsx(De,{label:"Table location",value:d.tableLocation,mono:!0}),a.jsx(De,{label:"Sample object",value:d.sampleObjectKey,mono:!0}),a.jsx(De,{label:"Last data",value:os(d.lastDataAt)}),a.jsx(De,{label:"Last checked",value:os(d.lastFinishedAt||d.lastStartedAt)}),d.lastError&&a.jsx("div",{className:"md:col-span-2 lg:col-span-3 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:d.lastError})]})]},d.id)),e.length>0&&a.jsxs(ce,{children:[a.jsx(ve,{children:a.jsx(Ne,{className:"text-sm",children:"Recent activity"})}),a.jsx(le,{children:s.length?a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b text-left text-xs uppercase text-muted-foreground",children:[a.jsx("th",{className:"py-2 pe-4 font-medium",children:"Time"}),a.jsx("th",{className:"py-2 pe-4 font-medium",children:"Level"}),a.jsx("th",{className:"py-2 pe-4 font-medium",children:"Event"}),a.jsx("th",{className:"py-2 font-medium",children:"Message"})]})}),a.jsx("tbody",{children:s.map(d=>a.jsxs("tr",{className:"border-b last:border-0 align-top",children:[a.jsx("td",{className:"whitespace-nowrap py-2 pe-4 text-xs text-muted-foreground",children:os(d.createdAt)}),a.jsx("td",{className:`py-2 pe-4 text-xs font-medium ${Pf[d.level]||""}`,children:d.level}),a.jsx("td",{className:"whitespace-nowrap py-2 pe-4 font-mono text-xs",children:d.event}),a.jsx("td",{className:"py-2",children:d.message})]},d.id))})]})}):a.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No log entries recorded yet."})})]})]})}const Of="https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/template",Lf=e=>e==="CONNECTED"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-600":e==="FAILED"?"border-destructive/30 bg-destructive/10 text-destructive":"border-amber-500/30 bg-amber-500/10 text-amber-700",as=e=>e?.response?.data?.error||e?.response?.data?.message||e?.message||"Request failed";function Mf(){const[e,t]=k.useState([]),[s,r]=k.useState(!0),[n,o]=k.useState(!1),[i,c]=k.useState(""),[l,d]=k.useState(!1),[f,u]=k.useState(null),[h,m]=k.useState(null),[p,g]=k.useState(null),x=k.useCallback(async()=>{r(!0),g(null);try{t((await ie.getSources()).sources||[])}catch(w){g(as(w))}finally{r(!1)}},[]);k.useEffect(()=>{x()},[x]);const b=async w=>{if(w.preventDefault(),!/^\d{12}$/.test(i)){g("AWS account ID must contain exactly 12 digits");return}m("create"),g(null);try{const N=await ie.createSource({managementAccountId:i,regionMode:l?"ALL":"SINGLE"});u(N.connectionId),o(!1),c(""),d(!1),await x()}catch(N){g(as(N))}finally{m(null)}},y=async w=>{m(`download-${w}`),g(null);try{const N=await ie.downloadSourceTemplate(w),j=URL.createObjectURL(N),_=document.createElement("a");_.href=j,_.download=`meyi-connect-cost-${w}.yaml`,_.click(),URL.revokeObjectURL(j),u(w)}catch(N){g(as(N))}finally{m(null)}},S=async w=>{m(`verify-${w}`),g(null);try{const N=await ie.verifySource(w);N.status==="FAILED"&&g(N.message||"AWS connection verification failed"),await x()}catch(N){g(as(N))}finally{m(null)}};return a.jsxs("div",{className:"flex w-full flex-col gap-6 p-2 md:p-6",children:[a.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(js,{className:"h-6 w-6 text-primary"}),"Cost Sources"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"AWS accounts connected to this tenant for Cost and Usage Report data."})]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx("button",{type:"button",onClick:()=>{x()},disabled:s,className:"rounded-md border p-2 hover:bg-muted disabled:opacity-50","aria-label":"Refresh sources",title:"Refresh sources",children:a.jsx(St,{className:`h-4 w-4 ${s?"animate-spin":""}`})}),a.jsxs("button",{type:"button",onClick:()=>{g(null),o(!0)},className:"flex items-center gap-2 rounded-md bg-primary px-3 py-2 text-sm font-medium text-primary-foreground hover:opacity-90",children:[a.jsx(ru,{className:"h-4 w-4"}),"Add AWS account"]})]})]}),p&&a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"mt-0.5 h-4 w-4 shrink-0"}),p]}),!s&&e.length===0&&a.jsxs("div",{className:"rounded-md border border-dashed py-14 text-center",children:[a.jsx(js,{className:"mx-auto mb-3 h-8 w-8 text-muted-foreground"}),a.jsx("p",{className:"font-medium",children:"No AWS Cost source"}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Add an AWS account to begin collecting tenant cost data."})]}),e.length>0&&a.jsx("div",{className:"overflow-x-auto rounded-md border",children:a.jsxs("table",{className:"w-full min-w-[780px] text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b bg-muted/50 text-left text-xs uppercase text-muted-foreground",children:[a.jsx("th",{className:"px-4 py-3 font-medium",children:"AWS account"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Connection"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Scope"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Status"}),a.jsx("th",{className:"px-4 py-3 text-right font-medium",children:"Actions"})]})}),a.jsx("tbody",{children:e.map(w=>a.jsxs("tr",{className:`border-b last:border-0 ${f===w.connectionId?"bg-muted/30":""}`,children:[a.jsx("td",{className:"px-4 py-3 font-mono",children:w.managementAccountId||"Pending"}),a.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:w.connectionId}),a.jsxs("td",{className:"px-4 py-3",children:[w.accountScope," / ",w.regionMode]}),a.jsxs("td",{className:"px-4 py-3",children:[a.jsx("span",{className:`rounded-full border px-2 py-1 text-xs font-medium ${Lf(w.status)}`,children:w.status.replace(/_/g," ")}),w.stackSetStatus&&a.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:w.stackSetStatus.replace(/_/g," ")})]}),a.jsx("td",{className:"px-4 py-3",children:a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsx("button",{type:"button",onClick:()=>{y(w.connectionId)},disabled:!!h,className:"rounded-md border p-2 hover:bg-muted disabled:opacity-50",title:"Download CloudFormation template","aria-label":"Download CloudFormation template",children:h===`download-${w.connectionId}`?a.jsx(bt,{className:"h-4 w-4 animate-spin"}):a.jsx(Cr,{className:"h-4 w-4"})}),a.jsx("a",{href:Of,target:"_blank",rel:"noreferrer",className:"rounded-md border p-2 hover:bg-muted",title:"Open AWS CloudFormation","aria-label":"Open AWS CloudFormation",children:a.jsx(ea,{className:"h-4 w-4"})}),a.jsxs("button",{type:"button",onClick:()=>{S(w.connectionId)},disabled:!!h||w.status==="CONNECTED",className:"flex items-center gap-2 rounded-md border px-3 py-2 font-medium hover:bg-muted disabled:opacity-50",children:[h===`verify-${w.connectionId}`?a.jsx(bt,{className:"h-4 w-4 animate-spin"}):w.status==="CONNECTED"?a.jsx($d,{className:"h-4 w-4 text-emerald-600"}):a.jsx(St,{className:"h-4 w-4"}),w.status==="CONNECTED"?"Connected":"Verify"]})]})})]},w.connectionId))})]})}),n&&a.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",role:"dialog","aria-modal":"true","aria-labelledby":"add-source-title",children:a.jsxs("form",{onSubmit:w=>{b(w)},className:"w-full max-w-md rounded-md border bg-background p-5 shadow-xl",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsx("h2",{id:"add-source-title",className:"text-lg font-semibold",children:"Add AWS account"}),a.jsx("button",{type:"button",onClick:()=>o(!1),className:"rounded-md p-1 hover:bg-muted","aria-label":"Close",children:a.jsx(Os,{className:"h-4 w-4"})})]}),a.jsx("label",{className:"mt-5 block text-sm font-medium",htmlFor:"aws-account-id",children:"AWS account ID"}),a.jsx("input",{id:"aws-account-id",value:i,onChange:w=>c(w.target.value.replace(/\D/g,"").slice(0,12)),inputMode:"numeric",autoComplete:"off",placeholder:"123456789012",className:"mt-2 h-10 w-full rounded-md border bg-background px-3 font-mono outline-none focus:ring-2 focus:ring-ring"}),a.jsxs("label",{className:"mt-4 flex items-start gap-3 rounded-md border p-3",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:w=>d(w.target.checked),className:"mt-1 h-4 w-4"}),a.jsxs("span",{children:[a.jsx("span",{className:"block text-sm font-medium",children:"All enabled AWS regions"}),a.jsx("span",{className:"block text-xs text-muted-foreground",children:"Use organization-wide StackSet deployment across enabled regions."})]})]}),a.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[a.jsx("button",{type:"button",onClick:()=>o(!1),className:"rounded-md border px-4 py-2 text-sm font-medium hover:bg-muted",children:"Cancel"}),a.jsxs("button",{type:"submit",disabled:h==="create"||i.length!==12,className:"flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:[h==="create"&&a.jsx(bt,{className:"h-4 w-4 animate-spin"}),"Create source"]})]})]})})]})}const Sa=k.createContext("user"),If=Sa.Provider,Df=()=>k.useContext(Sa),Ff=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Uf=["UTC","Asia/Kolkata","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Singapore","Asia/Tokyo","Australia/Sydney"];function $f({open:e,schedule:t,saving:s,onClose:r,onSave:n}){const[o,i]=k.useState(t);if(k.useEffect(()=>i(t),[t,e]),!e)return null;const c=l=>i(d=>({...d,frequency:l}));return a.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&r()},children:a.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"cost-ai-schedule-title",className:"w-full max-w-lg overflow-hidden rounded-lg border bg-background shadow-xl",children:[a.jsxs("div",{className:"flex items-start justify-between border-b px-5 py-4",children:[a.jsxs("div",{children:[a.jsxs("h2",{id:"cost-ai-schedule-title",className:"flex items-center gap-2 text-base font-semibold",children:[a.jsx(Xo,{className:"h-4 w-4 text-primary"}),"AI report schedule"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Reports run automatically against completed AWS CUR periods."})]}),a.jsx("button",{type:"button",onClick:r,className:"rounded-md p-1.5 hover:bg-muted","aria-label":"Close",children:a.jsx(Os,{className:"h-4 w-4"})})]}),a.jsxs("form",{className:"space-y-5 p-5",onSubmit:l=>{l.preventDefault(),n({enabled:o.enabled,frequency:o.frequency,time:o.time,timezone:o.timezone,dayOfWeek:o.dayOfWeek,dayOfMonth:o.dayOfMonth}).then(r)},children:[a.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-lg border p-3",children:[a.jsxs("span",{children:[a.jsx("span",{className:"block text-sm font-medium",children:"Scheduled reports"}),a.jsx("span",{className:"block text-xs text-muted-foreground",children:"Generate reports without a manual action"})]}),a.jsx("input",{type:"checkbox",checked:o.enabled,onChange:l=>i(d=>({...d,enabled:l.target.checked})),className:"h-4 w-4 accent-primary"})]}),a.jsxs("fieldset",{disabled:!o.enabled||s,className:"space-y-5 disabled:opacity-60",children:[a.jsxs("div",{children:[a.jsx("span",{className:"mb-2 block text-sm font-medium",children:"Frequency"}),a.jsx("div",{className:"grid grid-cols-3 rounded-lg border p-1",children:["daily","weekly","monthly"].map(l=>a.jsx("button",{type:"button",onClick:()=>c(l),className:`rounded-md px-3 py-2 text-sm capitalize ${o.frequency===l?"bg-primary text-primary-foreground":"hover:bg-muted"}`,children:l},l))})]}),a.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[a.jsxs("label",{className:"text-sm font-medium",children:["Run time",a.jsx("input",{type:"time",required:!0,value:o.time,onChange:l=>i(d=>({...d,time:l.target.value})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal"})]}),a.jsxs("label",{className:"text-sm font-medium",children:["Timezone",a.jsx("select",{value:o.timezone,onChange:l=>i(d=>({...d,timezone:l.target.value})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal",children:[...new Set([o.timezone,...Uf])].map(l=>a.jsx("option",{children:l},l))})]})]}),o.frequency==="weekly"&&a.jsxs("label",{className:"block text-sm font-medium",children:["Day of week",a.jsx("select",{value:o.dayOfWeek??1,onChange:l=>i(d=>({...d,dayOfWeek:Number(l.target.value)})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal",children:Ff.map((l,d)=>a.jsx("option",{value:d,children:l},l))})]}),o.frequency==="monthly"&&a.jsxs("label",{className:"block text-sm font-medium",children:["Day of month",a.jsx("input",{type:"number",min:1,max:28,value:o.dayOfMonth??1,onChange:l=>i(d=>({...d,dayOfMonth:Number(l.target.value)})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal"})]}),a.jsx("p",{className:"text-xs text-muted-foreground",children:"Daily reports cover the previous day, weekly reports the previous seven complete days, and monthly reports the previous calendar month."})]}),a.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[a.jsx("button",{type:"button",onClick:r,className:"rounded-lg border px-4 py-2 text-sm font-medium hover:bg-muted",children:"Cancel"}),a.jsx("button",{type:"submit",disabled:s,className:"rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:s?"Saving":"Save schedule"})]})]})]})})}function Bf(){const[e,t]=k.useState(null),[s,r]=k.useState(null),[n,o]=k.useState(null),[i,c]=k.useState([]),[l,d]=k.useState(!0),[f,u]=k.useState(!1),[h,m]=k.useState(null),[p,g]=k.useState(null),x=k.useRef(!0),b=k.useCallback(async(N=!1)=>{N||d(!0);try{const[j,_,R,E]=await Promise.all([ie.getAnalysisStatus(),ie.getDataStatus(),ie.getAnalysisSchedule(),ie.getAnalysisReports()]);if(!x.current)return;t(j),r(_),o(R),c(E),g(null)}catch(j){x.current&&g(j?.response?.data?.error||j?.message||"Unable to load scheduled AI reports")}finally{x.current&&!N&&d(!1)}},[]);return k.useEffect(()=>(x.current=!0,b(),()=>{x.current=!1}),[b]),k.useEffect(()=>{if(!i.some(j=>j.status==="PENDING"||j.status==="RUNNING"))return;const N=window.setInterval(()=>{b(!0)},15e3);return()=>window.clearInterval(N)},[b,i]),{status:e,dataStatus:s,schedule:n,reports:i,loading:l,saving:f,removingId:h,error:p,load:b,saveSchedule:async N=>{u(!0),g(null);try{const j=await ie.updateAnalysisSchedule(N);x.current&&o(j)}catch(j){throw g(j?.response?.data?.error||j?.message||"Unable to save the AI report schedule"),j}finally{x.current&&u(!1)}},download:async N=>{try{const j=await ie.downloadAnalysisPdf(N.id),_=URL.createObjectURL(j),R=document.createElement("a");R.href=_,R.download=`meyi-cost-analysis-${N.period.Start}.pdf`,R.click(),URL.revokeObjectURL(_)}catch(j){g(j?.response?.data?.error||j?.message||"Unable to download the PDF report")}},remove:async N=>{if(window.confirm(`Remove the AI cost report for ${N.period.Start} through ${N.period.End}?`)){m(N.id),g(null);try{await ie.removeAnalysisReport(N.id),x.current&&c(j=>j.filter(_=>_.id!==N.id))}catch(j){x.current&&g(j?.response?.data?.error||j?.message||"Unable to remove the AI report")}finally{x.current&&m(null)}}}}}const er=e=>e?new Date(e).toLocaleString():"Not scheduled",zf=e=>new Date(`${e}T00:00:00Z`).toLocaleDateString(),Vf=e=>{const t=new Date(`${e}T00:00:00Z`);return t.setUTCDate(t.getUTCDate()-1),t.toLocaleDateString()},Wf={COMPLETED:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",RUNNING:"border-blue-500/30 bg-blue-500/10 text-blue-700",PENDING:"border-amber-500/30 bg-amber-500/10 text-amber-700",FAILED:"border-destructive/30 bg-destructive/10 text-destructive"};function Hf(){const e=Bf(),t=Df(),[s,r]=k.useState(!1),n=t.toLowerCase()==="admin";return a.jsxs("div",{className:"flex min-w-0 max-w-full flex-col gap-6 overflow-x-hidden p-2 md:p-6",children:[a.jsxs("header",{className:"flex flex-wrap items-start justify-between gap-4",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(An,{className:"h-6 w-6 text-primary"}),"AI Cost Analysis"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Scheduled Cost reports generated from AWS CUR data"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{type:"button",onClick:()=>{e.load()},disabled:e.loading,className:"rounded-lg border p-2.5 hover:bg-muted disabled:opacity-50",title:"Refresh reports","aria-label":"Refresh reports",children:a.jsx(St,{className:`h-4 w-4 ${e.loading?"animate-spin":""}`})}),n&&e.schedule&&a.jsxs("button",{type:"button",onClick:()=>r(!0),className:"inline-flex h-10 items-center gap-2 rounded-lg bg-primary px-4 text-sm font-medium text-primary-foreground",children:[a.jsx(ra,{className:"h-4 w-4"}),"Report settings"]})]})]}),e.error&&a.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.error]}),e.loading?a.jsx("div",{className:"h-72 animate-pulse rounded-lg bg-muted"}):e.dataStatus&&!e.dataStatus.ready?a.jsx(Cs,{status:e.dataStatus}):e.status&&!e.status.enabled?a.jsx(ce,{children:a.jsxs(le,{className:"flex min-h-64 flex-col items-center justify-center px-6 text-center",children:[a.jsx(An,{className:"h-8 w-8 text-muted-foreground"}),a.jsx("h2",{className:"mt-4 text-base font-semibold",children:e.status.reason==="AI_PROVIDER_REQUIRED"?"Configure an AI provider":"AI cost analysis is not enabled"}),a.jsx("p",{className:"mt-2 max-w-xl text-sm text-muted-foreground",children:e.status.reason==="AI_PROVIDER_REQUIRED"?"Configure and activate an AI provider in Meyi Connect before scheduled cost reports can run.":"An administrator must enable the Cost AI deployment setting before scheduled reports can run."})]})}):a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-card px-4 py-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Xo,{className:"h-5 w-5 text-primary"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm font-semibold",children:e.schedule?.enabled?`${e.schedule.frequency[0].toUpperCase()}${e.schedule.frequency.slice(1)} reports enabled`:"Scheduled reports disabled"}),a.jsx("p",{className:"text-xs text-muted-foreground",children:e.schedule?.enabled?`Next run ${er(e.schedule.nextRunAt)} (${e.schedule.timezone})`:n?"Open report settings to configure a schedule":"An administrator can configure the report schedule"})]})]}),e.schedule?.lastRunAt&&a.jsxs("span",{className:"text-xs text-muted-foreground",children:["Last run ",er(e.schedule.lastRunAt)]})]}),e.reports.length?a.jsx("div",{className:"overflow-hidden rounded-lg border bg-card",children:a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full min-w-[960px] text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b bg-muted/40 text-left text-xs text-muted-foreground",children:[a.jsx("th",{className:"px-4 py-3 font-medium",children:"Report period"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Schedule"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"AI provider"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Generated"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Status"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Total cost"}),a.jsx("th",{className:"px-4 py-3 text-right font-medium",children:"Actions"})]})}),a.jsx("tbody",{children:e.reports.map(o=>a.jsxs("tr",{className:"border-b last:border-0",children:[a.jsxs("td",{className:"px-4 py-3 font-medium",children:[zf(o.period.Start)," - ",Vf(o.period.End)]}),a.jsx("td",{className:"px-4 py-3 capitalize text-muted-foreground",children:o.frequency}),a.jsxs("td",{className:"px-4 py-3",children:[a.jsx("span",{className:"capitalize",children:o.provider||"-"}),o.modelId&&a.jsx("p",{className:"max-w-48 truncate text-xs text-muted-foreground",title:o.modelId,children:o.modelId})]}),a.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:er(o.completedAt||o.startedAt||o.createdAt)}),a.jsxs("td",{className:"px-4 py-3",children:[a.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full border px-2 py-1 text-xs font-medium ${Wf[o.status]}`,children:[(o.status==="RUNNING"||o.status==="PENDING")&&a.jsx(bt,{className:"h-3 w-3 animate-spin"}),o.status.toLowerCase()]}),o.error&&a.jsx("p",{className:"mt-1 max-w-xs truncate text-xs text-destructive",title:o.error,children:o.error})]}),a.jsx("td",{className:"px-4 py-3",children:o.facts?new Intl.NumberFormat(void 0,{style:"currency",currency:o.facts.currency}).format(o.facts.currentTotal):"-"}),a.jsx("td",{className:"px-4 py-3",children:a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsxs("button",{type:"button",onClick:()=>{e.download(o)},disabled:!o.pdfReady,className:"inline-flex h-9 items-center gap-2 rounded-lg border px-3 text-sm font-medium hover:bg-muted disabled:cursor-not-allowed disabled:opacity-40",title:o.pdfReady?"Download PDF":"PDF not ready",children:[a.jsx(Cr,{className:"h-4 w-4"}),"Download"]}),n&&a.jsx("button",{type:"button",onClick:()=>{e.remove(o)},disabled:e.removingId===o.id||o.status==="RUNNING"||o.status==="PENDING",className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border text-destructive hover:bg-destructive/10 disabled:cursor-not-allowed disabled:opacity-40",title:"Remove report","aria-label":"Remove report",children:e.removingId===o.id?a.jsx(bt,{className:"h-4 w-4 animate-spin"}):a.jsx(du,{className:"h-4 w-4"})})]})})]},o.id))})]})})}):a.jsx(ce,{children:a.jsxs(le,{className:"flex min-h-64 flex-col items-center justify-center px-6 text-center",children:[a.jsx(ta,{className:"h-8 w-8 text-muted-foreground"}),a.jsx("h2",{className:"mt-4 text-base font-semibold",children:"No scheduled reports yet"}),a.jsx("p",{className:"mt-2 max-w-lg text-sm text-muted-foreground",children:"The first report will appear here after the configured schedule runs."})]})})]}),e.schedule&&a.jsx($f,{open:s,schedule:e.schedule,saving:e.saving,onClose:()=>r(!1),onSave:e.saveSchedule})]})}const _t=ic({component:So}),qf=zt({getParentRoute:()=>_t,path:"/",component:gf}),Gf=zt({getParentRoute:()=>_t,path:"/reports",component:Ef}),Kf=zt({getParentRoute:()=>_t,path:"/cur-discovery",component:Af}),Yf=zt({getParentRoute:()=>_t,path:"/analysis",component:Hf}),Jf=zt({getParentRoute:()=>_t,path:"/sources",component:Mf});function Pr(){return _t.addChildren([qf,Yf,Gf,Jf,Kf])}function Xf(e="/cost"){return Ro({routeTree:Pr(),basepath:e})}function Zf({apiBase:e,token:t,basePath:s="/cost",userRole:r="user"}){Yo(e,t);const n=k.useMemo(()=>Ro({routeTree:Pr(),basepath:s}),[s]);return a.jsx(If,{value:r,children:a.jsx(Sc,{router:n})})}const Qf=[{title:"Overview",url:"/",icon:"DollarSign",roles:["admin","user"]},{title:"AI Analysis",url:"/analysis",icon:"Sparkles",roles:["admin","user"]},{title:"Reports",url:"/reports",icon:"FileText",roles:["admin","user"]},{title:"Sources",url:"/sources",icon:"CloudCog",roles:["admin"]},{title:"CUR Discovery",url:"/cur-discovery",icon:"Search",roles:["admin"]}];exports.CostPage=Zf;exports.api=re;exports.attachAuthInterceptors=wd;exports.configureApi=Yo;exports.costNavItems=Qf;exports.createCostRouter=Xf;exports.createRouteTree=Pr;
|
|
21
|
+
`),f=`${n}-summary-report-${Date.now()}.csv`);const u=document.createElement("a");u.href=URL.createObjectURL(new Blob([d],{type:"text/csv"})),u.download=f,u.click(),URL.revokeObjectURL(u.href)}async function kf(e){const{report:t,comparison:s,rows:r,groupBy:n,mode:o,start:i,end:c,granularity:l}=e,d=at[n],[{jsPDF:f},{default:u}]=await Promise.all([Promise.resolve().then(()=>require("./jspdf.es.min-C10id8ME.cjs")).then(g=>g.jspdf_es_min),Promise.resolve().then(()=>require("./jspdf.plugin.autotable-CvTok6mL.cjs"))]),h=new f({orientation:"landscape",unit:"pt",format:"a4"}),m=(g,x,b)=>{h.setFontSize(7),h.setTextColor(100),h.text(`Report generated · All costs in ${t.currency} · ${x} to ${b}`,40,h.internal.pageSize.height-18),h.text(`Page ${g.pageNumber}`,h.internal.pageSize.width-70,h.internal.pageSize.height-18)};if(o==="compare"&&s){h.setFontSize(18),h.setTextColor(25),h.text("Comparison Report",40,42),h.setFontSize(9),h.setTextColor(98,86,230),h.text("TOTAL COST",40,66),h.setTextColor(40),h.text(`Previous Cost: ${s.previous.totalCost}`,40,82),h.text(`Current Cost: ${s.current.totalCost}`,220,82),h.text(`Granularity: ${l}`,400,82),u(h,{startY:100,head:[[`${d.item} Name`,"Current Cost","Previous Cost","Current Period","Previous Period","Change %","Current Accounts","Previous Accounts","Current Regions","Previous Regions"]],body:r.map(g=>[g.label,g.current?.amount?.toFixed(2)||"0.00",g.previous?.amount?.toFixed(2)||"0.00",Rt(s.currentStart,s.currentEnd,l),Rt(s.previousStart,s.previousEnd,l),`${g.change.toFixed(4)}%`,Xe(g.current?.accounts),Xe(g.previous?.accounts),Xe(g.current?.regions),Xe(g.previous?.regions)]),styles:{fontSize:6,cellPadding:3,overflow:"linebreak"},headStyles:{fillColor:[242,237,255],textColor:[82,35,190]},didDrawPage:g=>m(g,s.previousStart,s.currentEnd),margin:{bottom:32}}),h.save(`comparison-report-${n}-${Date.now()}.pdf`);return}h.setFontSize(18),h.setTextColor(25),h.text(d.pdfTitle,40,42),h.setFontSize(9),h.setTextColor(98,86,230),h.text("REPORT METADATA",40,66),h.setTextColor(40),h.text(`Tenant ID: ${t.tenantId||"Current tenant"}`,40,82),h.text(`Date Range: ${i} to ${c}`,40,97),h.text(`Accrued Total Cost: ${K(t.totalCost,t.currency)}`,40,112),h.setTextColor(98,86,230),h.text("COST SUMMARY BREAKDOWN",40,136);const p=n==="account";u(h,{startY:146,head:[p?["Account ID","Account Name","Total Cost","Percentage","Regions"]:[`${d.item} Name`,"Total Cost","Percentage","Accounts","Regions"]],body:t.summary.map(g=>p?[g.accountId||g.key||"—",g.label,K(g.amount,t.currency),`${(g.percentage||0).toFixed(2)}%`,Xe(g.regions)]:[g.label,K(g.amount,t.currency),`${(g.percentage||0).toFixed(2)}%`,Xe(g.accounts),Xe(g.regions)]),styles:{fontSize:7,cellPadding:4,overflow:"linebreak"},headStyles:{fillColor:[242,237,255],textColor:[82,35,190]},didDrawPage:g=>m(g,i,c),margin:{bottom:32}}),h.save(`${n}-summary-report-${Date.now()}.pdf`)}function Ef(){const e=Cf(),{groupBy:t,mode:s,report:r,comparison:n,comparedRows:o,loading:i,error:c,dataStatus:l,granularity:d,start:f,end:u}=e,h=at[t],m=r?.summary[0],p=n?n.current.totalCost-n.previous.totalCost:0,g=n?.previous.totalCost?p/Math.abs(n.previous.totalCost)*100:0,x=r?{report:r,comparison:n,rows:o,groupBy:t,mode:s,start:f,end:u,granularity:d}:null,b=a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{onClick:()=>x&&void kf(x),disabled:!x||i,className:"flex items-center gap-2 rounded-md border bg-card px-3 py-1.5 text-sm disabled:opacity-50",children:[a.jsx(Yd,{className:"h-4 w-4"}),"PDF"]}),a.jsxs("button",{onClick:()=>x&&_f(x),disabled:!x||i,className:"flex items-center gap-2 rounded-md border bg-card px-3 py-1.5 text-sm disabled:opacity-50",children:[a.jsx(Cr,{className:"h-4 w-4"}),"CSV"]})]});return a.jsxs("div",{className:"flex w-full flex-col gap-5 p-2 md:p-6",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(ta,{className:"h-6 w-6 text-primary"}),"Cost reports"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Analyse live AWS cost by service, linked account, region, resource, or cost allocation tag"})]}),!i&&(l&&!l.ready||c&&!l)?a.jsx(Cs,{status:l,error:c}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex gap-1 overflow-x-auto border-b",children:Object.keys(at).map(y=>a.jsx("button",{onClick:()=>e.changeGroup(y),className:`border-b-2 px-4 py-3 text-sm font-medium ${t===y?"border-primary text-primary":"border-transparent text-muted-foreground"}`,children:at[y].tab},y))}),a.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1fr)_320px]",children:[a.jsxs("div",{className:"space-y-5",children:[c&&a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"h-4 w-4"}),c]}),i?a.jsx(yf,{}):s==="compare"&&n?a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"rounded-xl bg-primary/5 p-4",children:[a.jsxs("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-4",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"text-sm font-semibold",children:"Comparison Cost Summary"}),a.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Updated On: ",Bn(n.current.updatedAt)]})]}),b]}),a.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[a.jsx(Le,{label:"Period accrued total",value:`${K(n.current.totalCost,n.current.currency)} vs ${K(n.previous.totalCost,n.previous.currency)}`,helper:`${g>=0?"+":""}${g.toFixed(1)}% from previous period`,trend:g}),a.jsx(Le,{label:Rt(n.currentStart,n.currentEnd,d),value:K(n.current.totalCost,n.current.currency),helper:"Current period spending"}),a.jsx(Le,{label:Rt(n.previousStart,n.previousEnd,d),value:K(n.previous.totalCost,n.previous.currency),helper:"Previous period spending"}),a.jsx(Le,{label:d==="monthly"?"Monthly change":"Period change",value:`${p>=0?"+":""}${K(p,n.current.currency)}`,helper:`${g>=0?"+":""}${g.toFixed(1)}% from previous period`,trend:p})]})]}),a.jsx(bf,{rows:o,currency:n.current.currency}),a.jsx(jf,{rows:o,groupBy:t,comparison:n,granularity:d})]}):r?a.jsxs(a.Fragment,{children:[r.message&&a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border bg-muted/50 p-3 text-sm text-muted-foreground",children:[a.jsx(lt,{className:"h-4 w-4"}),r.message]}),a.jsxs("section",{className:"rounded-xl bg-primary/5 p-4",children:[a.jsxs("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-4",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"text-sm font-semibold",children:h.title}),a.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Updated On: ",Bn(r.updatedAt)]})]}),b]}),a.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[a.jsx(Le,{label:"Accrued cost",value:K(r.totalCost,r.currency)}),a.jsx(Le,{label:h.top,value:m?K(m.amount,r.currency):"-",accent:!0}),a.jsx(Le,{label:h.count,value:String(r.count||0),accent:!0})]})]}),a.jsxs(ce,{children:[a.jsx(ve,{children:a.jsx(Ne,{className:"text-sm",children:"Cost Trend"})}),a.jsx(le,{children:a.jsx(xf,{timeline:r.timeline||[],currency:r.currency||"USD",daily:d==="daily"})})]}),a.jsx(Rf,{groupBy:t,report:r})]}):null]}),a.jsx(Nf,{mode:s,groupBy:t,start:f,end:u,granularity:d,reportTagKey:e.reportTagKey,options:e.options,filters:e.draftFilters,loading:i,filtersLoading:e.filtersLoading,comparisonPeriods:e.selectedComparisonPeriods,onModeChange:e.changeMode,onStartChange:e.setStart,onEndChange:e.setEnd,onGranularityChange:e.setGranularity,onReportTagKeyChange:e.setReportTagKey,onFiltersChange:e.setDraftFilters,onLoadTagValues:y=>{e.loadOptions(y)},onRun:e.runReport,onApply:e.applyFilters,onReset:e.resetFilters})]})]})]})}const Wn={READY:"bg-emerald-500/10 text-emerald-600 border-emerald-500/30",RUNNING:"bg-blue-500/10 text-blue-600 border-blue-500/30",WAITING_FOR_DATA:"bg-amber-500/10 text-amber-600 border-amber-500/30",WAITING_FOR_TABLE:"bg-amber-500/10 text-amber-600 border-amber-500/30",FAILED:"bg-destructive/10 text-destructive border-destructive/30",PENDING:"bg-muted text-muted-foreground border-border"},Pf={INFO:"text-muted-foreground",WARN:"text-amber-600",ERROR:"text-destructive"},os=e=>e?new Date(e).toLocaleString():"—";function Tf({status:e}){return a.jsx("span",{className:`rounded-full border px-2 py-0.5 text-xs font-medium ${Wn[e]||Wn.PENDING}`,children:e.replace(/_/g," ")})}function De({label:e,value:t,mono:s}){return a.jsxs("div",{className:"flex flex-col gap-0.5",children:[a.jsx("span",{className:"text-xs text-muted-foreground",children:e}),a.jsx("span",{className:`break-all text-sm ${s?"font-mono text-xs":""}`,children:t||"—"})]})}function Af(){const[e,t]=k.useState([]),[s,r]=k.useState([]),[n,o]=k.useState(!0),[i,c]=k.useState(null),l=k.useCallback(async()=>{o(!0),c(null);try{const d=await re.get("/cur-discovery",{params:{logLimit:100}});t(d.data?.jobs||[]),r(d.data?.logs||[])}catch(d){c(d?.response?.data?.error||d?.message||"Unable to load CUR discovery status")}finally{o(!1)}},[]);return k.useEffect(()=>{l()},[l]),a.jsxs("div",{className:"flex w-full flex-col gap-6 p-2 md:p-6",children:[a.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(_r,{className:"h-6 w-6 text-primary"}),"CUR Discovery"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Progress of the scheduled job that locates this tenant’s Cost and Usage Report table. Cost data becomes available after it reports Ready."})]}),a.jsx("button",{onClick:()=>{l()},disabled:n,className:"rounded-lg border p-2 hover:bg-muted disabled:opacity-50","aria-label":"Refresh",children:a.jsx(St,{className:`h-4 w-4 ${n?"animate-spin":""}`})})]}),i&&a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"h-4 w-4"}),i]}),!n&&!i&&!e.length&&a.jsx(ce,{children:a.jsx(le,{className:"py-10 text-center text-sm text-muted-foreground",children:"No discovery job exists for this tenant yet. One is created automatically once the AWS connection is verified and the Cost plugin is entitled."})}),e.map(d=>a.jsxs(ce,{children:[a.jsxs(ve,{className:"flex flex-row flex-wrap items-center gap-3",children:[a.jsx(Zo,{className:"h-4 w-4 text-primary"}),a.jsxs(Ne,{className:"text-sm",children:["Connection ",d.connectionId]}),a.jsx(Tf,{status:d.status}),a.jsxs("span",{className:"text-xs text-muted-foreground",children:["attempt ",d.attemptCount]}),a.jsxs("span",{className:"ms-auto text-xs text-muted-foreground",children:["next check ",os(d.nextRunAt)]})]}),a.jsxs(le,{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:[a.jsx(De,{label:"Source",value:d.curS3Uri||`s3://${d.bucket}/${d.prefix}`,mono:!0}),a.jsx(De,{label:"Tenant partition",value:d.tenantPartition,mono:!0}),a.jsx(De,{label:"Region",value:d.region}),a.jsx(De,{label:"Glue database",value:d.database,mono:!0}),a.jsx(De,{label:"Discovered table",value:d.table,mono:!0}),a.jsx(De,{label:"Table location",value:d.tableLocation,mono:!0}),a.jsx(De,{label:"Sample object",value:d.sampleObjectKey,mono:!0}),a.jsx(De,{label:"Last data",value:os(d.lastDataAt)}),a.jsx(De,{label:"Last checked",value:os(d.lastFinishedAt||d.lastStartedAt)}),d.lastError&&a.jsx("div",{className:"md:col-span-2 lg:col-span-3 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:d.lastError})]})]},d.id)),e.length>0&&a.jsxs(ce,{children:[a.jsx(ve,{children:a.jsx(Ne,{className:"text-sm",children:"Recent activity"})}),a.jsx(le,{children:s.length?a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b text-left text-xs uppercase text-muted-foreground",children:[a.jsx("th",{className:"py-2 pe-4 font-medium",children:"Time"}),a.jsx("th",{className:"py-2 pe-4 font-medium",children:"Level"}),a.jsx("th",{className:"py-2 pe-4 font-medium",children:"Event"}),a.jsx("th",{className:"py-2 font-medium",children:"Message"})]})}),a.jsx("tbody",{children:s.map(d=>a.jsxs("tr",{className:"border-b last:border-0 align-top",children:[a.jsx("td",{className:"whitespace-nowrap py-2 pe-4 text-xs text-muted-foreground",children:os(d.createdAt)}),a.jsx("td",{className:`py-2 pe-4 text-xs font-medium ${Pf[d.level]||""}`,children:d.level}),a.jsx("td",{className:"whitespace-nowrap py-2 pe-4 font-mono text-xs",children:d.event}),a.jsx("td",{className:"py-2",children:d.message})]},d.id))})]})}):a.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No log entries recorded yet."})})]})]})}const Of=e=>e.launchUrl||`https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create?stackName=${encodeURIComponent(e.stackName||`MeyiConnect-${e.connectionId}-Management`)}`,Lf=e=>e==="CONNECTED"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-600":e==="FAILED"?"border-destructive/30 bg-destructive/10 text-destructive":"border-amber-500/30 bg-amber-500/10 text-amber-700",as=e=>e?.response?.data?.error||e?.response?.data?.message||e?.message||"Request failed";function Mf(){const[e,t]=k.useState([]),[s,r]=k.useState(!0),[n,o]=k.useState(!1),[i,c]=k.useState(""),[l,d]=k.useState(!1),[f,u]=k.useState(null),[h,m]=k.useState(null),[p,g]=k.useState(null),x=k.useCallback(async()=>{r(!0),g(null);try{t((await ie.getSources()).sources||[])}catch(w){g(as(w))}finally{r(!1)}},[]);k.useEffect(()=>{x()},[x]);const b=async w=>{if(w.preventDefault(),!/^\d{12}$/.test(i)){g("AWS account ID must contain exactly 12 digits");return}m("create"),g(null);try{const N=await ie.createSource({managementAccountId:i,regionMode:l?"ALL":"SINGLE"});u(N.connectionId),o(!1),c(""),d(!1),await x()}catch(N){g(as(N))}finally{m(null)}},y=async w=>{m(`download-${w}`),g(null);try{const N=await ie.downloadSourceTemplate(w),j=URL.createObjectURL(N),_=document.createElement("a");_.href=j,_.download=`meyi-connect-cost-${w}.yaml`,_.click(),URL.revokeObjectURL(j),u(w)}catch(N){g(as(N))}finally{m(null)}},S=async w=>{m(`verify-${w}`),g(null);try{const N=await ie.verifySource(w);N.status==="FAILED"&&g(N.message||"AWS connection verification failed"),await x()}catch(N){g(as(N))}finally{m(null)}};return a.jsxs("div",{className:"flex w-full flex-col gap-6 p-2 md:p-6",children:[a.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(js,{className:"h-6 w-6 text-primary"}),"Cost Sources"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"AWS accounts connected to this tenant for Cost and Usage Report data."})]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx("button",{type:"button",onClick:()=>{x()},disabled:s,className:"rounded-md border p-2 hover:bg-muted disabled:opacity-50","aria-label":"Refresh sources",title:"Refresh sources",children:a.jsx(St,{className:`h-4 w-4 ${s?"animate-spin":""}`})}),a.jsxs("button",{type:"button",onClick:()=>{g(null),o(!0)},className:"flex items-center gap-2 rounded-md bg-primary px-3 py-2 text-sm font-medium text-primary-foreground hover:opacity-90",children:[a.jsx(ru,{className:"h-4 w-4"}),"Add AWS account"]})]})]}),p&&a.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"mt-0.5 h-4 w-4 shrink-0"}),p]}),!s&&e.length===0&&a.jsxs("div",{className:"rounded-md border border-dashed py-14 text-center",children:[a.jsx(js,{className:"mx-auto mb-3 h-8 w-8 text-muted-foreground"}),a.jsx("p",{className:"font-medium",children:"No AWS Cost source"}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Add an AWS account to begin collecting tenant cost data."})]}),e.length>0&&a.jsx("div",{className:"overflow-x-auto rounded-md border",children:a.jsxs("table",{className:"w-full min-w-[780px] text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b bg-muted/50 text-left text-xs uppercase text-muted-foreground",children:[a.jsx("th",{className:"px-4 py-3 font-medium",children:"AWS account"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Connection"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Scope"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Status"}),a.jsx("th",{className:"px-4 py-3 text-right font-medium",children:"Actions"})]})}),a.jsx("tbody",{children:e.map(w=>a.jsxs("tr",{className:`border-b last:border-0 ${f===w.connectionId?"bg-muted/30":""}`,children:[a.jsx("td",{className:"px-4 py-3 font-mono",children:w.managementAccountId||"Pending"}),a.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:w.connectionId}),a.jsxs("td",{className:"px-4 py-3",children:[w.accountScope," / ",w.regionMode]}),a.jsxs("td",{className:"px-4 py-3",children:[a.jsx("span",{className:`rounded-full border px-2 py-1 text-xs font-medium ${Lf(w.status)}`,children:w.status.replace(/_/g," ")}),w.stackSetStatus&&a.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:w.stackSetStatus.replace(/_/g," ")})]}),a.jsx("td",{className:"px-4 py-3",children:a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsx("button",{type:"button",onClick:()=>{y(w.connectionId)},disabled:!!h,className:"rounded-md border p-2 hover:bg-muted disabled:opacity-50",title:"Download CloudFormation template","aria-label":"Download CloudFormation template",children:h===`download-${w.connectionId}`?a.jsx(bt,{className:"h-4 w-4 animate-spin"}):a.jsx(Cr,{className:"h-4 w-4"})}),a.jsx("a",{href:Of(w),target:"_blank",rel:"noreferrer",className:"rounded-md border p-2 hover:bg-muted",title:`Open AWS CloudFormation as ${w.stackName||`MeyiConnect-${w.connectionId}-Management`}`,"aria-label":"Open AWS CloudFormation",children:a.jsx(ea,{className:"h-4 w-4"})}),a.jsxs("button",{type:"button",onClick:()=>{S(w.connectionId)},disabled:!!h||w.status==="CONNECTED",className:"flex items-center gap-2 rounded-md border px-3 py-2 font-medium hover:bg-muted disabled:opacity-50",children:[h===`verify-${w.connectionId}`?a.jsx(bt,{className:"h-4 w-4 animate-spin"}):w.status==="CONNECTED"?a.jsx($d,{className:"h-4 w-4 text-emerald-600"}):a.jsx(St,{className:"h-4 w-4"}),w.status==="CONNECTED"?"Connected":"Verify"]})]})})]},w.connectionId))})]})}),n&&a.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",role:"dialog","aria-modal":"true","aria-labelledby":"add-source-title",children:a.jsxs("form",{onSubmit:w=>{b(w)},className:"w-full max-w-md rounded-md border bg-background p-5 shadow-xl",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsx("h2",{id:"add-source-title",className:"text-lg font-semibold",children:"Add AWS account"}),a.jsx("button",{type:"button",onClick:()=>o(!1),className:"rounded-md p-1 hover:bg-muted","aria-label":"Close",children:a.jsx(Os,{className:"h-4 w-4"})})]}),a.jsx("label",{className:"mt-5 block text-sm font-medium",htmlFor:"aws-account-id",children:"AWS account ID"}),a.jsx("input",{id:"aws-account-id",value:i,onChange:w=>c(w.target.value.replace(/\D/g,"").slice(0,12)),inputMode:"numeric",autoComplete:"off",placeholder:"123456789012",className:"mt-2 h-10 w-full rounded-md border bg-background px-3 font-mono outline-none focus:ring-2 focus:ring-ring"}),a.jsxs("label",{className:"mt-4 flex items-start gap-3 rounded-md border p-3",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:w=>d(w.target.checked),className:"mt-1 h-4 w-4"}),a.jsxs("span",{children:[a.jsx("span",{className:"block text-sm font-medium",children:"All enabled AWS regions"}),a.jsx("span",{className:"block text-xs text-muted-foreground",children:"Use organization-wide StackSet deployment across enabled regions."})]})]}),a.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[a.jsx("button",{type:"button",onClick:()=>o(!1),className:"rounded-md border px-4 py-2 text-sm font-medium hover:bg-muted",children:"Cancel"}),a.jsxs("button",{type:"submit",disabled:h==="create"||i.length!==12,className:"flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:[h==="create"&&a.jsx(bt,{className:"h-4 w-4 animate-spin"}),"Create source"]})]})]})})]})}const Sa=k.createContext("user"),If=Sa.Provider,Df=()=>k.useContext(Sa),Ff=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Uf=["UTC","Asia/Kolkata","America/New_York","America/Los_Angeles","Europe/London","Europe/Berlin","Asia/Singapore","Asia/Tokyo","Australia/Sydney"];function $f({open:e,schedule:t,saving:s,onClose:r,onSave:n}){const[o,i]=k.useState(t);if(k.useEffect(()=>i(t),[t,e]),!e)return null;const c=l=>i(d=>({...d,frequency:l}));return a.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4",role:"presentation",onMouseDown:l=>{l.target===l.currentTarget&&r()},children:a.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"cost-ai-schedule-title",className:"w-full max-w-lg overflow-hidden rounded-lg border bg-background shadow-xl",children:[a.jsxs("div",{className:"flex items-start justify-between border-b px-5 py-4",children:[a.jsxs("div",{children:[a.jsxs("h2",{id:"cost-ai-schedule-title",className:"flex items-center gap-2 text-base font-semibold",children:[a.jsx(Xo,{className:"h-4 w-4 text-primary"}),"AI report schedule"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Reports run automatically against completed AWS CUR periods."})]}),a.jsx("button",{type:"button",onClick:r,className:"rounded-md p-1.5 hover:bg-muted","aria-label":"Close",children:a.jsx(Os,{className:"h-4 w-4"})})]}),a.jsxs("form",{className:"space-y-5 p-5",onSubmit:l=>{l.preventDefault(),n({enabled:o.enabled,frequency:o.frequency,time:o.time,timezone:o.timezone,dayOfWeek:o.dayOfWeek,dayOfMonth:o.dayOfMonth}).then(r)},children:[a.jsxs("label",{className:"flex items-center justify-between gap-4 rounded-lg border p-3",children:[a.jsxs("span",{children:[a.jsx("span",{className:"block text-sm font-medium",children:"Scheduled reports"}),a.jsx("span",{className:"block text-xs text-muted-foreground",children:"Generate reports without a manual action"})]}),a.jsx("input",{type:"checkbox",checked:o.enabled,onChange:l=>i(d=>({...d,enabled:l.target.checked})),className:"h-4 w-4 accent-primary"})]}),a.jsxs("fieldset",{disabled:!o.enabled||s,className:"space-y-5 disabled:opacity-60",children:[a.jsxs("div",{children:[a.jsx("span",{className:"mb-2 block text-sm font-medium",children:"Frequency"}),a.jsx("div",{className:"grid grid-cols-3 rounded-lg border p-1",children:["daily","weekly","monthly"].map(l=>a.jsx("button",{type:"button",onClick:()=>c(l),className:`rounded-md px-3 py-2 text-sm capitalize ${o.frequency===l?"bg-primary text-primary-foreground":"hover:bg-muted"}`,children:l},l))})]}),a.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[a.jsxs("label",{className:"text-sm font-medium",children:["Run time",a.jsx("input",{type:"time",required:!0,value:o.time,onChange:l=>i(d=>({...d,time:l.target.value})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal"})]}),a.jsxs("label",{className:"text-sm font-medium",children:["Timezone",a.jsx("select",{value:o.timezone,onChange:l=>i(d=>({...d,timezone:l.target.value})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal",children:[...new Set([o.timezone,...Uf])].map(l=>a.jsx("option",{children:l},l))})]})]}),o.frequency==="weekly"&&a.jsxs("label",{className:"block text-sm font-medium",children:["Day of week",a.jsx("select",{value:o.dayOfWeek??1,onChange:l=>i(d=>({...d,dayOfWeek:Number(l.target.value)})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal",children:Ff.map((l,d)=>a.jsx("option",{value:d,children:l},l))})]}),o.frequency==="monthly"&&a.jsxs("label",{className:"block text-sm font-medium",children:["Day of month",a.jsx("input",{type:"number",min:1,max:28,value:o.dayOfMonth??1,onChange:l=>i(d=>({...d,dayOfMonth:Number(l.target.value)})),className:"mt-2 block h-10 w-full rounded-lg border bg-background px-3 font-normal"})]}),a.jsx("p",{className:"text-xs text-muted-foreground",children:"Daily reports cover the previous day, weekly reports the previous seven complete days, and monthly reports the previous calendar month."})]}),a.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[a.jsx("button",{type:"button",onClick:r,className:"rounded-lg border px-4 py-2 text-sm font-medium hover:bg-muted",children:"Cancel"}),a.jsx("button",{type:"submit",disabled:s,className:"rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:s?"Saving":"Save schedule"})]})]})]})})}function Bf(){const[e,t]=k.useState(null),[s,r]=k.useState(null),[n,o]=k.useState(null),[i,c]=k.useState([]),[l,d]=k.useState(!0),[f,u]=k.useState(!1),[h,m]=k.useState(null),[p,g]=k.useState(null),x=k.useRef(!0),b=k.useCallback(async(N=!1)=>{N||d(!0);try{const[j,_,R,E]=await Promise.all([ie.getAnalysisStatus(),ie.getDataStatus(),ie.getAnalysisSchedule(),ie.getAnalysisReports()]);if(!x.current)return;t(j),r(_),o(R),c(E),g(null)}catch(j){x.current&&g(j?.response?.data?.error||j?.message||"Unable to load scheduled AI reports")}finally{x.current&&!N&&d(!1)}},[]);return k.useEffect(()=>(x.current=!0,b(),()=>{x.current=!1}),[b]),k.useEffect(()=>{if(!i.some(j=>j.status==="PENDING"||j.status==="RUNNING"))return;const N=window.setInterval(()=>{b(!0)},15e3);return()=>window.clearInterval(N)},[b,i]),{status:e,dataStatus:s,schedule:n,reports:i,loading:l,saving:f,removingId:h,error:p,load:b,saveSchedule:async N=>{u(!0),g(null);try{const j=await ie.updateAnalysisSchedule(N);x.current&&o(j)}catch(j){throw g(j?.response?.data?.error||j?.message||"Unable to save the AI report schedule"),j}finally{x.current&&u(!1)}},download:async N=>{try{const j=await ie.downloadAnalysisPdf(N.id),_=URL.createObjectURL(j),R=document.createElement("a");R.href=_,R.download=`meyi-cost-analysis-${N.period.Start}.pdf`,R.click(),URL.revokeObjectURL(_)}catch(j){g(j?.response?.data?.error||j?.message||"Unable to download the PDF report")}},remove:async N=>{if(window.confirm(`Remove the AI cost report for ${N.period.Start} through ${N.period.End}?`)){m(N.id),g(null);try{await ie.removeAnalysisReport(N.id),x.current&&c(j=>j.filter(_=>_.id!==N.id))}catch(j){x.current&&g(j?.response?.data?.error||j?.message||"Unable to remove the AI report")}finally{x.current&&m(null)}}}}}const er=e=>e?new Date(e).toLocaleString():"Not scheduled",zf=e=>new Date(`${e}T00:00:00Z`).toLocaleDateString(),Vf=e=>{const t=new Date(`${e}T00:00:00Z`);return t.setUTCDate(t.getUTCDate()-1),t.toLocaleDateString()},Wf={COMPLETED:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",RUNNING:"border-blue-500/30 bg-blue-500/10 text-blue-700",PENDING:"border-amber-500/30 bg-amber-500/10 text-amber-700",FAILED:"border-destructive/30 bg-destructive/10 text-destructive"};function Hf(){const e=Bf(),t=Df(),[s,r]=k.useState(!1),n=t.toLowerCase()==="admin";return a.jsxs("div",{className:"flex min-w-0 max-w-full flex-col gap-6 overflow-x-hidden p-2 md:p-6",children:[a.jsxs("header",{className:"flex flex-wrap items-start justify-between gap-4",children:[a.jsxs("div",{children:[a.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold",children:[a.jsx(An,{className:"h-6 w-6 text-primary"}),"AI Cost Analysis"]}),a.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Scheduled Cost reports generated from AWS CUR data"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{type:"button",onClick:()=>{e.load()},disabled:e.loading,className:"rounded-lg border p-2.5 hover:bg-muted disabled:opacity-50",title:"Refresh reports","aria-label":"Refresh reports",children:a.jsx(St,{className:`h-4 w-4 ${e.loading?"animate-spin":""}`})}),n&&e.schedule&&a.jsxs("button",{type:"button",onClick:()=>r(!0),className:"inline-flex h-10 items-center gap-2 rounded-lg bg-primary px-4 text-sm font-medium text-primary-foreground",children:[a.jsx(ra,{className:"h-4 w-4"}),"Report settings"]})]})]}),e.error&&a.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:[a.jsx(lt,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.error]}),e.loading?a.jsx("div",{className:"h-72 animate-pulse rounded-lg bg-muted"}):e.dataStatus&&!e.dataStatus.ready?a.jsx(Cs,{status:e.dataStatus}):e.status&&!e.status.enabled?a.jsx(ce,{children:a.jsxs(le,{className:"flex min-h-64 flex-col items-center justify-center px-6 text-center",children:[a.jsx(An,{className:"h-8 w-8 text-muted-foreground"}),a.jsx("h2",{className:"mt-4 text-base font-semibold",children:e.status.reason==="AI_PROVIDER_REQUIRED"?"Configure an AI provider":"AI cost analysis is not enabled"}),a.jsx("p",{className:"mt-2 max-w-xl text-sm text-muted-foreground",children:e.status.reason==="AI_PROVIDER_REQUIRED"?"Configure and activate an AI provider in Meyi Connect before scheduled cost reports can run.":"An administrator must enable the Cost AI deployment setting before scheduled reports can run."})]})}):a.jsxs(a.Fragment,{children:[a.jsxs("section",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-card px-4 py-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Xo,{className:"h-5 w-5 text-primary"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm font-semibold",children:e.schedule?.enabled?`${e.schedule.frequency[0].toUpperCase()}${e.schedule.frequency.slice(1)} reports enabled`:"Scheduled reports disabled"}),a.jsx("p",{className:"text-xs text-muted-foreground",children:e.schedule?.enabled?`Next run ${er(e.schedule.nextRunAt)} (${e.schedule.timezone})`:n?"Open report settings to configure a schedule":"An administrator can configure the report schedule"})]})]}),e.schedule?.lastRunAt&&a.jsxs("span",{className:"text-xs text-muted-foreground",children:["Last run ",er(e.schedule.lastRunAt)]})]}),e.reports.length?a.jsx("div",{className:"overflow-hidden rounded-lg border bg-card",children:a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full min-w-[960px] text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"border-b bg-muted/40 text-left text-xs text-muted-foreground",children:[a.jsx("th",{className:"px-4 py-3 font-medium",children:"Report period"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Schedule"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"AI provider"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Generated"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Status"}),a.jsx("th",{className:"px-4 py-3 font-medium",children:"Total cost"}),a.jsx("th",{className:"px-4 py-3 text-right font-medium",children:"Actions"})]})}),a.jsx("tbody",{children:e.reports.map(o=>a.jsxs("tr",{className:"border-b last:border-0",children:[a.jsxs("td",{className:"px-4 py-3 font-medium",children:[zf(o.period.Start)," - ",Vf(o.period.End)]}),a.jsx("td",{className:"px-4 py-3 capitalize text-muted-foreground",children:o.frequency}),a.jsxs("td",{className:"px-4 py-3",children:[a.jsx("span",{className:"capitalize",children:o.provider||"-"}),o.modelId&&a.jsx("p",{className:"max-w-48 truncate text-xs text-muted-foreground",title:o.modelId,children:o.modelId})]}),a.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:er(o.completedAt||o.startedAt||o.createdAt)}),a.jsxs("td",{className:"px-4 py-3",children:[a.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full border px-2 py-1 text-xs font-medium ${Wf[o.status]}`,children:[(o.status==="RUNNING"||o.status==="PENDING")&&a.jsx(bt,{className:"h-3 w-3 animate-spin"}),o.status.toLowerCase()]}),o.error&&a.jsx("p",{className:"mt-1 max-w-xs truncate text-xs text-destructive",title:o.error,children:o.error})]}),a.jsx("td",{className:"px-4 py-3",children:o.facts?new Intl.NumberFormat(void 0,{style:"currency",currency:o.facts.currency}).format(o.facts.currentTotal):"-"}),a.jsx("td",{className:"px-4 py-3",children:a.jsxs("div",{className:"flex justify-end gap-2",children:[a.jsxs("button",{type:"button",onClick:()=>{e.download(o)},disabled:!o.pdfReady,className:"inline-flex h-9 items-center gap-2 rounded-lg border px-3 text-sm font-medium hover:bg-muted disabled:cursor-not-allowed disabled:opacity-40",title:o.pdfReady?"Download PDF":"PDF not ready",children:[a.jsx(Cr,{className:"h-4 w-4"}),"Download"]}),n&&a.jsx("button",{type:"button",onClick:()=>{e.remove(o)},disabled:e.removingId===o.id||o.status==="RUNNING"||o.status==="PENDING",className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border text-destructive hover:bg-destructive/10 disabled:cursor-not-allowed disabled:opacity-40",title:"Remove report","aria-label":"Remove report",children:e.removingId===o.id?a.jsx(bt,{className:"h-4 w-4 animate-spin"}):a.jsx(du,{className:"h-4 w-4"})})]})})]},o.id))})]})})}):a.jsx(ce,{children:a.jsxs(le,{className:"flex min-h-64 flex-col items-center justify-center px-6 text-center",children:[a.jsx(ta,{className:"h-8 w-8 text-muted-foreground"}),a.jsx("h2",{className:"mt-4 text-base font-semibold",children:"No scheduled reports yet"}),a.jsx("p",{className:"mt-2 max-w-lg text-sm text-muted-foreground",children:"The first report will appear here after the configured schedule runs."})]})})]}),e.schedule&&a.jsx($f,{open:s,schedule:e.schedule,saving:e.saving,onClose:()=>r(!1),onSave:e.saveSchedule})]})}const _t=ic({component:So}),qf=zt({getParentRoute:()=>_t,path:"/",component:gf}),Gf=zt({getParentRoute:()=>_t,path:"/reports",component:Ef}),Kf=zt({getParentRoute:()=>_t,path:"/cur-discovery",component:Af}),Yf=zt({getParentRoute:()=>_t,path:"/analysis",component:Hf}),Jf=zt({getParentRoute:()=>_t,path:"/sources",component:Mf});function Pr(){return _t.addChildren([qf,Yf,Gf,Jf,Kf])}function Xf(e="/cost"){return Ro({routeTree:Pr(),basepath:e})}function Zf({apiBase:e,token:t,basePath:s="/cost",userRole:r="user"}){Yo(e,t);const n=k.useMemo(()=>Ro({routeTree:Pr(),basepath:s}),[s]);return a.jsx(If,{value:r,children:a.jsx(Sc,{router:n})})}const Qf=[{title:"Overview",url:"/",icon:"DollarSign",roles:["admin","user"]},{title:"AI Analysis",url:"/analysis",icon:"Sparkles",roles:["admin","user"]},{title:"Reports",url:"/reports",icon:"FileText",roles:["admin","user"]},{title:"Sources",url:"/sources",icon:"CloudCog",roles:["admin"]},{title:"CUR Discovery",url:"/cur-discovery",icon:"Search",roles:["admin"]}];exports.CostPage=Zf;exports.api=re;exports.attachAuthInterceptors=wd;exports.configureApi=Yo;exports.costNavItems=Qf;exports.createCostRouter=Xf;exports.createRouteTree=Pr;
|
package/dist/index.mjs
CHANGED
|
@@ -10793,7 +10793,7 @@ function Uf() {
|
|
|
10793
10793
|
] })
|
|
10794
10794
|
] });
|
|
10795
10795
|
}
|
|
10796
|
-
const $f =
|
|
10796
|
+
const $f = (e) => e.launchUrl || `https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create?stackName=${encodeURIComponent(e.stackName || `MeyiConnect-${e.connectionId}-Management`)}`, Bf = (e) => e === "CONNECTED" ? "border-emerald-500/30 bg-emerald-500/10 text-emerald-600" : e === "FAILED" ? "border-destructive/30 bg-destructive/10 text-destructive" : "border-amber-500/30 bg-amber-500/10 text-amber-700", ls = (e) => e?.response?.data?.error || e?.response?.data?.message || e?.message || "Request failed";
|
|
10797
10797
|
function zf() {
|
|
10798
10798
|
const [e, t] = U([]), [s, r] = U(!0), [n, o] = U(!1), [i, c] = U(""), [l, d] = U(!1), [f, u] = U(null), [h, m] = U(null), [p, g] = U(null), x = Ut(async () => {
|
|
10799
10799
|
r(!0), g(null);
|
|
@@ -10897,7 +10897,7 @@ function zf() {
|
|
|
10897
10897
|
/* @__PURE__ */ a.jsx("button", { type: "button", onClick: () => {
|
|
10898
10898
|
y(w.connectionId);
|
|
10899
10899
|
}, disabled: !!h, className: "rounded-md border p-2 hover:bg-muted disabled:opacity-50", title: "Download CloudFormation template", "aria-label": "Download CloudFormation template", children: h === `download-${w.connectionId}` ? /* @__PURE__ */ a.jsx(vt, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ a.jsx(Ar, { className: "h-4 w-4" }) }),
|
|
10900
|
-
/* @__PURE__ */ a.jsx("a", { href: $f, target: "_blank", rel: "noreferrer", className: "rounded-md border p-2 hover:bg-muted", title:
|
|
10900
|
+
/* @__PURE__ */ a.jsx("a", { href: $f(w), target: "_blank", rel: "noreferrer", className: "rounded-md border p-2 hover:bg-muted", title: `Open AWS CloudFormation as ${w.stackName || `MeyiConnect-${w.connectionId}-Management`}`, "aria-label": "Open AWS CloudFormation", children: /* @__PURE__ */ a.jsx(oa, { className: "h-4 w-4" }) }),
|
|
10901
10901
|
/* @__PURE__ */ a.jsxs("button", { type: "button", onClick: () => {
|
|
10902
10902
|
S(w.connectionId);
|
|
10903
10903
|
}, disabled: !!h || w.status === "CONNECTED", className: "flex items-center gap-2 rounded-md border px-3 py-2 font-medium hover:bg-muted disabled:opacity-50", children: [
|
package/dist/types.d.ts
CHANGED