1import{j as e}from"./vendor-ui-CezFABrC.js";import{h as Y,r as a}from"./vendor-react-BKa71ujQ.js";import{L as f,a3 as G,N as J,B as o,A as V,l as E,b4 as I,n as x,a6 as K,b$ as P,aD as W,b5 as F,b6 as O,m as R,ab as l,I as c,dU as j,w as Z,bK as ee,F as se,s as r,bA as n}from"./index-Rt0ORiw_.js";import{a as te,u as ae,d as U}from"./vendor-data-kfxz6GN9.js";import"./vendor-charts-DDSFMeER.js";import"./vendor-editor-Dg0kxhZ2.js";import"./vendor-motion-ClyPiY3v.js";import"./vendor-carousel-ClXKjko3.js";import"./vendor-dnd-CuNJvw6T.js";const pe=()=>{const i=Y(),v=te(),[y,L]=a.useState(!1),[q,T]=a.useState(!0),[N,b]=a.useState(""),[w,A]=a.useState(""),[m,S]=a.useState(""),[h,D]=a.useState(""),[M,_]=a.useState(!1),[$,C]=a.useState(!0),[B,ne]=a.useState(!0);a.useEffect(()=>{(async()=>{try{const{data:{session:t}}=await r.auth.getSession();if(!t){i("/login");return}const{data:u,error:k}=await r.rpc("is_admin_or_cs_or_pm",{_user_id:t.user.id});if(k)throw k;if(!u){i("/");return}L(!0)}catch(t){console.error("Error checking admin status:",t),i("/")}finally{T(!1)}})()},[i]);const{data:d,isLoading:Q}=ae({queryKey:["event-settings-other"],queryFn:async()=>{const{data:s,error:t}=await r.from("event_settings").select("resend_from_name, resend_from_domain, resend_api_key").order("updated_at",{ascending:!1}).limit(1).maybeSingle();if(t)throw t;return s},enabled:y});a.useEffect(()=>{d&&(b(d.resend_from_name||""),A(d.resend_from_domain||""),C(!!d.resend_api_key))},[d]);const p=U({mutationFn:async()=>{const{data:s}=await r.from("event_settings").select("id").order("updated_at",{ascending:!1}).limit(1).maybeSingle();if(s){const{error:t}=await r.from("event_settings").update({resend_from_name:N||null,resend_from_domain:w||null,updated_at:new Date().toISOString()}).eq("id",s.id);if(t)throw t}else throw new Error("No event settings found to update")},onSuccess:()=>
1{n.success("Settings saved successfully"),v.invalidateQueries({queryKey:["event-settings-other"]})},onError:s=>{n.error(`Failed to save settings: ${s.message}`)}}),g=U({mutationFn:async s=>{const{data:t}=await r.from("event_settings").select("id").order("updated_at",{ascending:!1}).limit(1).maybeSingle();if(t){const{error:u}=await r.from("event_settings").update({resend_api_key:s,updated_at:new Date().toISOString()}).eq("id",t.id);if(u)throw u}else throw new Error("No event settings found to update")},onSuccess:()=>{n.success("Resend API key updated successfully"),S(""),C(!0),v.invalidateQueries({queryKey:["event-settings-other"]})},onError:s=>{n.error(`Failed to update API key: ${s.message}`)}}),z=()=>{if(!m.trim()){n.error("Please enter a Resend API key");return}g.mutate(m.trim())},H=()=>{if(!h.trim()){n.error("Please enter a SEO Article API key");return}n.info('To update the SEO Article API key, please ask the Lovable AI assistant: "Update the SEO_ARTICLE_API_KEY secret" and provide the new value.',{duration:1e4})},X=()=>{navigator.clipboard.writeText("https://gwgzvdecklaqvvorcrfd.supabase.co/functions/v1/receive-article"),_(!0),n.success("Endpoint copied to clipboard"),setTimeout(()=>_(!1),2e3)};return q||Q?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(f,{className:"h-8 w-8 animate-spin"})}):y?e.jsxs(e.Fragment,{children:[e.jsxs(G,{children:[e.jsx("title",{children:"Other Settings - Admin"}),e.jsx("meta",{name:"robots",content:"noindex, nofollow"})]}),e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(J,{}),e.jsx("div",{className:"flex-1 bg-muted/30 pt-[168px] pb-16",children:e.jsxs("div",{className:"container mx-auto px-4 max-w-4xl",children:[e.jsxs("div",{className:"mb-6 flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold mb-2",children:"Other Settings"}),e.jsx("p",{className:"text-muted-foreground",children:"Configure email and API settings"})]}),e.jsxs(o,{variant:"outline",onClick:()=>i("/admin"),className:"flex-shrink-0",children:[e.jsx(V,{className:"mr-2 h-4 w-4"}),"Back to Admin"]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(E,{children:[e.jsxs(I,{className:"relative",children:[e.jsx("div",{className:"absolute top-4 right-4",children:$?e.jsxs(x,{variant:"outline",className:"bg-background border-green-200 text-green-700",children:[e.jsx(K,{className:"h-3.5 w-3.5 mr-1"}),"API Key Configured"]}):e.jsxs(x,{variant:"outline",className:"bg-background border-red-200 text-red-700",children:[e.jsx(P,{className:"h-3.5 w-3.5 mr-1"}),"API Key Not Set"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{className:"h-5 w-5"}),e.jsx(F,{children:"Resend Email Configuration"})]}),e.jsx(O,{children:"Configure the email sender settings for Resend"})]}),e.jsxs(R,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"resend-from-name",children:"From Name"}),e.jsx(c,{id:"resend-from-name",value:N,onChange:s=>b(s.target.value),placeholder:"e.g., Event Team"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The sender name displayed in emails"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"resend-from-domain",children:"From Domain"}),e.jsx(c,{id:"resend-from-domain",value:w,onChange:s=>A(s.target.value),placeholder:"e.g., [email protected]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The verified sender email address"})]})]}),e.jsx("div",{className:"border-t pt-4 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"resend-api-key",children:"Update Resend API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{id:"resend-api-key",type:"password",value:m,onChange:s=>S(s.target.value),placeholder:"Enter new API key"}),e.jsx(o,{onClick:z,disabled:g.isPending||!m.trim(),children:g.isPending?e.jsx(f,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"h-4 w-4 mr-2"}
1),"Update Key"]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter a new Resend API key to update the existing one"})]})})]})]}),e.jsxs(E,{children:[e.jsxs(I,{className:"relative",children:[e.jsx("div",{className:"absolute top-4 right-4",children:B?e.jsxs(x,{variant:"outline",className:"bg-background border-green-200 text-green-700",children:[e.jsx(K,{className:"h-3.5 w-3.5 mr-1"}),"API Key Configured"]}):e.jsxs(x,{variant:"outline",className:"bg-background border-red-200 text-red-700",children:[e.jsx(P,{className:"h-3.5 w-3.5 mr-1"}),"API Key Not Set"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{className:"h-5 w-5"}),e.jsx(F,{children:"SEO Article API"})]}),e.jsx(O,{children:"Configure the SEO article receiver endpoint"})]}),e.jsxs(R,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:"Endpoint URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{value:"https://gwgzvdecklaqvvorcrfd.supabase.co/functions/v1/receive-article",readOnly:!0,className:"font-mono text-sm"}),e.jsx(o,{variant:"outline",onClick:X,children:M?e.jsx(Z,{className:"h-4 w-4"}):e.jsx(ee,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use this endpoint to submit SEO articles programmatically"})]}),e.jsx("div",{className:"border-t pt-4 mt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"seo-api-key",children:"Update SEO Article API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(c,{id:"seo-api-key",type:"password",value:h,onChange:s=>D(s.target.value),placeholder:"Enter new API key"}),e.jsxs(o,{onClick:H,disabled:!h.trim(),children:[e.jsx(j,{className:"h-4 w-4 mr-2"}),"Update Key"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter a new SEO Article API key to update the existing one"})]})})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(o,{onClick:()=>p.mutate(),disabled:p.isPending,size:"lg",children:p.isPending?e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save Settings"})})]})]})}),e.jsx(se,{})]})]}):null};export{pe 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.