import{j as e}from"./ui-vendor-CJlQk0Tq.js";import{r as t}from"./react-vendor-f6QdChhz.js";import{Q as a}from"./index-DaofzGsq.js";import{u as n,g as s,h as i,i as o,j as r,B as c,H as l,s as d,be as p,bA as m,dM as h,bB as u,R as x,bg as w,P as g,M as k,bE as b,ff as j,z as C,bz as y,aV as f,al as N}from"./index-BzXujQ-F.js";import{S as v}from"./contact-lI35o84o.js";import{D as T,a as $,b as I,c as R,d as U,h as S}from"./dropdown-menu-sYWqzZq1.js";const P=({open:d,onOpenChange:p,url:m,title:h})=>{const{toast:u}=n(),x=t.useRef(null);return e.jsx(s,{open:d,onOpenChange:p,children:e.jsxs(i,{className:"sm:max-w-md",children:[e.jsx(o,{children:e.jsx(r,{className:"text-center",children:h?`Share: ${h}`:"Share this page"})}),e.jsxs("div",{className:"flex flex-col items-center gap-4 py-4",children:[e.jsx("div",{ref:x,className:"bg-white p-4 rounded-lg shadow-inner",children:e.jsx(a,{value:m,size:200,level:"H",includeMargin:!1})}),e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"Scan with your phone camera to open this page"}),e.jsxs(c,{onClick:()=>{var e;const t=null==(e=x.current)?void 0:e.querySelector("svg");if(!t)return;const a=document.createElement("canvas"),n=a.getContext("2d"),s=(new XMLSerializer).serializeToString(t),i=new Image;a.width=300,a.height=300,i.onload=()=>{null==n||n.drawImage(i,0,0,300,300);const e=a.toDataURL("image/png"),t=document.createElement("a");t.href=e,t.download=`qr-code-${(null==h?void 0:h.toLowerCase().replace(/\s+/g,"-"))||"share"}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t),u({title:"QR Code Downloaded",description:"The QR code has been saved as a PNG image."})},i.src="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(s)))},variant:"outline",className:"gap-2",children:[e.jsx(l,{className:"w-4 h-4"}),"Download QR Code"]})]})]})})},L=({title:a,description:s="",url:i,className:o="",variant:r="default",size:l="default",showText:L=!0,itemNumber:_,pageType:z="general",imageUrl:O,structureType:D})=>{const{toast:M}=n(),{trackShare:A}={trackShare:async e=>{try{await d.from("share_analytics").insert({platform:e.platform,structure_id:e.structureId||null,structure_title:e.structureTitle||null,page_url:e.pageUrl||window.location.href})}catch(t){}}},[E,Q]=t.useState(!1),[B,G]=t.useState(!1),[q,H]=t.useState(!1),F=i||window.location.href,V=a,W=s||a,X=e=>{A({platform:e,structureId:_,structureTitle:a,pageUrl:F})},J="floating"===r?"default":r,K="floating"===r?"bg-primary hover:bg-primary/90 text-white rounded-full shadow-lg hover:scale-105 transition-all duration-300":"";return e.jsxs(T,{open:E,onOpenChange:Q,children:[e.jsx($,{asChild:!0,children:e.jsxs(c,{variant:J,size:"floating"===r?void 0:l,className:`${K} ${o}`,"aria-label":"Share this article",children:[e.jsx(p,{className:"floating"===r?"h-5 w-5":"sm"===l?"h-4 w-4":"h-5 w-5"}),L&&"floating"!==r&&e.jsx("span",{className:"ml-2",children:"Share"})]})}),e.jsxs(I,{align:"end",className:"w-52",children:[navigator.share&&e.jsxs(e.Fragment,{children:[e.jsxs(R,{onClick:async()=>{if(navigator.share)try{await navigator.share({title:V,text:W,url:F}),X("native"),Q(!1)}catch(e){}},className:"cursor-pointer",children:[e.jsx(p,{className:"w-4 h-4 mr-2"}),"Share via Device..."]}),e.jsx(U,{})]}),e.jsx(S,{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Social Networks"}),e.jsxs(R,{onClick:()=>{const e=`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(F)}`;window.open(e,"_blank","width=600,height=400"),X("facebook"),Q(!1)},className:"cursor-pointer",children:[e.jsx(m,{className:"w-4 h-4 mr-2 text-blue-600"}),"Facebook"]}),e.jsxs(R,{onClick:async()=>{try{const{data:e,error:t}=await d.functions.invoke("generate-social-post",{body:{title:V,description:W,itemNumber:_,url:F,pageType:z,structureType:D}});let a=V;(null==e?void 0:e.success)&&(null==e?void 0:e.twitterPostText)&&(a=e.twitterPostText);const n=`https://twitter.com/intent/tweet?text=${encodeURIComponent(a)}&url=${encodeURIComponent(F)}`;window.open(n,"_blank","width=600,height=400"),X("twitter"),Q(!1)}catch(e){const t=`https://twitter.com/intent/tweet?url=${encodeURIComponent(F)}&text=${encodeURIComponent(V)}`;window.open(t,"_blank","width=600,height=400"),X("twitter"),Q(!1)}},className:"cursor-pointer",children:[e.jsx(h,{className:"w-4 h-4 mr-2 text-blue-400"}),"Twitter"]}),e.jsxs(R,{onClick:()=>{const e=`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(F)}`;window.open(e,"_blank","width=600,height=400"),X("linkedin"),Q(!1)},className:"cursor-pointer",children:[e.jsx(u,{className:"w-4 h-4 mr-2 text-blue-700"}),"LinkedIn"]}),e.jsxs(R,{onClick:async()=>{try{const{data:e,error:t}=await d.functions.invoke("generate-social-post",{body:{title:V,description:W,itemNumber:_,url:F,pageType:z,structureType:D}});let a=W;(null==e?void 0:e.success)&&(null==e?void 0:e.pinterestPostText)&&(a=e.pinterestPostText);let n=`https://pinterest.com/pin/create/button/?url=${encodeURIComponent(F)}&description=${encodeURIComponent(a)}`;O&&(n+=`&media=${encodeURIComponent(O)}`),window.open(n,"_blank","width=600,height=400"),X("pinterest"),Q(!1)}catch(e){let t=`https://pinterest.com/pin/create/button/?url=${encodeURIComponent(F)}&description=${encodeURIComponent(V)}`;O&&(t+=`&media=${encodeURIComponent(O)}`),window.open(t,"_blank","width=600,height=400"),X("pinterest"),Q(!1)}},className:"cursor-pointer",children:[e.jsx(x,{className:"w-4 h-4 mr-2 text-red-600"}),"Pinterest"]}),e.jsxs(R,{onClick:()=>{const e=`https://reddit.com/submit?url=${encodeURIComponent(F)}&title=${encodeURIComponent(V)}`;window.open(e,"_blank","width=600,height=400"),X("reddit"),Q(!1)},className:"cursor-pointer",children:[e.jsx(w,{className:"w-4 h-4 mr-2 text-orange-600"}),"Reddit"]}),e.jsx(U,{}),e.jsx(S,{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Direct Message"}),e.jsxs(R,{onClick:()=>{const e=`Check out this ${a}! ${F}`;window.open(`sms:${v}?body=${encodeURIComponent(e)}`,"_self"),X("sms"),Q(!1)},className:"cursor-pointer",children:[e.jsx(g,{className:"w-4 h-4 mr-2 text-green-600"}),"Text Message"]}),e.jsxs(R,{onClick:()=>{const e=`https://wa.me/?text=${encodeURIComponent(`${V} - ${F}`)}`;window.open(e,"_blank","width=600,height=400"),X("whatsapp"),Q(!1)},className:"cursor-pointer",children:[e.jsx(x,{className:"w-4 h-4 mr-2 text-green-500"}),"WhatsApp"]}),e.jsxs(R,{onClick:()=>{const e=`I thought you might be interested in this:\n\n${V}${s?"\n"+s:""}\n\n${F}`,t=`mailto:?subject=${encodeURIComponent(`Check out: ${V}`)}&body=${encodeURIComponent(e)}`;window.location.href=t,X("email"),Q(!1)},className:"cursor-pointer",children:[e.jsx(k,{className:"w-4 h-4 mr-2 text-gray-600"}),"Email"]}),e.jsx(U,{}),e.jsx(S,{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Copy to Clipboard"}),e.jsxs(R,{onClick:async()=>{try{await navigator.clipboard.writeText(F),X("copy-link"),M({title:"Link copied!",description:"The article URL has been copied to your clipboard."}),Q(!1)}catch(e){const t=document.createElement("textarea");t.value=F,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),X("copy-link"),M({title:"Link copied!",description:"The article URL has been copied to your clipboard."}),Q(!1)}},className:"cursor-pointer",children:[e.jsx(b,{className:"w-4 h-4 mr-2"}),"Copy Link"]}),e.jsxs(R,{onClick:()=>{X("qr_code"),G(!0),Q(!1)},className:"cursor-pointer",children:[e.jsx(j,{className:"w-4 h-4 mr-2"}),"QR Code"]}),e.jsxs(R,{onClick:async()=>{H(!0),M({title:"Generating caption...",description:"Creating an Instagram-optimized caption with hashtags."});try{const{data:e,error:t}=await d.functions.invoke("generate-social-post",{body:{title:V,description:W,itemNumber:_,url:F,pageType:z,structureType:D}});let a=F;(null==e?void 0:e.instagramPostText)&&(a=`${e.instagramPostText}\n\n${F}`),await navigator.clipboard.writeText(a),X("instagram"),M({title:"Caption + link copied!",description:"Paste in Instagram - includes hashtags and URL."})}catch(e){await navigator.clipboard.writeText(F),X("instagram"),M({title:"Link copied for Instagram!",description:"Open Instagram and paste the link in your story or post."})}finally{H(!1),Q(!1)}},className:"cursor-pointer",disabled:q,children:[q?e.jsx(C,{className:"w-4 h-4 mr-2 text-purple-600 animate-spin"}):e.jsx(y,{className:"w-4 h-4 mr-2 text-purple-600"}),"Instagram (AI Caption)"]}),e.jsxs(R,{onClick:async()=>{H(!0),M({title:"Generating caption...",description:"Creating a TikTok-optimized caption with hashtags."});try{const{data:e,error:t}=await d.functions.invoke("generate-social-post",{body:{title:V,description:W,itemNumber:_,url:F,pageType:z,structureType:D}});let a=F;(null==e?void 0:e.tiktokPostText)&&(a=`${e.tiktokPostText}\n\n${F}`),await navigator.clipboard.writeText(a),X("tiktok"),M({title:"Caption + link copied!",description:"Paste in TikTok - includes hashtags and URL."})}catch(e){await navigator.clipboard.writeText(F),X("tiktok"),M({title:"Link copied for TikTok!",description:"Open TikTok and paste the link in your video description."})}finally{H(!1),Q(!1)}},className:"cursor-pointer",disabled:q,children:[q?e.jsx(C,{className:"w-4 h-4 mr-2 text-black animate-spin"}):e.jsx(f,{className:"w-4 h-4 mr-2 text-black"}),"TikTok (AI Caption)"]}),e.jsxs(R,{onClick:async()=>{H(!0),M({title:"Generating caption...",description:"Creating a universal caption with hashtags."});try{const{data:e,error:t}=await d.functions.invoke("generate-social-post",{body:{title:V,description:W,itemNumber:_,url:F,pageType:z,structureType:D}});let a=F;(null==e?void 0:e.genericPostText)&&(a=`${e.genericPostText}\n\n${F}`),await navigator.clipboard.writeText(a),X("generic-caption"),M({title:"Caption + link copied!",description:"Paste on Threads, BeReal, Bluesky, or any platform."})}catch(e){await navigator.clipboard.writeText(F),X("generic-caption"),M({title:"Link copied!",description:"Open your preferred platform and paste."})}finally{H(!1),Q(!1)}},className:"cursor-pointer",disabled:q,children:[q?e.jsx(C,{className:"w-4 h-4 mr-2 text-purple-500 animate-spin"}):e.jsx(N,{className:"w-4 h-4 mr-2 text-purple-500"}),"AI Caption + Link"]})]}),e.jsx(P,{open:B,onOpenChange:G,url:F,title:V})]})};export{L as S};