1import{a as P,r as c,j as e,B as l,I as s,c7 as f,c8 as _,bq as A,s as d}from"./index-KSWbwNeY.js";import{I as N}from"./lucide-react-DtQ4f67v.js";import{L as r}from"./label-ndOKmXJw.js";import{T as U}from"./textarea-BXv-lbww.js";import{D as q,a as B,b as O,c as z,d as R}from"./dialog-Bpfij23O.js";import{C as b}from"./card-CwL_ed79.js";import F from"./NotificationWidget-enRkpMwr.js";import{A as H}from"./AdminNav-DsaLvjFx.js";import{P as M}from"./plus-oseq6Y0_.js";import{E as W}from"./eye-Cwzmef_1.js";import{E as K}from"./eye-off-DqR1XpTQ.js";import{P as $}from"./pencil-BI2V26IC.js";import{T as G}from"./trash-2-CwcwS_bf.js";import"./gauge-C60sEmQH.js";import"./arrow-down-DKVyz2Fj.js";import"./arrow-left-1kEvYP7w.js";import"./user-cog-DvqSS7bY.js";import"./arrow-up-down-DX-AOYn7.js";import"./arrow-up-CBTsa4sb.js";import"./award-CzReamER.js";import"./ban-Dw9y4DYY.js";import"./book-open-DS7Nmuzn.js";import"./briefcase-B44Bkvp2.js";import"./building-2-BHBT7DvO.js";import"./calendar-Cdsbx2VF.js";import"./chevron-down-D7IdZFzc.js";import"./chevron-left-C0OR5oyH.js";import"./chevron-up-B5q4f77c.js";import"./chevrons-right-kQ_1KW5C.js";import"./circle-alert-B57G6NgG.js";import"./circle-check-big-C14ZIfaU.js";import"./circle-check-8n8_Yy4E.js";import"./timer-Cjq2uP0S.js";import"./circle-x-BIrM7WJR.js";import"./clock-CzRotAbS.js";import"./code-xml-DKN-dImL.js";import"./frame-DK78DFP3.js";import"./copy-Crr8TIYJ.js";import"./heart-BKeMwoxw.js";import"./download-BtORIOsS.js";import"./ellipsis-aIaacu3o.js";import"./facebook-DahhNxAJ.js";import"./filter-BFFcBMjy.js";import"./flag-DhaMxnCI.js";import"./flame-Ck6h37yv.js";import"./pen-tool-DgCU2-5j.js";import"./folder-open-DdjcdZ5b.js";import"./type-ByxbHmee.js";import"./globe-CoeBqXIi.js";import"./grip-vertical-CeQgvVnP.js";import"./minimize-2-DZ_0eBEd.js";import"./indian-rupee-CqiOCBT_.js";import"./info-BEx3d0ds.js";import"./youtube-CwivUiPT.js";import"./zoom-out-C68OcPwQ.js";import"./link-2-VBLbUTUk.js";import"./linkedin-B1bA0DJP.js";import"./lock-DNHSxtLD.js";import"./map-pin-ByDI4dgS.js";import"./maximize-2-yYWjcX_b.js";import"./megaphone-9smGzN1L.js";import"./message-circle-CTM3eYRV.js";import"./message-square-quote-CTKL5-su.js";import"./message-square-D9MVWo21.js";import"./monitor-DWTsCiB7.js";import"./mouse-pointer-CfBgNt0g.js";import"./palette-DgiBJZzP.js";import"./pen-BKGmuNWh.js";import"./percent-eJe4-D1A.js";import"./pin-off-VcIENd_X.js";import"./pin-DHVdH5Ty.js";import"./trending-down-DkMB12LV.js";import"./printer-C8Q1PzYy.js";import"./radio-BbIxXjYG.js";import"./receipt-DgWJf9Ou.js";import"./rotate-ccw-L8AGeQxc.js";import"./save-xjMYTeam.js";import"./send-Diy0wlsk.js";import"./settings-2-DosyAUqX.js";import"./share-2-DMKgqov0.js";import"./shield-check-CHHnEQz_.js";import"./shield-x-ChXCKoj7.js";import"./shuffle-BOT2k_fz.js";import"./smartphone-C9APGzKx.js";import"./square-pen-CRmh_xc0.js";import"./star-DnX2lA9e.js";import"./triangle-alert-D2A9IHcD.js";import"./trophy-DOqUgSiA.js";import"./twitter-yEUqfNJX.js";import"./upload-CstIFHrJ.js";import"./user-minus-jgLnIJNk.js";import"./user-plus-1CV9fZb0.js";import"./user-x-Dnw7rX3O.js";import"./volume-x-j3xRYxXz.js";import"./zoom-in-DZK_VH4x.js";import"./index-BpbyRUKB.js";import"./index-DsYLezIw.js";const y={title:"",description:"",image_url:"",icon_name:"",cta_label:"",cta_href:"",href:"",delay_ms:2e3,duration_ms:5e3,is_active:!0,display_order:0,rotation_weight:1,text_color:null,bg_color:null,bg_opacity:.95},Bt=()=>{const{toast:n}=P(),[h,w]=c.useState([]),[C,g]=c.useState(!0),[k,m]=c.useState(!1),[v,T]=c.useState(0),[t,a]=c.useState(y),p=async()=>{g(!0);const{data:i,error:o}=await d.from("admin_notifications").select("*").order("display_order",{ascending:!1}).order("created_at",{ascending:!1});o?n({title:"Failed to load",description:o.message,variant:"destructive"}):w(i||[]),g(!1)};c.useEffect(()=>{p()},[]);const D=()=>{a(y),m(!0)},S=i=>{a(i),m(!0)},I=async()=>{var j;if(!((j=t.title)!=null&&j.trim())){n({title:"Title required",variant:"destructive"});return}const i={title:t.title,description:t.description||null,image_url:t.image_url||null,icon_name:t.icon_name||null,cta_label:t.cta_label||null,cta_href:t.cta_href||null,href:t.href||null,delay_ms:Number(t.delay_ms??2e3),duration_ms:Number(t.duration_ms??5e3),is_active:!!t.is_active,display_order:Number(t.display_order??0),rotation_weight:Number(t.rotation_weight??1),start_at:t.start_at||null,end_at:t.end_at||null,text_color:t.text_color||null,bg_color:t.bg_color||null,bg_opacity:Number(t.bg_opacity??.95)};let o;if(t.id)({error:o}=await d.from("admin_notifications").update(i).eq("id",t.id));else{const{data:{user:u}}=await d.auth.getUser();({error:o}=await d.from("admin_notifications").insert({...i,created_by:u==null?void 0:u.id}))}if(o){n({title:"Save failed",description:o.message,variant:"destructive"});return}n({title:"Saved"}),m(!1),p()},E=async i=>{const{error:o}=await d.from("admin_notifications").update({is_active:!i.is_active}).eq("id",i.id);o?n({title:"Update failed",description:o.message,variant:"destructive"}):p()},L=async i=>{if(!confirm(`Delete "${i.title}"?`))return;const{error:o}=await d.from("admin_notifications").delete().eq("id",i.id);o?n({title:"Delete failed",description:o.message,variant:"destructive"}):p()},x=t.icon_name&&N[t.icon_name]?N[t.icon_name]:null;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(H,{}),e.jsx("main",{className:"md:ml-52 p-6 overflow-auto",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Notification"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage the slide-in notification shown on the public site."})]}),e.jsxs(l,{onClick:D,children:[e.jsx(M,{className:"mr-2 h-4 w-4"})," New Notification"]})]}),C?e.jsx("p",{className:"text-muted-foreground",children:"Loadingâ¦"}):h.length===0?e.jsxs(b,{className:"p-8 text-center text-muted-foreground",children:["No notifications yet. Click ",e.jsx("strong",{children:"New Notification"})," to create one."]}):e.jsx("div",{className:"space-y-3",children:h.map(i=>e.jsxs(b,{className:"flex items-center justify-between gap-4 p-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"truncate font-semibold",children:i.title}),!i.is_active&&e.jsx("span",{className:"rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground",children:"Inactive"})]}),i.description&&e.jsx("p",{className:"mt-1 line-clamp-1 text-sm text-muted-foreground",children:i.description}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Delay ",i.delay_ms,"ms · Duration ",i.duration_ms,"ms · Order ",i.display_order]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>E(i),title:i.is_active?"Disable":"Enable",children:i.is_active?e.jsx(W,{className:"h-4 w-4"}):e.jsx(K,{className:"h-4 w-4"})}),e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>S(i),children:e.jsx($,{className:"h-4 w-4"})}),e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>L(i),children:e.jsx(G,{className:"h-4 w-4"})})]})]},i.id))}),e.jsx(q,{open:k,onOpenChange:m,children:e.jsxs(B,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",children:[e.jsx(O,{children:e.jsxs(z,{children:[t.id?"Edit":"New"," Notification"]})}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Title *"}),e.jsx(s,{value:t.title||"",onChange:i=>a({...t,title:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Description"}),e.jsx(U,{rows:2,value:t.description||"",onChange:i=>a({...t,description:i.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Image URL"}),e.jsx(s,{placeholder:"https://â¦",value:t.image_url||"",onChange:i=>a({...t,image_url:i.target.value,icon_name:i.target.value?"":t.icon_name})})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Icon name (lucide)"}),e.jsx(s,{placeholder:"Bell, Sparkles, Crownâ¦",value:t.icon_name||"",onChange:i=>a({...t,icon_name:i.target.value}),disabled:!!t.image_url}),t.icon_name&&!x&&e.jsx("p",{className:"mt-1 text-xs text-destructive",children:"Unknown icon name"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(r,{children:"CTA label"}),e.jsx(s,{value:t.cta_label||"",onChange:i=>a({...t,cta_label:i.target.value})})]}),e.jsxs("div",{children:[e.jsx(r,{children:"CTA link"}),e.jsx(s,{placeholder:"/subscribe or https://â¦",value:t.cta_href||"",onChange:i=>a({...t,cta_href:i.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Wrap whole card in link (optional)"}),e.jsx(s,{placeholder:"/path or https://â¦",value:t.href||"",onChange:i=>a({...t,href:i.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_1fr_1.5fr] gap-3 items-end",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Text color"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s,{type:"color",className:"h-9 w-12 p-1",value:t.text_color||"#0f172a",onChange:i=>a({...t,text_color:i.target.value})}),e.jsx(s,{placeholder:"auto",value:t.text_color||"",onChange:i=>a({...t,text_color:i.target.value||null})})]})]}
1),e.jsxs("div",{children:[e.jsx(r,{children:"Background color"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s,{type:"color",className:"h-9 w-12 p-1",value:t.bg_color||"#ffffff",onChange:i=>a({...t,bg_color:i.target.value})}),e.jsx(s,{placeholder:"auto",value:t.bg_color||"",onChange:i=>a({...t,bg_color:i.target.value||null})})]})]}),e.jsxs("div",{children:[e.jsxs(r,{children:["Background opacity (",Math.round((t.bg_opacity??.95)*100),"%)"]}),e.jsx("input",{type:"range",min:0,max:1,step:.05,value:t.bg_opacity??.95,onChange:i=>a({...t,bg_opacity:Number(i.target.value)}),className:"h-9 w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Delay (ms)"}),e.jsx(s,{type:"number",value:t.delay_ms??2e3,onChange:i=>a({...t,delay_ms:Number(i.target.value)})})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Duration (ms)"}),e.jsx(s,{type:"number",value:t.duration_ms??5e3,onChange:i=>a({...t,duration_ms:Number(i.target.value)})})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Display order"}),e.jsx(s,{type:"number",value:t.display_order??0,onChange:i=>a({...t,display_order:Number(i.target.value)})})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Rotation weight"}),e.jsx(s,{type:"number",min:0,value:t.rotation_weight??1,onChange:i=>a({...t,rotation_weight:Number(i.target.value)})}),e.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:"Higher = more often when multiple popups compete. 0 excludes."})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs(r,{children:["Start at ",e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"(IST)"})]}),e.jsx(s,{type:"datetime-local",value:f(t.start_at),onChange:i=>a({...t,start_at:_(i.target.value)})})]}),e.jsxs("div",{children:[e.jsxs(r,{children:["End at ",e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"(IST)"})]}),e.jsx(s,{type:"datetime-local",value:f(t.end_at),onChange:i=>a({...t,end_at:_(i.target.value)})})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Active"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"When off, the notification is hidden from visitors."})]}),e.jsx(A,{checked:!!t.is_active,onCheckedChange:i=>a({...t,is_active:i})})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Live preview"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click to replay the slide-in animation."})]}),e.jsx(l,{variant:"outline",size:"sm",onClick:()=>T(i=>i+1),children:"Preview"})]})]}),e.jsxs(R,{children:[e.jsx(l,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(l,{onClick:I,children:"Save"})]})]})}),v>0&&t.title&&e.jsx(F,{title:t.title,description:t.description||void 0,imageUrl:t.image_url||void 0,icon:x?e.jsx(x,{className:"h-5 w-5"}):void 0,ctaLabel:t.cta_label||void 0,ctaHref:t.cta_href||void 0,href:t.href||void 0,delay:300,duration:t.duration_ms??5e3,textColor:t.text_color||void 0,bgColor:t.bg_color||void 0,bgOpacity:t.bg_opacity??void 0},v)]})})]})};export{Bt 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.