1import{j as a,b as x,a as T}from"./vendor-query-C0G7-zTq.js";import{r as p,k as A}from"./vendor-react-Cog84hhN.js";import{m as U,an as F,am as R,aD as L,B as g,e as w,ag as f,D as q,a3 as B,N as M,ac as O,b6 as _,aa as $}from"./index-Cn9CABFg.js";import{F as Y,f as v,a as K}from"./FilePreview-BwwL2hmD.js";import{E as Q}from"./eye-LO849pZB.js";import{D as y}from"./download-BELtw3k5.js";import{d as V}from"./download-YTM_5c9V.js";import{C as G}from"./chevron-right-BmQMJJjB.js";import"./vendor-sentry-Bg9nlJsI.js";import"./vendor-charts-Dj5OJhBv.js";import"./file-spreadsheet-DuEVCuaE.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"[email protected]"}}catch{}})();try{(function(){var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="992a4455-e434-4514-87c6-0ef893e3f6a5",e._sentryDebugIdIdentifier="sentry-dbid-992a4455-e434-4514-87c6-0ef893e3f6a5")})()}catch{}function H({resource:e,onView:t,onDownload:s}){const[i,o]=p.useState(!1),m=e.mimeType.startsWith("image/")&&!i;return a.jsxs(U,{className:"group hover:shadow-lg transition-all duration-200 hover:scale-[1.02] cursor-pointer",onClick:()=>t(e),children:[a.jsx(F,{className:"pb-3",children:a.jsx("div",{className:"w-full h-40 bg-gray-100 rounded-md flex items-center justify-center overflow-hidden",children:m?a.jsx("img",{src:e.fileUrl,alt:e.title,className:"w-full h-full object-cover",onError:()=>o(!0)}):a.jsx(Y,{fileName:e.fileName,size:64})})}),a.jsxs(R,{className:"pb-3",children:[a.jsx("h3",{className:"font-semibold text-gray-900 line-clamp-2 mb-2",title:e.title,children:e.title}),e.description&&a.jsx("p",{className:"text-sm text-gray-600 line-clamp-3",title:e.description,children:e.description}),a.jsx("p",{className:"text-xs text-gray-500 mt-2",children:v(e.fileSize)})]}),a.jsxs(L,{className:"pt-0 gap-2 flex-wrap",children:[a.jsxs(g,{variant:"outline",size:"sm",className:"flex-1 min-w-[7.5rem]",onClick:d=>{d.stopPropagation(),t(e)},children:[a.jsx(Q,{className:"h-4 w-4 mr-2"}),"Visualizar"]}),a.jsxs(g,{size:"sm",className:"flex-1 min-w-[7.5rem]",onClick:d=>{d.stopPropagation(),s(e)},children:[a.jsx(y,{className:"h-4 w-4 mr-2"}),"Download"]})]})]})}function W({resources:e,onView:t,onDownload:s,isLoading:i=!1}){return i?a.jsx("div",{className:"border rounded-lg p-12 text-center",children:a.jsx("p",{className:"text-gray-500",children:"Carregando recursos..."})}):e.length===0?a.jsxs("div",{className:"border rounded-lg p-12 text-center",children:[a.jsx("p",{className:"text-gray-500",children:"Nenhum recurso disponÃvel no momento."}),a.jsx("p",{className:"text-sm text-gray-400 mt-2",children:"Os recursos da marca aparecerão aqui quando disponÃveis."})]}):a.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:e.map(o=>a.jsx(H,{resource:o,onView:t,onDownload:s},o.id))})}function X(e){if(!e||typeof e.id!="number")throw new Error("Invalid resource: missing or invalid id");if(typeof e.fileSizeBytes!="number"||e.fileSizeBytes<0)throw new Error(`Invalid resource ${e.id}: missing or invalid fileSizeBytes`);if(typeof e.isActive!="boolean")throw new Error(`Invalid resource ${e.id}: missing or invalid isActive`);const t={...e,fileSize:e.fileSizeBytes,status:e.isActive?"active":"inactive"};return"downloadCount"in e&&typeof e.downloadCount=="number"?{...t,downloadCount:e.downloadCount}:t}function J(e){if(!e)throw new Error("Missing pagination data");if(typeof e.page!="number"||e.page<1)throw new Error("Invalid pagination: page must be a positive number");if(typeof e.pageSize!="number"||e.pageSize<1)throw new Error("Invalid pagination: pageSize must be a positive number");if(typeof e.totalCount!="number"||e.totalCount<0)throw new Error("Invalid pagination: totalCount must be a non-negative number");if(typeof e.totalPages!="number"||e.totalPages<0)throw new Error("Invalid pagination: totalPages must be a non-negative number")}async function Z(e){const t=new URLSearchParams;e?.search&&t.append("search",e.search),e?.page&&t.append("page",e.page.toString()),e?.pageSize&&t.append("pageSize",e.pageSize.toString());const s=await w.get(`/api/influencer/resources?${t.toString()}`);if(!s.data||!s.data.data)throw new Error("Invalid API response: missing data");const i=s.data.data;if(J(i),!Array.isArray(i.items))throw new Error("Invalid API response: items must be an array");return{resources:i.items.map(X),pagination:{page:i.page,limit:i.pageSize,total:i.totalCount,totalPages:i.totalPages}}}async function j(e){const t=await w.get(`/api/influencer/resources/${e}/download`);
1if(!t.data||!t.data.data)throw new Error("Invalid API response: missing data");const s=t.data.data;if(!s.downloadUrl||typeof s.downloadUrl!="string")throw new Error("Invalid download response: missing or invalid downloadUrl");if(!s.expiresAt||typeof s.expiresAt!="string")throw new Error("Invalid download response: missing or invalid expiresAt");return s}function k({open:e,onOpenChange:t,resource:s}){const[i,o]=p.useState(!1),m=x({mutationFn:c=>j(c),onSuccess:c=>{V(c.downloadUrl,s?.fileName),o(!1),f.success("Download iniciado",{description:"O arquivo será baixado em breve."})},onError:c=>{o(!1),f.error("Erro",{description:c.response?.data?.message||"Erro ao fazer download do arquivo."})}}),d=async()=>{s&&(o(!0),await m.mutateAsync(s.id))};return s?a.jsx(q,{open:e,onClose:()=>t(!1),title:s.title,size:"xl",children:a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsx("div",{className:"lg:col-span-1",children:a.jsx(K,{fileName:s.fileName,fileUrl:s.fileUrl,mimeType:s.mimeType,className:"h-96",showDownloadButton:!1})}),a.jsxs("div",{className:"lg:col-span-1 space-y-4",children:[s.description&&a.jsxs("div",{children:[a.jsx("label",{className:"text-sm font-medium text-gray-600",children:"Descrição"}),a.jsx("p",{className:"text-sm text-gray-700 whitespace-pre-wrap mt-1",children:s.description})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t",children:[a.jsxs("div",{children:[a.jsx("label",{className:"text-sm font-medium text-gray-600",children:"Nome do arquivo"}),a.jsx("p",{className:"text-sm font-medium truncate",children:s.fileName})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"text-sm font-medium text-gray-600",children:"Tamanho"}),a.jsx("p",{className:"text-sm font-medium",children:v(s.fileSize)})]}),a.jsxs("div",{children:[a.jsx("label",{className:"text-sm font-medium text-gray-600",children:"Tipo"}),a.jsx("p",{className:"text-sm font-medium font-mono",children:s.fileExtension})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"text-sm font-medium text-gray-600",children:"Disponibilizado em"}),a.jsx("p",{className:"text-sm font-medium",children:new Date(s.createdAt).toLocaleDateString("pt-BR",{day:"2-digit",month:"long",year:"numeric"})})]})]}),a.jsxs("div",{className:"pt-4",children:[a.jsxs(g,{onClick:d,disabled:i,className:"w-full",children:[a.jsx(y,{className:"h-5 w-5 mr-2"}),i?"Preparando download...":"Fazer Download"]}),a.jsx("p",{className:"text-xs text-gray-500 text-center mt-2",children:"O download será registrado para auditoria"})]})]})]})}):null}function me(){const[e,t]=A(),[s,i]=p.useState(e.get("search")||""),[o,m]=p.useState(!1),[d,c]=p.useState(null),h={search:e.get("search")||void 0,page:parseInt(e.get("page")||"1",10),pageSize:parseInt(e.get("pageSize")||"12",10)},{data:r,isLoading:N,error:b}=T({queryKey:$.INFLUENCER_RESOURCES_LIST(h),queryFn:()=>Z(h),staleTime:3e5}),S=x({mutationFn:n=>j(n),onSuccess:n=>{window.location.href=n.downloadUrl,f.success("Download iniciado. O arquivo será baixado em breve.")},onError:n=>{f.error(n.response?.data?.message||"Erro ao fazer download do arquivo.")}}),u=p.useRef(null),E=n=>{i(n),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{const l=new URLSearchParams(e);n?l.set("search",n):l.delete("search"),l.set("page","1"),t(l)},500)},I=()=>{i("");const n=new URLSearchParams(e);n.delete("search"),n.set("page","1"),t(n)},P=n=>{c(n),m(!0)},C=async n=>{await S.mutateAsync(n.id)},z=()=>{const n=new URLSearchParams(e),l=parseInt(n.get("page")||"1",10);n.set("page",Math.max(1,l-1).toString()),t(n)},D=()=>{if(r?.pagination){const n=new URLSearchParams(e),l=parseInt(n.get("page")||"1",10);l<r.pagination.totalPages&&(n.set("page",(l+1).toString()),t(n))}};return a.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 space-y-6",children:[a.jsxs("div",{children:[a.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Recursos da Marca"}),a.jsx("p",{className:"text-gray-600 mt-1",children:"Acesse arquivos e recursos disponibilizados pela marca"})]}),a.jsxs("div",{className:"relative max-w-md",children:[a.jsx(B,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}
1),a.jsx(M,{type:"text",placeholder:"Buscar recursos...",value:s,onChange:n=>E(n.target.value),className:"pl-10 pr-10"}),s&&a.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:I,className:"absolute right-1 top-1/2 transform -translate-y-1/2 h-7 w-7 p-0",children:a.jsx(O,{className:"h-4 w-4"})})]}),b&&a.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4",children:a.jsx("p",{className:"text-red-600",children:"Erro ao carregar recursos. Tente novamente."})}),a.jsx(W,{resources:r?.resources||[],onView:P,onDownload:C,isLoading:N}),r?.pagination&&r.pagination.totalPages>1&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("p",{className:"text-sm text-gray-600",children:["Página ",r.pagination.page," de ",r.pagination.totalPages," ","(",r.pagination.total," recursos disponÃveis)"]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs(g,{variant:"outline",size:"sm",onClick:z,disabled:r.pagination.page===1,children:[a.jsx(_,{className:"h-4 w-4 mr-1"}),"Anterior"]}),a.jsxs(g,{variant:"outline",size:"sm",onClick:D,disabled:r.pagination.page===r.pagination.totalPages,children:["Próxima",a.jsx(G,{className:"h-4 w-4 ml-1"})]})]})]}),a.jsx(k,{open:o,onOpenChange:m,resource:d})]})}export{me as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.