1import{j as e}from"./vendor-ui-CEGjIuqP.js";import{r as o,h as S}from"./vendor-react-BT-Op1j_.js";import{a6 as T,s as l,f as X,N as L,B as c,A as C,aM as M,b7 as A,l as E,ab as d,aO as m,F as G}from"./index-DgkqAiwu.js";import{A as f,a as u}from"./alert-DYfVHOeT.js";import{C as H,a as F,b as B}from"./collapsible-BAacVz-D.js";import"./vendor-data-CqtBkUbK.js";import"./vendor-charts-F376sfYw.js";import"./vendor-editor-CAsPUtf2.js";import"./vendor-dnd-D3FEUJ2d.js";const J=()=>{const[y,p]=o.useState(!0),[g,h]=o.useState(!1),[x,j]=o.useState(null),{toast:a}=T(),i=S(),[t,n]=o.useState({before_head_end:"",after_body_start:"",before_body_end:""});o.useEffect(()=>{_()},[]);const _=async()=>{const{data:{user:s}}=await l.auth.getUser();if(!s){a({title:"Authentication required",description:"Please log in to access this page",variant:"destructive"}),i("/login");return}const{data:r,error:b}=await l.from("user_roles").select("role").eq("user_id",s.id);if(b){console.error("Error checking user roles:",b),a({title:"Error",description:"Failed to verify admin status",variant:"destructive"}),i("/");return}const v=["admin","customer_service","project_manager"];if(!(r==null?void 0:r.some(k=>v.includes(k.role)))){a({title:"Access denied",description:"You must be an admin to access this page",variant:"destructive"}),i("/");return}w()},w=async()=>{p(!0);const{data:s,error:r}=await l.from("global_html_snippets").select("*").order("updated_at",{ascending:!1}).limit(1).maybeSingle();r?(console.error("Error loading snippets:",r),a({title:"Error",description:"Failed to load HTML snippets",variant:"destructive"})):s&&(j(s.id),n({before_head_end:s.before_head_end||"",after_body_start:s.after_body_start||"",before_body_end:s.before_body_end||""})),p(!1)},N=async()=>{if(!x)return;h(!0);const{error:s}=await l.from("global_html_snippets").update({before_head_end:t.before_head_end,after_body_start:t.after_body_start,before_body_end:t.before_body_end}).eq("id",x);a(s?{title:"Error",description:s.message,variant:"destructive"}:{title:"Success",description:"Global HTML snippets updated successfully"}),h(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(X,{titlePrefix:"Global HTML & Scripts - Admin",noIndex:!0}),e.jsxs("div",{className:"min-h-screen flex flex-col bg-gray-50",children:[e.jsx(L,{}),e.jsx("main",{className:"flex-1 container mx-auto px-4 py-12 pt-[168px] md:pt-[152px]",children:e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold mb-2",children:"Global HTML Snippets"}),e.jsx("p",{className:"text-muted-foreground",children:"Add custom HTML, scripts, or tracking codes to all pages"})]}),e.jsxs(c,{onClick:()=>i("/admin"),variant:"outline",className:"flex-shrink-0",children:[e.jsx(C,{className:"mr-2 h-4 w-4"}),"Back to Admin"]})]}),y?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading..."})}):e.jsxs("div",{className:"bg-white rounded-lg shadow p-6 space-y-6",children:[e.jsxs(f,{className:"bg-amber-50 border-amber-200",children:[e.jsx(M,{className:"h-4 w-4 text-amber-600"}),e.jsx(u,{className:"text-amber-800",children:"Incorrect html/scripts entered here can break the website - be sure to check the site after making any changes"})]}
1),e.jsxs(H,{children:[e.jsx(F,{asChild:!0,children:e.jsxs(c,{variant:"outline",className:"w-full justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"View Examples & Supported HTML Tags"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Click to expand"})]})}),e.jsxs(B,{className:"mt-4 space-y-4",children:[e.jsxs(f,{className:"bg-blue-50 border-blue-200",children:[e.jsx(E,{className:"h-4 w-4 text-blue-600"}),e.jsxs(u,{className:"text-blue-800",children:[e.jsx("strong",{children:"You can paste raw HTML directly!"})," The system supports meta tags, scripts, link tags, and more."]})]}),e.jsxs("div",{className:"grid gap-4 text-sm",children:[e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:"SEO Meta Tags:"}),e.jsx("code",{className:"block bg-gray-100 p-2 rounded text-xs overflow-x-auto whitespace-pre",children:`<meta name="description" content="Your page description here"> 2<meta name="keywords" content="keyword1, keyword2, keyword3"> 3<meta name="author" content="Your Name">`})]}),e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:"Open Graph (Social Media Previews):"}),e.jsx("code",{className:"block bg-gray-100 p-2 rounded text-xs overflow-x-auto whitespace-pre",children:`<meta property="og:title" content="Your Title"> 4<meta property="og:description" content="Your Description"> 5<meta property="og:image" content="https://example.com/image.jpg"> 6<meta property="og:url" content="https://example.com">`})]}),e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:"Google Analytics / GTM:"}),e.jsx("code",{className:"block bg-gray-100 p-2 rounded text-xs overflow-x-auto whitespace-pre",children:`<!-- Google tag (gtag.js) --> 7<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXX"><\/script> 8<script> 9
vendor: 133 bytes, lines 9-12
9window.dataLayer = window.dataLayer || []; 10 function gtag(){dataLayer.push(arguments);} 11 gtag('js', new Date()); 12 gtag('config', '
12G-XXXXXX
vendor: 4 bytes, line 12
12');
13<\/script>`})]}),e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:"Facebook Pixel:"}),e.jsx("code",{className:"block bg-gray-100 p-2 rounded text-xs overflow-x-auto whitespace-pre",children:`<script> 14!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){...}; 15fbq('init', 'YOUR_PIXEL_ID'); 16fbq('track', 'PageView'); 17<\/script>`})]}),e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:"Custom Fonts / Stylesheets:"}),e.jsx("code",{className:"block bg-gray-100 p-2 rounded text-xs overflow-x-auto whitespace-pre",children:`<link rel="preconnect" href="https://fonts.googleapis.com"> 18<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">`})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"before_head_end",className:"text-black text-base",children:"Before Head End (Meta Tags, Scripts, Styles):"}),e.jsx(m,{id:"before_head_end",value:t.before_head_end,onChange:s=>n({...t,before_head_end:s.target.value}),placeholder:`Paste your HTML here. Examples: 19 20<meta name="description" content="Your SEO description"> 21<meta property="og:image" content="https://example.com/image.jpg"> 22 23<!-- Google Analytics --> 24<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX"><\/script>`,rows:8,className:"bg-white text-gray-700 font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Best for: Meta tags (SEO, Open Graph), tracking scripts, custom fonts, stylesheets. Code will be inserted before the closing </head> tag."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"after_body_start",className:"text-black text-base",children:"After Body Start (Noscript Fallbacks):"}),e.jsx(m,{id:"after_body_start",value:t.after_body_start,onChange:s=>n({...t,after_body_start:s.target.value}),placeholder:`Paste your HTML here. Example: 25 26<!-- Google Tag Manager (noscript) -->
vendor: 68 bytes, lines 26-27
26 27<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=
27GTM-XXXXX
vendor: 82 bytes, lines 27-28
27" 28height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
28`,rows:6,className:"bg-white text-gray-700 font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Best for: Noscript fallbacks for tracking pixels. Code will be inserted right after the opening <body> tag."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"before_body_end",className:"text-black text-base",children:"Before Body End (Footer Scripts):"}),e.jsx(m,{id:"before_body_end",value:t.before_body_end,onChange:s=>n({...t,before_body_end:s.target.value}),placeholder:`Paste your HTML here. Example: 29 30<!-- Chat widget or other scripts that should load last --> 31<script src="https://example.com/chat-widget.js"><\/script>`,rows:6,className:"bg-white text-gray-700 font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Best for: Chat widgets, analytics that don't need to load early, other footer scripts. Code will be inserted before the closing </body> tag."})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(c,{onClick:N,disabled:g,className:"bg-gray-800 hover:bg-gray-700",children:g?"Saving...":"Save Global HTML"})})]})]})}),e.jsx(G,{})]})]})};export{J 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.