1import{Y as W,a3 as le,r as h,a4 as L,j as e,aR as he,ba as me,bG as ge,b9 as pe,ao as Z,a8 as J,au as N,a2 as ie}from"./vendor-DPFe_te2.js";import{o as ue,am as xe,a2 as je,s as _,$ as ye}from"./index-DFbr7-Jt.js";import"./vendor-md-DlwECirW.js";const D=["admin-hooks"],re=["admin-validated-hooks"],be=300;function ee(n){return n?n.startsWith("viral:")?"vÃdeo coletado":n.startsWith("creation:")?"criação do app":n.startsWith("ganchos1#")?"base curada":n.startsWith("doc:")?"material enviado":n:"â"}function fe(n=500){return ie({queryKey:[...D,n],queryFn:async()=>{const{data:m,error:r}=await _.from("hooks").select("id, content, category, niche, source, created_at").order("created_at",{ascending:!1}).limit(n);if(r)throw r;return m??[]}})}function ne(n){return ie({queryKey:[...re,n],queryFn:async()=>{const{data:m,error:r,count:u}=await _.from("validated_hooks").select("*",{count:"exact"}).eq("review_status",n).order("created_at",{ascending:!1}).range(0,be-1);if(r)throw r;return{rows:m??[],total:u??0}}})}function _e(){var A,I,K,O,M,Q,V,G,U,Y;const{t:n}=W(),{locale:m}=ue(),r=je(m),u=le(),[x,o]=h.useState("hooks"),[c,E]=h.useState(""),[P,k]=h.useState(!1),[f,w]=h.useState(null),[b,C]=h.useState(null),[l,d]=h.useState(new Set),g=fe(),j=ne("approved"),y=ne("pending"),p=L({mutationFn:async({ids:t,decision:a})=>{const{error:s}=await _.rpc("fn_review_hooks",{p_hook_ids:t,p_decision:a});if(s)throw new Error(s.message);return{count:t.length,decision:a}},onSuccess:({count:t,decision:a})=>{N.success(a==="approved"?n("admin.ganchos.msgApproved",{n:t}):n("admin.ganchos.msgRejected",{n:t})),d(new Set),u.invalidateQueries({queryKey:re})},onError:t=>N.error(t.message)}),oe=h.useMemo(()=>{const t=new Set;for(const a of g.data??[])a.category&&t.add(a.category);return[...t].sort((a,s)=>a.localeCompare(s))},[g.data]),F=h.useMemo(()=>{const t=c.trim().toLowerCase(),a=g.data??[];return t?a.filter(s=>s.content.toLowerCase().includes(t)||(s.category??"").toLowerCase().includes(t)||(s.niche??"").toLowerCase().includes(t)):a},[g.data,c]),q=t=>{const a=c.trim().toLowerCase(),s=t??[];return a?s.filter(S=>S.hook_text.toLowerCase().includes(a)||(S.hook_type??"").toLowerCase().includes(a)||(S.niche??"").toLowerCase().includes(a)):s},R=h.useMemo(()=>{var t;return q((t=j.data)==null?void 0:t.rows)},[j.data,c]),v=h.useMemo(()=>{var t;return q((t=y.data)==null?void 0:t.rows)},[y.data,c]),H=L({mutationFn:async t=>{const a=t.content.trim(),s=t.category.trim()||null,S=t.niche.trim()||null;if(!a)throw new Error(n("admin.ganchos.errContentRequired"));if(t.id){const{error:X}=await _.from("hooks").update({content:a,category:s,niche:S}).eq("id",t.id);if(X)throw X;return"updated"}const{error:$}=await _.from("hooks").insert({id:crypto.randomUUID(),content:a,category:s,niche:S,source:"admin"});if($)throw $;return"created"},onSuccess:t=>{N.success(n(t==="updated"?"admin.ganchos.msgUpdated":"admin.ganchos.msgCreated")),k(!1),w(null),u.invalidateQueries({queryKey:D})},onError:t=>N.error(t.message)}),T=L({mutationFn:async t=>{const{error:a}=await _.from("hooks").delete().eq("id",t);if(a)throw a},onSuccess:()=>{N.success(n("admin.ganchos.msgRemoved")),C(null),u.invalidateQueries({queryKey:D})},onError:t=>N.error(t.message)});function de(){w(null),k(!0)}function ce(t){w(t),k(!0)}return e.jsxs("div",{style:{display:"grid",gap:16},children:[e.jsxs("header",{children:[e.jsx("h1",{style:{margin:0,fontSize:22,letterSpacing:"-.02em"},children:n("admin.ganchos.title")}),e.jsx("p",{style:{margin:"4px 0 0",opacity:.65,fontSize:14},children:e.jsx(he,{i18nKey:"admin.ganchos.subtitle",components:{code:e.jsx("code",{}),em:e.jsx("em",{})}})})]}),e.jsxs("div",{style:ke,children:[e.jsxs(B,{active:x==="hooks",onClick:()=>o("hooks"),children:[n("admin.ganchos.tabHooks")," (",((A=g.data)==null?void 0:A.length)??"â",")"]}),e.jsxs(B,{active:x==="validated",onClick:()=>o("validated"),children:[n("admin.ganchos.tabValidated")," (",((I=j.data)==null?void 0:I.total)??"â",")"]}),e.jsxs(B,{active:x==="pending",onClick:()=>o("pending"),children:[n("admin.ganchos.tabPending")," (",((K=y.data)==null?void 0:K.total)??"â",")"]})]}),x!=="hooks"&&e.jsx("input",{type:"search",value:c,onChange:t=>E(t.target.value),placeholder:n("admin.ganchos.searchPlaceholder"),style:{...i.input,maxWidth:320}}),x==="hooks"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:se,children:[e.jsx("input",{type:"search",value:c,onChange:t=>E(t.target.value),placeholder:n("admin.ganchos.searchPlaceholder"),style:{...i.input,maxWidth:320}}),e.jsxs("button",{type:"button",onClick:de,style:i.primaryBtn,children:[e.jsx(me,{size:15})," ",n("admin.ganchos.newHook")]})]}),g.isLoading&&e.jsx("p",{style:{opacity:.6},children:n("admin.common.loading")}),g.error&&e.jsx("p",{style:{color:"var(--danger)"},children:g.error.message}),((O=g.data)==null?void 0:O.length)===0&&e.jsx(z,{hint:n("admin.ganchos.hooksEmpty")}),g.data&&g.data.length>0&&F.length===0&&e.jsx(z,{hint:n("admin.ganchos.noResults")}),F.length>0&&e.jsx("div",{className:"data-table-wrap",children:e.jsxs("table",{className:"data-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thContent")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thCategory")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thNiche")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thCreated")})}),e.jsx("th",{style:{width:92},children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thActions")})})]})}),e.jsx("tbody",{children:F.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.content}),e.jsx("td",{children:t.category??"â"}),e.jsx("td",{children:t.niche??"â"}),e.jsx("td",{className:"date",children:new Date(t.created_at).toLocaleDateString(r)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"inline-flex",gap:6},children:[e.jsx("button",{type:"button",onClick:()=>ce(t),style:i.iconBtn,"aria-label":n("admin.common.edit"),title:n("admin.common.edit"),children:e.jsx(ge,{size:14})}),e.jsx("button",{type:"button",onClick:()=>C(t),style:i.iconBtnDanger,"aria-label":n("admin.common.remove"),title:n("admin.common.remove"),children:e.jsx(pe,{size:14})})]})})]},t.id))})]})})]}),x==="validated"&&e.jsxs(e.Fragment,{children:[j.isLoading&&e.jsx("p",{style:{opacity:.6},children:n("admin.common.loading")}),j.error&&e.jsx("p",{style:{color:"var(--danger)"},children:j.error.message}),((M=j.data)==null?void 0:M.total)===0&&e.jsx(z,{hint:n("admin.ganchos.validatedEmpty")}),R.length===0&&(((Q=j.data)==null?void 0:Q.total)??0)>0&&e.jsx(z,{hint:n("admin.ganchos.noResults")}),R.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ae,{shown:R.length,total:((V=j.data)==null?void 0:V.total)??0}),e.jsx("div",{className:"data-table-wrap",children:e.jsxs("table",{className:"data-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thHook")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thType")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thNiche")})}),e.jsx("th",{className:"num",children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thSuccessPct")}
1)}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thOrigin")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thTemplate")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thActive")})}),e.jsx("th",{style:{width:60},children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thActions")})})]})}),e.jsx("tbody",{children:R.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.hook_text}),e.jsx("td",{children:t.hook_type}),e.jsx("td",{children:t.niche??"â"}),e.jsx("td",{className:"num",children:te(t.success_rate)}),e.jsx("td",{children:ee(t.source)}),e.jsx("td",{children:t.is_template?n("admin.common.yes"):n("admin.common.no")}),e.jsx("td",{children:t.is_active?n("admin.common.yes"):n("admin.common.no")}),e.jsx("td",{children:e.jsx("button",{type:"button",onClick:()=>p.mutate({ids:[t.id],decision:"rejected"}),disabled:p.isPending,style:i.iconBtnDanger,"aria-label":n("admin.ganchos.reject"),title:n("admin.ganchos.reject"),children:e.jsx(Z,{size:14})})})]},t.id))})]})})]})]}),x==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{margin:0,opacity:.65,fontSize:13,maxWidth:720},children:n("admin.ganchos.pendingIntro")}),y.isLoading&&e.jsx("p",{style:{opacity:.6},children:n("admin.common.loading")}),y.error&&e.jsx("p",{style:{color:"var(--danger)"},children:y.error.message}),((G=y.data)==null?void 0:G.total)===0&&e.jsx(z,{hint:n("admin.ganchos.pendingEmpty")}),v.length===0&&(((U=y.data)==null?void 0:U.total)??0)>0&&e.jsx(z,{hint:n("admin.ganchos.noResults")}),v.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:se,children:[e.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:8,fontSize:13},children:[e.jsx("input",{type:"checkbox",checked:l.size>0&&l.size===v.length,onChange:t=>d(t.target.checked?new Set(v.map(a=>a.id)):new Set)}),n("admin.ganchos.selectAll",{n:v.length})]}),e.jsxs("div",{style:{display:"inline-flex",gap:8},children:[e.jsxs("button",{type:"button",disabled:l.size===0||p.isPending,onClick:()=>p.mutate({ids:[...l],decision:"approved"}),style:{...i.primaryBtn,opacity:l.size===0?.45:1},children:[e.jsx(J,{size:15})," ",n("admin.ganchos.approveSelected",{n:l.size})]}),e.jsx("button",{type:"button",disabled:l.size===0||p.isPending,onClick:()=>p.mutate({ids:[...l],decision:"rejected"}),style:{...i.ghostBtn,opacity:l.size===0?.45:1},children:n("admin.ganchos.rejectSelected")})]})]}),e.jsx(ae,{shown:v.length,total:((Y=y.data)==null?void 0:Y.total)??0}),e.jsx("div",{className:"data-table-wrap",children:e.jsxs("table",{className:"data-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:{width:36},children:e.jsx("span",{className:"th-inner"})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thHook")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thNiche")})}),e.jsx("th",{className:"num",children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thSuccessPct")})}),e.jsx("th",{children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thOrigin")})}),e.jsx("th",{style:{width:92},children:e.jsx("span",{className:"th-inner",children:n("admin.ganchos.thActions")})})]})}),e.jsx("tbody",{children:v.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("input",{type:"checkbox",checked:l.has(t.id),onChange:a=>{const s=new Set(l);a.target.checked?s.add(t.id):s.delete(t.id),d(s)},"aria-label":t.hook_text.slice(0,60)})}),e.jsx("td",{children:t.hook_text}),e.jsx("td",{children:t.niche??"â"}),e.jsx("td",{className:"num",children:te(t.success_rate)}),e.jsx("td",{children:ee(t.source)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"inline-flex",gap:6},children:[e.jsx("button",{type:"button",onClick:()=>p.mutate({ids:[t.id],decision:"approved"}),disabled:p.isPending,style:i.iconBtn,"aria-label":n("admin.ganchos.approve"),title:n("admin.ganchos.approve"),children:e.jsx(J,{size:14})}),e.jsx("button",{type:"button",onClick:()=>p.mutate({ids:[t.id],decision:"rejected"}),disabled:p.isPending,style:i.iconBtnDanger,"aria-label":n("admin.ganchos.reject"),title:n("admin.ganchos.reject"),children:e.jsx(Z,{size:14})})]})})]},t.id))})]})})]})]}),P&&e.jsx(ve,{initial:f,categories:oe,saving:H.isPending,onCancel:()=>{k(!1),w(null)},onSubmit:t=>H.mutate({...t,id:f==null?void 0:f.id})}),e.jsx(xe,{open:!!b,title:n("admin.ganchos.confirmRemoveTitle"),description:b?n("admin.ganchos.confirmRemoveBody",{content:b.content.slice(0,80)}):void 0,confirmLabel:n("admin.common.remove"),destructive:!0,loading:T.isPending,onConfirm:()=>{b&&T.mutate(b.id)},onCancel:()=>C(null)})]})}function ve({initial:n,categories:m,saving:r,onCancel:u,onSubmit:x}){const{t:o}=W(),[c,E]=h.useState((n==null?void 0:n.content)??""),[P,k]=h.useState((n==null?void 0:n.category)??""),[f,w]=h.useState((n==null?void 0:n.niche)??"");ye(!r,u);const b=c.trim()?c.trim().split(/\s+/).length:0,C=b>30;function l(d){d.preventDefault(),x({content:c,category:P,niche:f})}return e.jsx("div",{className:"ds-modal-overlay",role:"dialog","aria-modal":"true","aria-labelledby":"hook-editor-title",onClick:()=>!r&&u(),style:we,children:e.jsxs("form",{className:"ds-modal-card",onClick:d=>d.stopPropagation(),onSubmit:l,style:Ce,children:[e.jsx("h3",{id:"hook-editor-title",style:{margin:0,fontSize:17,fontWeight:600},children:o(n?"admin.ganchos.editHook":"admin.ganchos.newHook")}),e.jsxs("label",{style:{display:"grid",gap:6},children:[e.jsx("span",{style:i.label,children:o("admin.ganchos.fContent")}),e.jsx("textarea",{value:c,onChange:d=>E(d.target.value),placeholder:o("admin.ganchos.fContentPh"),rows:3,autoFocus:!0,style:{...i.input,resize:"vertical",minHeight:72,lineHeight:1.45}}),e.jsxs("span",{style:{fontSize:11,color:C?"var(--danger, #ef4444)":"var(--text-dim, #8a857b)"},children:[o("admin.ganchos.wordCount",{n:b}),C?` · ${o("admin.ganchos.wordCountWarn")}`:""]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("label",{style:{display:"grid",gap:6},children:[e.jsx("span",{style:i.label,children:o("admin.ganchos.fCategory")}),e.jsx("input",{value:P,onChange:d=>k(d.target.value),placeholder:o("admin.ganchos.fCategoryPh"),list:"hook-categories",style:i.input}),e.jsx("datalist",{id:"hook-categories",children:m.map(d=>e.jsx("option",{value:d},d))})]}),e.jsxs("label",{style:{display:"grid",gap:6},children:[e.jsx("span",{style:i.label,children:o("admin.ganchos.fNiche")}),e.jsx("input",{value:f,onChange:d=>w(d.target.value),placeholder:o("admin.ganchos.fNichePh"),style:i.input})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:4},children:[e.jsx("button",{type:"button",onClick:u,disabled:r,style:i.ghostBtn,children:o("admin.common.cancel")}),e.jsx("button",{type:"submit",disabled:r||!c.trim(),style:i.primaryBtn,children:o(r?"admin.common.saving":"admin.common.save")})]})]})})}function te(n){return n==null?"â":`${Math.round(n*100)}%`}function ae({shown:n,total:m}){const{t:r}=W();return n>=m?null:e.jsx("p",{style:{margin:0,fontSize:12,opacity:.6},children:r("admin.ganchos.showingOf",{shown:n,total:m})})}function z({hint:n}){return e.jsx("div",{style:{padding:24,borderRadius:12,background:"var(--bg-card)",border:"1px solid var(--border)",textAlign:"center"},children:e.jsx("p",{style:{opacity:.7,margin:0},children:n})})}function B({active:n,onClick:m,children:r}){return e.jsx("button",{type:"button",onClick:m,style:{padding:"6px 14px",borderRadius:999,border:"none",background:n?"var(--brand-500, #F46D11)":"transparent",color:n?"#0a0a0a":"inherit",fontWeight:n?600:400,fontSize:12,cursor:"pointer"},children:r})}const ke={display:"inline-flex",padding:3,borderRadius:999,background:"var(--surface-2)",border:"1px solid var(--hairline-2)",alignSelf:"flex-start"},se={display:"flex",gap:10,alignItems:"center",justifyContent:"space-between",flexWrap:"wrap"},we={position:"fixed",inset:0,background:"rgba(0,0,0,0.6)",display:"grid",placeItems:"center",padding:24,zIndex:90},Ce={width:"100%",maxWidth:520,padding:24,borderRadius:16,background:"var(--bg-card)",border:"1px solid var(--border)",boxShadow:"var(--shadow-lg)",display:"grid",gap:14},i={primaryBtn:{display:"inline-flex",alignItems:"center",gap:6,padding:"9px 14px",borderRadius:999,border:"none",background:"var(--brand-500, #F46D11)",color:"#0A0908",fontWeight:700,fontSize:13,cursor:"pointer",fontFamily:"inherit"},ghostBtn:{padding:"9px 14px",borderRadius:999,border:"1px solid var(--border-strong, var(--border))",background:"transparent",color:"var(--text)",cursor:"pointer",fontSize:13,fontFamily:"inherit"},iconBtn:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,borderRadius:8,border:"1px solid var(--hairline-2)",background:"var(--surface-2)",color:"var(--text)",cursor:"pointer"},iconBtnDanger:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:30,height:30,borderRadius:8,border:"1px solid rgba(239,68,68,0.32)",background:"rgba(239,68,68,0.10)",color:"#FCA5A5",cursor:"pointer"},label:{fontSize:11,opacity:.7,fontWeight:600,letterSpacing:"0.03em",textTransform:"uppercase"},input:{padding:"9px 11px",borderRadius:8,border:"1px solid var(--hairline-2)",background:"var(--surface-2)",color:"inherit",fontSize:13,outline:"none",width:"100%",boxSizing:"border-box",fontFamily:"inherit"}};export{_e 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.