1import{j as e,u as ne}from"./vendor-query-skQMsM6X.js";import{r as o,u as We,L as ee}from"./vendor-react-DyYvSSk1.js";import{am as ke,an as Pe,ao as De,ap as Ee,ab as B,T as ue,aq as $,I as Y,p as g,r as U,v as H,x as K,y as Q,z as F,u as Ge,b as Ae,az as Ue,ai as se,aK as ae,a5 as I,a7 as L,aa as O,bn as He,a4 as Ke,aB as he,aC as ge,aD as pe,aE as je,aF as fe,aG as be,aH as ve,aI as Ne,b4 as te}from"./index-BGwtrXIa.js";import{R as Qe,f as Xe,g as Je,h as Ye,i as Ze,j as es,k as ss,n as as}from"./useBlogPosts-JkifSc8P.js";import{g as ts}from"./blogSubmitRules-Bec6GccW.js";import{u as rs,a as is}from"./useBlogMetadata-DgB0QdbH.js";import{_ as ns,F as Re,A as ls,b as Te,V as os,bi as oe,L as cs,k as ds,i as re,w as ms,ab as xs,a as ce,aJ as us,a7 as hs,bk as gs,bj as ps,r as js,ag as ye,Y as fs,t as le,o as Fe,c as bs,aR as Ce,m as vs,ca as Ns,u as ys,x as Cs,v as ws,c9 as _s}from"./vendor-ui-CCmu0bzQ.js";import{P as Ss}from"./progress-DewcR8Rb.js";import{u as ks}from"./useNFTPricingMode-o8vJF5yP.js";import{a as Ps,t as X,C as Ds,r as Es,g as As}from"./web3Wallets-DKU11ybA.js";import{useWeb3ChainConfig as Ie}from"./useWeb3ChainConfig-oZ-Z2Koq.js";import{y as Rs,k as Ts}from"./type-guards-C6mkCq0U.js";import{r as Fs}from"./bundler-BZOUbTQa.js";import"./vendor-supabase-BfoV2C50.js";import"./edgeFunctionClient-4dcAKx2Z.js";import"./errorTranslations-lTGRyFpS.js";import"./sessionTelemetry-X-Vnv8Qs.js";import"./utils-BnNtzvC2.js";import"./extends-CF3RwP-h.js";import"./decimals-AzlhcAmY.js";import"./TypedData-CVVqYjz9.js";import"./fuse-CcLD0YPK.js";import"./arweave-CAGvOb64.js";const Is=2,J=10;function Ls({open:a,onOpenChange:d,onCreatePost:x,isPending:r}){const[b,j]=o.useState(1),[i,c]=o.useState(null),[m,u]=o.useState(""),[w,p]=o.useState(""),[S,D]=o.useState(""),[z,v]=o.useState(""),[R,N]=o.useState(""),[_,k]=o.useState(""),[P,f]=o.useState(""),y=m.trim().length>=J,{data:E=[]}=rs(),{data:W=[]}=is(),C=i==="caso"?Qe:Xe,T=()=>{j(1),c(null),u(""),p(""),D(""),v(""),N(""),k(""),f("")},V=n=>{n||T(),d(n)},A=n=>{c(n)},G=()=>{if(!i||!y)return;const n=C.map(l=>({type:l.type,title:l.title,content:""})),M=z.split(",").map(l=>l.trim()).filter(Boolean);x({title:m.trim(),type:i,modality:w||void 0,body_region:S||void 0,tags:M.length>
10?M:void 0,patient_age:i==="caso"&&R||void 0,patient_gender:i==="caso"&&_||void 0,diagnostic_certainty:i==="caso"&&P||void 0,sections:n})};return e.jsx(ke,{open:a,onOpenChange:V,children:e.jsxs(Pe,{className:"sm:max-w-[600px] max-h-[85vh] overflow-y-auto",children:[e.jsx(De,{children:e.jsxs(Ee,{className:"flex items-center gap-2",children:["Nova Publicação",e.jsxs(B,{variant:"outline",className:"ml-auto text-xs font-normal",children:["Etapa ",b,"/",Is]})]})}),b===1&&e.jsxs("div",{className:"space-y-5 pt-2",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("button",{onClick:()=>A("caso"),className:ue("flex flex-col items-center gap-3 rounded-xl border-2 p-6 text-center transition-all hover:border-primary hover:bg-primary/5",i==="caso"?"border-primary bg-primary/5":"border-border bg-card"),children:[e.jsx(ns,{className:"h-10 w-10 text-primary"}),e.jsx("span",{className:"text-base font-semibold text-foreground",children:"Caso ClÃnico"}),e.jsx("span",{className:"text-xs text-muted-foreground leading-relaxed",children:"Apresente um caso real com imagens, achados e diagnóstico diferencial"})]}),e.jsxs("button",{onClick:()=>A("artigo"),className:ue("flex flex-col items-center gap-3 rounded-xl border-2 p-6 text-center transition-all hover:border-primary hover:bg-primary/5",i==="artigo"?"border-primary bg-primary/5":"border-border bg-card"),children:[e.jsx(Re,{className:"h-10 w-10 text-primary"}),e.jsx("span",{className:"text-base font-semibold text-foreground",children:"Artigo CientÃfico"}),e.jsx("span",{className:"text-xs text-muted-foreground leading-relaxed",children:"Escreva sobre um tema com introdução, revisão e conclusões"})]})]}),i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"TÃtulo *"}),e.jsx(Y,{value:m,onChange:n=>u(n.target.value),onKeyDown:n=>{n.key==="Enter"&&y&&j(2)},placeholder:"Ex: Nódulo hepático com realce arterial em TC",autoFocus:!0,"aria-invalid":m.trim().length>0&&!y}),e.jsx("p",{className:`text-xs ${m.trim().length>0&&!y?"text-destructive":"text-muted-foreground"}`,children:m.trim().length>0&&!y?`Use um tÃtulo descritivo com pelo menos ${J} caracteres (${m.trim().length}/${J}).`:`MÃnimo de ${J} caracteres. As seções obrigatórias de ${i==="caso"?"caso clÃnico":"artigo"} já vêm prontas â as opcionais você adiciona dentro do editor.`})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsxs(g,{onClick:()=>j(2),disabled:!i||!y,children:["Próximo ",e.jsx(ls,{className:"h-4 w-4 ml-1"})]})})]}),b===2&&i&&e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Modalidade"}),e.jsxs(U,{value:w,onValueChange:p,children:[e.jsx(H,{children:e.jsx(K,{placeholder:"Selecione..."})}),e.jsx(Q,{children:E.map(n=>e.jsxs(F,{value:n.codigo,children:[n.codigo," â ",n.nome]},n.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Região Anatômica"}),e.jsxs(U,{value:S,onValueChange:D,children:[e.jsx(H,{children:e.jsx(K,{placeholder:"Selecione..."})}),e.jsx(Q,{children:W.map(n=>e.jsx(F,{value:n.nome,children:n.nome},n.id))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Palavras-chave (separadas por vÃrgula)"}),e.jsx(Y,{value:z,onChange:n=>v(n.target.value),placeholder:"Ex: fÃgado, hepatocarcinoma, LI-RADS"})]}),i==="caso"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Sexo do Paciente"}),e.jsxs(U,{value:_,onValueChange:k,children:[e.jsx(H,{children:e.jsx(K,{placeholder:"Selecione..."})}),e.jsxs(Q,{children:[e.jsx(F,{value:"M",children:"Masculino"}),e.jsx(F,{value:"F",children:"Feminino"}),e.jsx(F,{value:"NI",children:"Não informado"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Idade do Paciente"}),e.jsx(Y,{value:R,onChange:n=>N(n.target.value),placeholder:"Ex: 55 anos, neonato"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($,{children:"Certeza Diagnóstica"}),e.jsxs(U,{value:P,onValueChange:f,children:[e.jsx(H,{children:e.jsx(K,{placeholder:"Selecione..."})}),e.jsxs(Q,{children:[e.jsx(F,{value:"confirmed",children:"Confirmado"}),e.jsx(F,{value:"almost_certain",children:"Quase certo"}),e.jsx(F,{value:"probable",children:"Provável"})]})]})]})]}),e.jsxs("div",{className:"flex justify-between pt-2",children:[e.jsxs(g,{variant:"ghost",onClick:()=>j(1),children:[e.jsx(Te,{className:"h-4 w-4 mr-1"})," Voltar"]}),e.jsxs(g,{onClick:G,disabled:r||!y,children:[e.jsx(os,{className:"h-4 w-4 mr-1"})," Criar Rascunho"]})]})]})]})})}const we=new Set(["da","de","do","dos","das","e"]);function Os(a){if(!(a!=null&&a.trim()))return"Anônimo";const d=a.trim().split(/\s+/);if(d.length===1)return d[0];let x=d.length-1;for(;x>1&&we.has(d[x-1].toLowerCase());)x--;
1const r=d.slice(0,x),b=d.slice(x).join(" ");if(r.length===0)return b;const j=r.filter(i=>!we.has(i.toLowerCase())).map(i=>i.charAt(0).toUpperCase()).join("");return`${b} ${j}`}function $s(a,d=200){return a?a.length<=d?a:a.slice(0,d).trimEnd()+"â¦":""}const Bs={idle:"",publishing:"1/2 â Debitando RADC e enviando metadados ao IPFS...",confirming:"2/2 â Aguardando confirmação on-chain...",done:"Publicado com sucesso!",error:"Falha na publicação"},zs={idle:0,publishing:40,confirming:75,done:100,error:0},Vs=({open:a,onOpenChange:d,onConfirm:x,mintStep:r,mintError:b,onResetMint:j,radcCost:i,post:c})=>{const{user:m}=Ge(),{isOnChain:u,radcContractAddress:w}=ks(),p=Rs(),{defaultChain:S,defaultChainId:D}=Ie(),{handleConnect:z}=Ps(),[v,R]=o.useState({modality:!0,body_region:!0}),[N,_]=o.useState(!1),k=!!(p!=null&&p.address),P=r==="publishing"||r==="confirming",f=r==="done";o.useEffect(()=>{a&&(_(!1),R({modality:!0,body_region:!0}),j())},[a,j]),o.useEffect(()=>{if(f){const l=setTimeout(()=>d(!1),2500);return()=>clearTimeout(l)}},[f,d]);const{data:y}=ne({queryKey:["ai-credits",m==null?void 0:m.id],queryFn:async()=>{if(!(m!=null&&m.id))return 0;const{data:l}=await Ae.from("user_ai_balance").select("balance").eq("user_id",m.id).single();return(l==null?void 0:l.balance)??0},enabled:a&&!!(m!=null&&m.id)&&!u}),{data:E=0,isLoading:W}=ne({queryKey:["radc-balance",p==null?void 0:p.address,w],queryFn:async()=>{if(!(p!=null&&p.address)||!X||!w)return 0;const l=Ts({client:X,chain:S,address:w}),q=await Fs({contract:l,method:"function balanceOf(address account) view returns (uint256)",params:[p.address]});return Number(q)/1e18},enabled:a&&u&&k&&!!w,staleTime:15e3}),C=u?E:y,T=C!=null&&C>=i,V=l=>{R(q=>({...q,[l]:!q[l]}))},A=Os(c.author_name),G=$s(c.summary,200),n=[{label:"Tipo",value:c.type==="caso"?"Caso ClÃnico":"Artigo CientÃfico"},{label:"Autor",value:A},{label:"Data Publicação",value:new Date().toLocaleDateString("pt-BR")},{label:"DOI Blockchain",value:"radreport:..."},...v.modality&&c.modality?[{label:"Modalidade",value:c.modality}]:[],...v.body_region&&c.body_region?[{label:"Região",value:c.body_region}]:[]],M=N&&T&&!P&&!f&&r!=="error"&&(u?k:!0);return e.jsx(ke,{open:a,onOpenChange:P?void 0:l=>{l||(_(!1),R({modality:!0,body_region:!0})),d(l)},children:e.jsxs(Pe,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsxs(De,{children:[e.jsxs(Ee,{className:"flex items-center gap-2 text-base",children:[e.jsx(oe,{className:"h-5 w-5 text-primary"}),"Publicar na Blockchain",e.jsx(B,{variant:u?"default":"secondary",className:"text-[9px] px-1.5 py-0 ml-1",children:u?"ON-CHAIN":"OFF-CHAIN"})]}),e.jsx(Ue,{className:"text-xs text-muted-foreground",children:"Seu artigo será registrado como um NFT ERC-721 único na blockchain"})]}),P&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ss,{value:zs[r],className:"h-2"}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-primary",children:[e.jsx(cs,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:Bs[r]})]})]}),f&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-primary text-sm font-medium py-4",children:[e.jsx(ds,{size:18}),e.jsx("span",{children:"Artigo publicado na blockchain com sucesso!"})]}),r==="error"&&e.jsxs("div",{className:"text-center space-y-3 py-2",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg p-3 bg-destructive/10 border border-destructive/20",children:[e.jsx(re,{className:"h-4 w-4 text-destructive shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-destructive text-left",children:b||"Erro desconhecido. Tente novamente."})]}),e.jsx("button",{onClick:j,className:"text-xs text-muted-foreground underline hover:text-foreground",children:"Tentar novamente"})]}),r==="idle"&&e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg p-3 bg-yellow-500/10 border border-yellow-500/20",children:[e.jsx(re,{className:"h-4 w-4 text-yellow-600 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs text-yellow-700 dark:text-yellow-400 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Registro permanente e irreversÃvel"}),e.jsx("p",{children:"Após a confirmação on-chain, os metadados não podem ser alterados, excluÃdos ou remov
1idos."})]})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-lg p-3 bg-blue-500/10 border border-blue-500/20",children:[e.jsx(ms,{className:"h-4 w-4 text-blue-600 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs text-blue-700 dark:text-blue-400 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Armazenamento IPFS"}),e.jsx("p",{children:"Metadados armazenados no IPFS. Em caso de LGPD Art. 18, o conteúdo pode ser despublicado (unpin), mas o hash permanece na blockchain."})]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Re,{className:"h-4 w-4 mt-0.5 text-muted-foreground shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:c.title}),e.jsx(B,{variant:"outline",className:"text-xs mt-1",children:c.type==="caso"?"Caso ClÃnico":"Artigo CientÃfico"})]})]}),c.author_name&&e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(xs,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:c.author_name}),e.jsxs("span",{className:"text-xs text-muted-foreground/60",children:["â Vancouver: ",e.jsx("strong",{className:"text-foreground",children:A})]})]})]}),e.jsx(se,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"font-medium text-foreground text-xs flex items-center gap-1.5",children:[e.jsx(ce,{className:"h-3.5 w-3.5"})," Dados opcionais on-chain"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"TÃtulo, autor, resumo, tipo e data são obrigatórios. Selecione os adicionais:"}),e.jsxs("div",{className:"space-y-2 pl-1",children:[c.modality&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-xs",children:[e.jsx(ae,{checked:v.modality,onCheckedChange:()=>V("modality")}),e.jsxs("span",{children:["Modalidade: ",e.jsx("span",{className:"font-medium text-foreground",children:c.modality})]})]}),c.body_region&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-xs",children:[e.jsx(ae,{checked:v.body_region,onCheckedChange:()=>V("body_region")}),e.jsxs("span",{children:["Região Anatômica: ",e.jsx("span",{className:"font-medium text-foreground",children:c.body_region})]})]})]})]}),e.jsx(se,{}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-foreground text-xs",children:"Preview dos metadados"}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-2.5 space-y-1 font-mono text-[11px]",children:[e.jsxs("p",{className:"text-muted-foreground",children:["name: ",e.jsxs("span",{className:"text-foreground",children:["RadReport: ",c.title]})]}),e.jsxs("p",{className:"text-muted-foreground",children:["description: ",e.jsx("span",{className:"text-foreground",children:G||"â"})]}),n.map(l=>e.jsxs("p",{className:"text-muted-foreground",children:[l.label,": ",e.jsx("span",{className:"text-foreground",children:l.value})]},l.label))]})]}),e.jsxs("div",{className:"flex items-center justify-between bg-primary/5 rounded-lg p-3 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(us,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-foreground",children:"Custo"})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("span",{className:"font-bold text-primary",children:[i," RADC"]}),u&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Débito off-chain (Server Wallet faz o mint)"})]})]}),C!=null&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg p-3 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(hs,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-foreground",children:["Seu saldo ",u?"(on-chain)":"(off-chain)"]})]}),e.jsxs("span",{className:`font-bold ${T?"text-emerald-600":"text-destructive"}`,children:[W?"...":C," RADC"]})]}),u&&!k&&e.jsxs("div",{className:"flex flex-col gap-2.5 rounded-lg p-3 bg-destructive/10 border border-destructive/20",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-destructive shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-destructive font-medium",children:"Wallet não conectada. Conecte para publicar."})]}),X&&e.jsx(Ds,{client:X,wallets:Es,chain:S,supportedTokens:As(D,w),onConnect:z,connectButton:{label:"Conectar Wallet",style:{width:"100%",height:"32px",fontSize:"12px",fontWeight:600}},theme:"dark"})]}),!T&&C!=null&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-xs text-destructive font-medium",children:["Saldo insuficiente. Você precisa de mais ",Math.ceil(i-(C||0))," RADC."]}),e.jsx("a",{href:"/web3",className:"inline-flex items-center gap-1.5 text-xs text-primary hover:underline font-medium",children:u?e.jsxs(e.Fragment,{children:[e.jsx(gs,{className:"h-3 w-3"})," Depositar créditos"]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-3 w-3"})," Gerenciar créditos RADC"]})})]}),e.jsx(se,{}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx(ae,{checked:N,onCheckedChange:l=>_(l===!0),className:"mt-0.5"}),e.jsxs("span",{className:"text-xs text-muted-foreground leading-relaxed",children:[e.jsx(js,{className:"h-3 w-3 inline mr-1"}),"Declaro estar ciente de que os dados selecionados serão registrados ",e.jsx("strong",{className:"text-foreground",children:"permanentemente na blockchain e IPFS"}),". O nome será gravado no formato Vancouver (",A,"). O hash on-chain é irreversÃvel."]})]})]}),!f&&r!=="error"&&r==="idle"&&e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(g,{variant:"outline",size:"sm",className:"flex-1 h-9 text-xs",onClick:()=>d(!1),children:"Cancelar"}),e.jsx(g,{size:"sm",className:"flex-1 h-9 text-xs font-bold",disabled:!M,onClick:()=>x(v),children:u?`Confirmar Publicação (${i} RADC)`:`Publicar (${i} RADC)`})]})]})})}
1,Ms=({txHash:a,chainId:d,explorerUrl:x})=>{const{getExplorer:r,defaultChainId:b}=Ie(),i=`${x||r(d??b)}/tx/${a}`,c=`${a.slice(0,6)}â¦${a.slice(-4)}`;return e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",children:e.jsxs(B,{className:"bg-emerald-500/15 text-emerald-600 hover:bg-emerald-500/25 cursor-pointer gap-1 transition-colors",children:[e.jsx(oe,{className:"h-3 w-3"}),"On-Chain"]})})}),e.jsxs(O,{children:[e.jsxs("p",{className:"text-xs",children:["TX: ",c]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Clique para ver no explorador"})]})]})},_e={draft:{label:"Rascunho",icon:le,color:"bg-muted text-muted-foreground"},pending_review:{label:"Em Revisão",icon:Fe,color:"bg-yellow-500/20 text-yellow-600"},approved:{label:"Aprovado",icon:Cs,color:"bg-green-500/20 text-green-600"},published:{label:"Publicado",icon:ce,color:"bg-primary/20 text-primary"},rejected:{label:"Rejeitado",icon:ws,color:"bg-destructive/20 text-destructive"},paused:{label:"Pausado",icon:_s,color:"bg-orange-500/20 text-orange-600"}},qs={pending_review:"O post será retirado da fila de revisão e voltará como rascunho.",approved:"O post perderá a aprovação e voltará como rascunho.",published:"O post será despublicado e voltará como rascunho. Ele não ficará mais visÃvel no blog.",nft_minted:"Este artigo já foi publicado e registrado permanentemente. Edições no site NÃO alteram o registro original."};function Se(a,d){return ts({type:a.type,title:a.title,summary:a.summary,sections:Array.isArray(a.content_sections)?a.content_sections:[],hasImages:d,imageConsent:a.image_consent}).map(x=>({label:x.label,step:x.step}))}const ie=[{id:"todos",label:"Todas",match:()=>!0},{id:"rascunhos",label:"Rascunhos",match:a=>a==="draft"||a==="rejected"},{id:"revisao",label:"Em revisão",match:a=>a==="pending_review"},{id:"publicados",label:"Publicados",match:a=>a==="published"||a==="approved"}],ua=({nftActions:a,web3Available:d=!1})=>{const x=We(),{data:r=[],isLoading:b}=Je(),j=Ye(),i=Ze(),c=es(),m=ss(),[u,w]=o.useState(null),[p,S]=o.useState(!1),[D,z]=o.useState("todos"),[v,R]=o.useState(""),[N,_]=o.useState(null),[k,P]=o.useState(null),[f,y]=o.useState(null),{enabled:E}=He(),W=E&&d&&!!(a!=null&&a.isEnabled),C=o.useMemo(()=>r.filter(s=>s.status==="draft"||s.status==="rejected").map(s=>s.id),[r]),{data:T=new Set}=ne({queryKey:["blog-my-posts-with-images",C],enabled:C.length>0,staleTime:6e4,queryFn:async()=>{const{data:s,error:t}=await Ae.from("blog_post_images").select("post_id").in("post_id",C);if(t)throw t;return new Set((s||[]).map(h=>h.post_id))}}),[V,A]=o.useState(null),[G,n]=o.useState(!1),M=async s=>{const t=await j.mutateAsync({title:s.title,type:s.type,modality:s.modality,body_region:s.body_region,tags:s.tags,patient_age:s.patient_age,patient_gender:s.patient_gender,diagnostic_certainty:s.diagnostic_certainty,sections:s.sections});S(!1),t!=null&&t.id&&x(`/editor/diario/${t.id}/edit`)},l=(s,t,h)=>{h?_({id:s,status:"nft_minted"}):t==="draft"||t==="rejected"?x(`/editor/diario/${s}/edit`):_({id:s,status:t})},q=async s=>{const t=Se(s,T.has(s.id));if(t.length>0){te({title:`Falta ajustar: ${t[0].label}`,description:"Abrimos a etapa correspondente para você completar.",variant:"destructive"}),x(`/editor/diario/${s.id}/edit?step=${t[0].step}`);return}const h=await c.mutateAsync(s.id).catch(()=>null);A(h&&h.adminNotified===!1?s.id:null)},Le=async s=>{n(!0);const t=await as({id:s.id,full_name:s.author_name??null,type:s.type,title:s.title,slug:s.slug,modality:s.modality,body_region:s.body_region});n(!1),t?(A(null),te({title:"Equipe editorial avisada."})):te({title:"Ainda não foi possÃvel avisar",description:"Sua publicação continua na fila de revisão.",variant:"destructive"})},Oe=async()=>{N&&(await m.mutateAsync(N.id),_(null),x(`/editor/diario/${N.id}/edit`))},de=o.useMemo(()=>{const s={};for(const t of ie)s[t.id]=r.filter(h=>t.match(h.status)).length;return s},[r]),me=o.useMemo(()=>{const s=ie.find(h=>h.id===D),t=v.trim().toLowerCase();return r.filter(h=>s.match(h.status)).filter(h=>!t||h.title.toLowerCase().includes(t))},[r,D,v]),$e=s=>s!=="paused",Be=(s,t)=>!t&&["draft","pending_review","rejected"].includes(s),ze=s=>["draft","rejected"].includes(s),Ve=s=>s==="pending_review",Me=s=>s==="published",qe=typeof window<"u"?new URLSearchParams(window.location.search).get("enviado"):null;return e.jsx(Ke,{delayDuration:300,children:e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs("header",{className:"border-b border-border bg-card/50 backdrop-blur-sm sticky top-0 z-10",children:[e.jsxs("div",{className:"max-w-5xl mx-auto px-4 py-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(g,{variant:"ghost",size:"sm",asChild:!0,className:"min-h-[44px]",children:e.jsx(ee,{to:"/editor","aria-label":"Voltar para o editor",children:e.jsx(Te,{className:"h-4 w-4"})})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-foreground leading-tight",children:"Minhas Publicações"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.length===0?"Nenhuma publicação ainda":`${r.length} no total · ${de.rascunhos} em rascunho`})]})]}),e.jsxs(g,{onClick:()=>S(!0),className:"min-h-[44px]",children:[e.jsx(ye,{className:"h-4 w-4 mr-2"})," Nova Publicação"]}
1),e.jsx(Ls,{open:p,onOpenChange:S,onCreatePost:M,isPending:j.isPending})]}),r.length>0&&e.jsxs("div",{className:"max-w-5xl mx-auto px-4 pb-3 flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:ie.map(s=>e.jsxs("button",{type:"button",onClick:()=>z(s.id),"aria-current":D===s.id?"true":void 0,className:`min-h-[36px] rounded-md px-3 text-xs font-medium transition-colors ${D===s.id?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[s.label," ",e.jsx("span",{className:"tabular-nums opacity-70",children:de[s.id]})]},s.id))}),e.jsxs("div",{className:"relative ml-auto w-full sm:w-56",children:[e.jsx(fs,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Y,{value:v,onChange:s=>R(s.target.value),placeholder:"Buscar por tÃtulo...",className:"pl-8 h-9 text-sm","aria-label":"Buscar publicação"})]})]})]}),e.jsxs("main",{className:"max-w-5xl mx-auto px-4 py-6 space-y-4",children:[qe&&e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-4",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Publicação enviada para revisão"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"A equipe editorial confere formatação, seções e anonimização. Depois disso ela é publicada ou devolvida com feedback â você acompanha o status por aqui."})]}),b?e.jsx("div",{className:"text-center py-16 text-muted-foreground",children:"Carregando..."}):r.length===0?e.jsxs("div",{className:"text-center py-16 space-y-3",children:[e.jsx(le,{className:"h-12 w-12 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-muted-foreground",children:"Você ainda não tem publicações."}),e.jsxs(g,{onClick:()=>S(!0),className:"min-h-[44px]",children:[e.jsx(ye,{className:"h-4 w-4 mr-2"})," Criar minha primeira publicação"]})]}):me.length===0?e.jsx("div",{className:"text-center py-16 text-muted-foreground text-sm",children:"Nenhuma publicação neste filtro."}):me.map(s=>{const t=_e[s.status]||_e.draft,h=t.icon,xe=s.status==="draft"||s.status==="rejected"?Se(s,T.has(s.id)):[];return e.jsxs("div",{className:"border border-border rounded-lg p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3 bg-card",children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{className:t.color,children:[e.jsx(h,{className:"h-3 w-3 mr-1"}),t.label]}),e.jsx(B,{variant:"outline",className:"text-xs",children:s.type==="caso"?"Caso":"Artigo"}),E&&s.nft_tx_hash&&e.jsx(Ms,{txHash:s.nft_tx_hash,chainId:s.nft_chain_id}),E&&!s.nft_tx_hash&&s.nft_minted_at&&e.jsxs(B,{className:"bg-yellow-500/15 text-yellow-600 gap-1 animate-pulse",children:[e.jsx(Fe,{className:"h-3 w-3"})," Processando registro"]})]}),e.jsx("h3",{className:"font-medium text-foreground truncate",children:s.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Atualizado em ",new Date(s.updated_at).toLocaleDateString("pt-BR")]}),xe.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[e.jsx(bs,{className:"h-3.5 w-3.5 text-muted-foreground","aria-hidden":!0}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Falta:"}),xe.map(Z=>e.jsx(ee,{to:`/editor/diario/${s.id}/edit?step=${Z.step}`,className:"text-[11px] underline underline-offset-2 text-muted-foreground hover:text-foreground",children:Z.label},Z.label))]}),V===s.id&&s.status==="pending_review"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Não conseguimos avisar a equipe editorial."}),e.jsxs(g,{size:"sm",variant:"outline",className:"h-7 text-[11px]",disabled:G,onClick:()=>Le(s),children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"})," Reenviar aviso"]})]}),s.status==="rejected"&&s.admin_notes&&e.jsxs("p",{className:"text-xs text-destructive",children:["Feedback: ",s.admin_notes]}),s.status==="paused"&&s.admin_notes&&e.jsxs("p",{className:"text-xs text-orange-600",children:["Motivo: ",s.admin_notes]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 flex-wrap",children:[$e(s.status)&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsxs(g,{size:"sm",variant:"outline",className:"min-h-[40px]",onClick:()=>l(s.id,s.status,!!s.nft_tx_hash),children:[e.jsx(le,{className:"h-3.5 w-3.5 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:s.status==="draft"||s.status==="rejected"?"Continuar":"Editar"})]})}),e.jsx(O,{children:"Editar"})]}),ze(s.status)&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsxs(g,{size:"sm",variant:"outline",className:"min-h-[40px]",onClick:()=>q(s),disabled:c.isPending,children:[e.jsx(vs,{className:"h-3.5 w-3.5 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Enviar"})]})}),e.jsx(O,{children:"Enviar para revisão"})]}),Ve(s.status)&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsx(g,{size:"sm",variant:"outline",onClick:()=>m.mutate(s.id),disabled:m.isPending,children:e.jsx(Ns,{className:"h-3.5 w-3.5"})})}),e.jsx(O,{children:"Retirar de revisão"})]}),Me(s.status)&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsx(g,{size:"sm",variant:"outline",asChild:!0,children:e.jsxs(ee,{to:`/diario/${s.slug}`,className:"min-h-[40px]",children:[e.jsx(ce,{className:"h-3.5 w-3.5 sm:mr-1.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Ver"})]})})}),e.jsx(O,{children:"Ver no diário"})]}),a&&s.status==="published"&&!s.nft_tx_hash&&!s.nft_minted_at&&W&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsx(g,{size:"sm",variant:"outline",onClick:()=>y({id:s.id,title:s.title,type:s.type,author_name:s.author_name,modality:s.modality,body_region:s.body_region,author_crm:s.author_crm,summary:s.summary,slug:s.slug}),children:e.jsx(oe,{className:"h-3.5 w-3.5"})})}),e.jsx(O,{children:"Publicar com registro permanente"})]}),E&&a&&!s.nft_tx_hash&&s.nft_minted_at&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsx(g,{size:"sm",variant:"outline",disabled:u===s.id,onClick:async()=>
1{w(s.id),await a.checkArticleStatus(s.id),w(null)},children:e.jsx(Ce,{className:`h-3.5 w-3.5 ${u===s.id?"animate-spin":""}`})})}),e.jsx(O,{children:"Verificar status do registro"})]}),Be(s.status,s.nft_tx_hash)&&e.jsxs(I,{children:[e.jsx(L,{asChild:!0,children:e.jsx(g,{size:"sm",variant:"ghost",className:"text-destructive",onClick:()=>P(s.id),children:e.jsx(ys,{className:"h-3.5 w-3.5"})})}),e.jsx(O,{children:"Deletar"})]})]})]},s.id)})]}),e.jsx(he,{open:!!N,onOpenChange:s=>!s&&_(null),children:e.jsxs(ge,{children:[e.jsxs(pe,{children:[e.jsx(je,{children:"Editar publicação?"}),e.jsxs(fe,{children:[N&&qs[N.status]||""," ","Você poderá reenviá-lo para revisão após as alterações."]})]}),e.jsxs(be,{children:[e.jsx(ve,{children:"Cancelar"}),e.jsx(Ne,{onClick:Oe,disabled:m.isPending,children:"Editar mesmo assim"})]})]})}),e.jsx(he,{open:!!k,onOpenChange:s=>!s&&P(null),children:e.jsxs(ge,{children:[e.jsxs(pe,{children:[e.jsx(je,{children:"Deletar publicação permanentemente?"}),e.jsx(fe,{children:"Esta ação é irreversÃvel. O post, todas as imagens associadas e dados serão permanentemente removidos."})]}),e.jsxs(be,{children:[e.jsx(ve,{children:"Cancelar"}),e.jsx(Ne,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{k&&(i.mutate(k),P(null))},disabled:i.isPending,children:"Deletar permanentemente"})]})]})}),E&&d&&a&&f&&e.jsx(Vs,{open:!!f,onOpenChange:s=>!s&&y(null),onConfirm:async s=>{await a.mintArticleNFT(f.id,s)},mintStep:a.mintStep,mintError:a.mintError,onResetMint:a.resetMintState,radcCost:a.config.radc_cost,post:f})]})})};export{ua as BlogMyPostsView};
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.