import{k as C,j as n,ap as P,R as m,dj as w,o as x,e8 as R,l as A,a8 as T,e9 as F,aR as k}from"./app-BgLa5dit.js";import{F as h}from"./B5-QmNlz.chunk.js";import{O as D}from"./B-fq6xxv.chunk.js";import{E}from"./D-bfnq46.chunk.js";import{g as L}from"./DdbSDhh9.chunk.js";const $={"text/csv":"csv"},H={"text/csv":"text/csv;charset=utf-8;"};function I(){const e=C();async function o(t){const{request:r,mimeType:s="text/csv",filename:p}=t,i=`${p}.${$[s]}`,c=H[s];if(typeof r!="string"){const d=await e(r);h.downloadDataAsFile(d,i,c);return}h.downloadDataAsFile(r,i,c)}return o}const S=[{Header:"Name",accessor:"name"},{Header:"Description",accessor:"description"},{Header:"Actions",accessor:"actions",Cell:({row:e})=>n.jsx("div",{children:n.jsx(w,{variant:"outline-dark",onClick:e.original.actions[0].onClick,disabled:e.original.actions[0].loading??!1,showSpinner:e.original.actions[0].loading??!1,spinnerText:"Generating...",children:e.original.actions[0].label})})}];function G(e){return m.useMemo(()=>[{name:"Produced videos report",description:`A report that lists all the videos produced by ${e.entity}.`,actions:[{label:"Generate Report",onClick:()=>e.generateReport("company"),loading:e.loading.company}]},{name:"Distributed videos report",description:`A report that lists all the videos distributed by ${e.entity}.`,actions:[{label:"Generate Report",onClick:()=>e.generateReport("distributor"),loading:e.loading.distributor}]}],[e.entity,e.loading,e.generateReport])}const M={table:"striped-list no-full-width pb-3",header:"fw-semibold pb-1",headerCell:"px-2 py-1",row:"striped-row rounded",cell:"d-flex align-items-center py-1 px-2"};function q(e){var t;const o=G({entity:((t=e.contentPartner)==null?void 0:t.name)??"company",generateReport:e.generateReport,loading:e.loading});return n.jsx("div",{className:"mt-3",children:n.jsx(P,{data:o,columns:S,theme:M})})}const N={company:"produced-videos-report",distributor:"distributed-videos-report"};function _(e){const o=x(k.currentUser()),t=x(R.getContentPartner(e.contentPartnerId)),r=A(),s=I(),[p,i]=m.useState({company:!1,distributor:!1}),c=L();function d(a,l){i(u=>({...u,[a]:l}))}const v=m.useCallback(async a=>{var g,f,y,b;const l=(f=(g=t.data)==null?void 0:g.company)==null?void 0:f.id;if(!l){r.error("Company ID not found");return}const u=T.slugify(`${(y=t.data)==null?void 0:y.name}-${N[a]}`);d(a,!0);try{await s({request:R.generateVideoListReport(l,a),filename:u}),r.success(`Report generated for ${(b=t.data)==null?void 0:b.name}`)}catch{r.error("Failed to generate video list report")}finally{d(a,!1)}},[t.data,r,s]),j=!!t.data;return n.jsxs(n.Fragment,{children:[!!o.data&&n.jsx(E,{contentPartnerId:e.contentPartnerId,activeAction:c.viewReports(e.contentPartnerId).action,currentUser:o.data}),(()=>{var a;return j?n.jsxs(n.Fragment,{children:[n.jsx(D,{object:{name:`${(a=t.data)==null?void 0:a.name} Reports`}}),n.jsx(q,{loading:p,contentPartner:t.data,generateReport:v})]}):n.jsx(F,{})})()]})}export{_ as ContentPartnerReportsView};
//# sourceMappingURL=CMUZfRaU.chunk.js.map
