1import{by as le,u as V,r as l,aj as L,al as oe,s as j,j as a,z,aF as re,R as ne,aD as de,aH as ce,aG as me,cf as ue,y as xe,cg as pe,m as U,t as B,o as fe,c0 as H,aA as he,aB as ge,aC as be,a_ as ye,a$ as ve,aK as je,ch as _e,aM as we,aL as Ne,b2 as Se,a as Ce,ci as ke,a0 as Te}from"./index-D4q9XhjX.js";import{I as Ee}from"./inbox-CiS4yMR3.js";const C=e=>/\.(mp4|mov|webm|ogg|mkv)(\?|$)/i.test(e||""),G={saude:{label:"Saúde",emoji:"ð"},familia:{label:"FamÃlia",emoji:"ð¨âð©âð§âð¦"},trabalho:{label:"Trabalho",emoji:"ð¼"},financas:{label:"Finanças",emoji:"ð°"},espiritual:{label:"Vida Espiritual",emoji:"â¨"},nacao:{label:"Nação",emoji:"ð§ð·"},outro:{label:"Outro",emoji:"ð"}};function Ie({request:e,me:t,myProfile:p,onUpdate:r,onDelete:o}){const{toast:d}=le(),c=V(),[y,u]=l.useState(!1),[N,v]=l.useState(!1),[f,h]=l.useState(0),[s,g]=l.useState(!1),[x,m]=l.useState(()=>{const i=_e();return i?i.has(e.id):!1}),[_,w]=l.useState(!1),[Y,I]=l.useState(!1),[P,T]=l.useState(0),[R,$]=l.useState(null),[O,M]=l.useState(!1);C(e.video_url)||(e.media_urls||[]).some(i=>C(i));const[E,K]=l.useState(0),{text:J,isTranslated:W}=L(e.title||"",{source_type:"prayer",source_id:e.id}),{text:Z,isTranslated:Q}=L(e.content||"",{source_type:"prayer",source_id:e.id});l.useEffect(()=>{const i=Array.isArray(e.praying_by)?e.praying_by:[];h(i.length),t&&u(i.includes(t.id))},[e,t]),l.useEffect(()=>{t&&oe(e.id).then(m)},[t,e.id]),l.useEffect(()=>{let i=!0;j.entities.Comment.filter({target_id:e.id,target_type:"prayer"}).then(b=>{i&&T(b.length)}).catch(()=>{});const n=j.entities.Comment.subscribe(()=>{j.entities.Comment.filter({target_id:e.id,target_type:"prayer"}).then(b=>{i&&T(b.length)}).catch(()=>{})});return()=>{i=!1,n&&n()}},[e.id]);const X=async i=>{if(i==null||i.stopPropagation(),!t){c("/login");return}v(!0);try{const n=await j.functions.invoke("togglePrayerRequest",{request_id:e.id});n!=null&&n.success&&(u(n.praying),h(n.count),n.praying&&(g(!0),setTimeout(()=>g(!1),1e3)),r==null||r(e.id,{praying_by:n.praying?[...e.praying_by||[],t.id]:(e.praying_by||[]).filter(b=>b!==t.id),praying_count:n.count}))}catch(n){d({title:"Erro",description:n.message,variant:"destructive"})}finally{v(!1)}},D=async()=>{if(!t)return;const i=await we({targetId:e.id,targetType:"prayer",category:"oracoes",meId:t.id});m(i)},q=async()=>{try{await j.entities.PrayerRequest.update(e.id,{status:"removed"}),o==null||o(e.id),d({title:"Pedido removido"})}catch{d({title:"Erro ao remover",variant:"destructive"})}},ee=async()=>{const n=(e.media_urls||[])[E]||e.video_url||e.image_url;if(!n||_)return;const b=C(n);w(!0);try{await Ne(n,{isVideo:b,filename:`godby_oracao_${e.id}_${E+1}`,onStatus:S=>{S==="processing"&&d({title:b?"Baixando...":"Adicionando logo GODBY..."})}})}catch{d({title:"Erro ao baixar",variant:"destructive"})}finally{w(!1)}},ae=()=>{var S;const i=e.media_urls||[],n=i[0]||e.video_url||e.image_url||"",b=i.find(ie=>!/\.(mp4|mov|webm|ogg)(\?|$)/i.test(ie))||e.image_url||"";$({kind:"prayer",id:e.id,title:e.title||((S=e.content)==null?void 0:S.slice(0,60))||"Pedido de Oração",thumb:b,author:e.author_name,authorUsername:e.author_username,authorPhoto:e.author_photo,media:n,url:`${Se}/functions/sharePreview?type=prayer&id=${e.id}`,onCountShare:()=>{}})},te=i=>T(Math.max(0,i)),se=t&&e.author_id===t.id,A=G[e.category]||G.outro,F=e.privacy==="specific"||Array.isArray(e.allowed_viewers)&&e.allowed_viewers.length>0;return a.jsxs("article",{className:"rounded-3xl bg-card border border-border/60 overflow-hidden",children:[a.jsxs("div",{className:"flex items-center gap-3 p-4",children:[a.jsx("button",{type:"button",onClick:()=>c(`/perfil/${e.author_id}`),className:"flex-shrink-0 active:opacity-80 transition-opacity",children:a.jsx(z,{src:e.author_photo,name:e.author_name,className:"w-11 h-11 rounded-full"})}),a.jsxs("button",{type:"button",onClick:()=>c(`/perfil/${e.author_id}`),className:"flex-1 min-w-0 text-left active:opacity-80 transition-opacity",children:[a.jsx("span",{className:"font-semibold text-sm truncate block",children:e.author_name}),a.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:["@",e.author_username||"godby"," · ",a.jsx(re,{date:e.created_date})]})]}),a.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-violet-500/10 text-violet-600 dar
1k:text-violet-400 text-[10px] font-medium shrink-0",children:[A.emoji," ",A.label]}),F&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full bg-amber-500/10 text-amber-600 dark:text-amber-400 text-[10px] font-medium shrink-0",title:"VisÃvel apenas para contas especÃficas â não pode ser repostado",children:[a.jsx(ne,{className:"w-3 h-3"})," Privado"]}),a.jsx(de,{target:e,targetType:"prayer",me:t,profile:p,onDelete:se||(t==null?void 0:t.role)==="admin"?q:void 0,onSave:D,saved:x,onDownload:e.video_url||e.image_url||(e.media_urls||[]).length>0?ee:void 0,downloadLabel:C((e.media_urls||[])[E]||e.video_url||"")?"Baixar vÃdeo":"Baixar imagem"})]}),a.jsxs("div",{className:"px-4 pb-3",children:[e.title&&a.jsx("h3",{className:"text-base font-bold leading-tight mb-1",children:J}),a.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap break-words",children:a.jsx(ce,{text:Z})}),(W||Q)&&a.jsxs("p",{className:"flex items-center gap-1 mt-1 text-[10px] text-muted-foreground/60 font-medium",children:[a.jsx(me,{className:"w-2.5 h-2.5"})," Traduzido automaticamente"]})]}),(e.media_urls||[]).length>0?a.jsx("div",{className:"pb-3",children:a.jsx(ue,{mediaUrls:e.media_urls,thumbnailUrls:e.thumbnail_urls||[],isVideoFn:i=>/\.(mp4|mov|webm|ogg)(\?|$)/i.test(i),onIndexChange:K})}):a.jsxs(a.Fragment,{children:[e.image_url&&a.jsx("div",{className:"px-4 pb-3",children:a.jsx("div",{className:"rounded-2xl overflow-hidden",children:a.jsx(xe,{src:e.image_url,alt:"",className:"w-full",fittingType:"fill"})})}),e.video_url&&a.jsx("div",{className:"px-4 pb-3",children:a.jsx("div",{className:"rounded-2xl overflow-hidden",children:a.jsx(pe,{src:e.video_url})})})]}),a.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-3 border-t border-border/40",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(U.button,{onClick:X,disabled:N,whileTap:{scale:.97},className:`flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-semibold transition-all disabled:opacity-50 ${y?"bg-emerald-600 text-white":"bg-violet-500/10 text-violet-600 dark:text-violet-400"}`,children:N?a.jsx(B,{className:"w-4 h-4 animate-spin"}):y?a.jsxs(a.Fragment,{children:[a.jsx(fe,{className:"w-4 h-4"})," Estou orando"]}):a.jsxs(a.Fragment,{children:[a.jsx(U.span,{animate:s?{scale:[1,1.4,1]}:{},transition:{duration:.6},children:a.jsx(H,{className:"w-4 h-4"})}),"Estou orando"]})}),f>0&&a.jsx("span",{className:"text-xs text-muted-foreground",children:f===1?"1 orando":`${f.toLocaleString("pt-BR")} orando`})]}),a.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[a.jsxs("button",{onClick:()=>I(!0),className:"relative p-2 rounded-full hover:bg-accent flex-shrink-0 active:scale-95 transition-transform",children:[a.jsx(he,{className:"w-5 h-5 text-muted-foreground"}),P>0&&a.jsx("span",{className:"absolute -top-0.5 -right-0.5 text-[10px] font-bold text-primary bg-primary/10 rounded-full px-1.5 leading-tight",children:P})]}),a.jsx("button",{onClick:ae,className:"p-2 rounded-full hover:bg-accent flex-shrink-0 active:scale-95 transition-transform",children:a.jsx(ge,{className:"w-5 h-5 text-muted-foreground"})}),!F&&a.jsx("button",{onClick:()=>M(!0),className:"p-2 rounded-full hover:bg-accent flex-shrink-0 active:scale-95 transition-transform",children:a.jsx(be,{className:"w-5 h-5 text-muted-foreground"})})]})]}),Y&&a.jsx(ye,{targetId:e.id,targetType:"prayer",me:t,profile:p,authorId:e.author_id,onClose:()=>I(!1),onCountChange:te,caption:e.title?`${e.title} 2${e.content}`:e.content}),R&&a.jsx(ve,{item:R,me:t,profile:p,onClose:()=>$(null)}),O&&a.jsx(je,{open:O,onClose:()=>M(!1),original:e,originalType:"prayer",me:t,profile:p})]})}const k=100;async function Pe(e,t="-created_date",p={},{onBatch:r,onDone:o}={}){const d=j.entities[e];if(!d)return o==null||o(),[];try{const c=await d.filter(p,t,k,0);if(r==null||r(c),c.length<k)return o==null||o(),c;let y=c.length;return(async()=>{for(;;)try{const u=await d.filter(p,t,k,y);if(u.length===0||(r==null||r(u),y+=u.length,u.length<k))break}catch{break}o==null||o()})(),c}catch{return o==null||o(),[]}}function Re(e,t="-created_date",p={}){const[r,o]=l.useState([]),[d,c]=l.useState(!0),[y,u]=l.useState(!1),N=JSON.stringify(p),v=l.useCallback(async()=>{c(!0),u(!1),o([]),await Pe(e,t,p,{onBatch:f=>o(h=>[...h,...f]),onDone:()=>u(!0)}),c(!1)},[e,t,N]);return l.useEffect(()=>
2{v()},[v]),l.useEffect(()=>{const f=j.entities[e];if(!(f!=null&&f.subscribe))return;const h=f.subscribe(s=>{o(g=>{const x=[...g];if(s.type==="create")x.find(m=>{var _;return m.id===((_=s.data)==null?void 0:_.id)})||x.unshift(s.data);else if(s.type==="update"){const m=x.findIndex(_=>{var w;return _.id===((w=s.data)==null?void 0:w.id)});m>=0&&(x[m]=s.data)}else if(s.type==="delete"){const m=x.findIndex(_=>{var w;return _.id===((w=s.data)==null?void 0:w.id)});m>=0&&x.splice(m,1)}return x})});return()=>h==null?void 0:h()},[e]),{records:r,loading:d,fullyLoaded:y,reload:v,setRecords:o}}const $e=[{value:"all",label:"Todos",emoji:"ð"},{value:"saude",label:"Saúde",emoji:"ð"},{value:"familia",label:"FamÃlia",emoji:"ð¨âð©âð§âð¦"},{value:"trabalho",label:"Trabalho",emoji:"ð¼"},{value:"financas",label:"Finanças",emoji:"ð°"},{value:"espiritual",label:"Espiritual",emoji:"â¨"},{value:"nacao",label:"Nação",emoji:"ð§ð·"},{value:"outro",label:"Outro",emoji:"ð"}];function Ae(){const e=V(),[t,p]=l.useState(null),[r,o]=l.useState(null),[d,c]=l.useState("all");Ce({title:"Pedidos de Oração â Comunidade de Oração Cristã | GODBY",description:"Compartilhe seus pedidos de oração e ore com a comunidade cristã na GODBY. Sala de oração online: interceda por saúde, famÃlia, trabalho, finanças e vida espiritual com pessoas de fé.",url:"/pedidos-oracao"}),l.useEffect(()=>{(async()=>{try{const s=await j.auth.me().catch(()=>null);if(s){p(s);const g=await j.entities.UserProfile.filter({user_id:s.id});o(g[0]||null)}}catch{}})()},[]);const y=l.useMemo(()=>{const s={status:"active",privacy:{$in:["public","specific"]}};return d!=="all"&&(s.category=d),s},[d]),{records:u,loading:N,setRecords:v}=Re("PrayerRequest","-created_date",y),f=(s,g)=>{v(x=>x.map(m=>m.id===s?{...m,...g}:m))},h=s=>{v(g=>g.filter(x=>x.id!==s))};return a.jsx("div",{className:"min-h-full bg-background",children:a.jsxs("div",{className:"px-4 py-4 space-y-3 pb-24",children:[a.jsx(ke,{}),a.jsxs("button",{onClick:()=>e("/pedidos-oracao/criar"),className:"w-full flex items-center gap-3 p-3 rounded-2xl bg-card border border-border/60 hover:border-violet-500/30 transition-colors active:scale-[0.99]",children:[a.jsx(z,{src:r==null?void 0:r.profile_photo,name:(r==null?void 0:r.display_name)||(t==null?void 0:t.full_name),className:"w-10 h-10 rounded-full flex-shrink-0"}),a.jsx("span",{className:"flex-1 text-left text-sm text-muted-foreground",children:"Compartilhe um pedido de oração..."}),a.jsx("span",{className:"w-9 h-9 rounded-full bg-violet-500/10 flex items-center justify-center flex-shrink-0",children:a.jsx(H,{className:"w-5 h-5 text-violet-600 dark:text-violet-400"})})]}),a.jsx("div",{className:"flex gap-1.5 overflow-x-auto no-scrollbar -mx-4 px-4",children:$e.map(s=>a.jsxs("button",{onClick:()=>c(s.value),className:`flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border transition-colors ${d===s.value?"border-violet-500 bg-violet-500/10 text-violet-600 dark:text-violet-400":"border-border bg-card text-muted-foreground"}`,children:[s.emoji," ",s.label]},s.value))}),N?a.jsx("div",{className:"flex justify-center py-10",children:a.jsx(B,{className:"w-6 h-6 animate-spin text-violet-600"})}):u.length===0?a.jsxs("div",{className:"text-center py-10 px-4",children:[a.jsx("div",{className:"w-14 h-14 mx-auto rounded-2xl bg-violet-500/10 flex items-center justify-center mb-3",children:a.jsx(Ee,{className:"w-7 h-7 text-violet-600 dark:text-violet-400"})}),a.jsx("p",{className:"text-sm font-semibold",children:"Nenhum pedido ainda"}),a.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Seja o primeiro a compartilhar um pedido de oração."}),a.jsxs("button",{onClick:()=>e("/pedidos-oracao/criar"),className:"mt-4 inline-flex items-center gap-1.5 px-4 py-2 rounded-full prayer-gradient text-white text-sm font-bold",children:[a.jsx(Te,{className:"w-4 h-4"})," Fazer pedido de oração"]})]}):a.jsx("div",{className:"space-y-3",children:u.map(s=>a.jsx(Ie,{request:s,me:t,myProfile:r,onUpdate:f,onDelete:h},s.id))})]})})}export{Ae 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.