import{r as e,h as o}from"./p-083180bf.js";import{k as t,f as a,n as r}from"./p-a7fc1e02.js";import{d as n,H as i,J as d,B as s,F as c,w as l,$ as m,i as g}from"./p-d0993bb9.js";import{c as p}from"./p-c1086930.js";import{g as u}from"./p-9ec99ced.js";import"./p-cef45012.js";import{a as h}from"./p-bab4929e.js";import"./p-044a76f1.js";import{Q as v}from"./p-c0517032.js";const w=n.gql`
  query shareLink($programId: ID, $engagementMedium: UserEngagementMedium!) {
    user: viewer {
      ... on User {
        shareLink(
          programId: $programId
          engagementMedium: $engagementMedium
          shareMedium: DIRECT
        )
      }
    }
  }
`,f=n.gql`
  mutation loadEvent($eventMeta: UserAnalyticsEvent!) {
    createUserAnalyticsEvent(eventMeta: $eventMeta)
  }
`,C=class{constructor(o){e(this,o),this.titleText="Share your QR code",this.viewCodeText="View QR code",this.downloadCodeText="Download",this.printCodeText="Print",this.errorHeaderText="There was an error loading your QR code",this.errorDescriptionText="Please refresh this page and try again",this.hideTitle=!1,this.alignment="center",r(this)}disconnectedCallback(){}render(){const e=u(this),r=g()?function(e){const[o,a]=t(!1);return p({dialogIsOpen:o,hideTitle:e.hideTitle,showDialog:()=>a(!0),hideDialog:()=>a(!1),loading:!0,titleText:e.titleText,viewCodeText:e.viewCodeText,downloadCodeText:e.downloadCodeText,printCodeText:e.printCodeText,alignment:e.alignment,qrLink:"https://media.istockphoto.com/id/1251071788/vector/qr-code-bar-code-black-icon-digital-technology.jpg?s=612x612&w=0&k=20&c=maw4OqMSEegAdSo8Drm9HO7i1ddddvP2YaL1UuWbRig=",fireViewQrEvent:()=>{console.log("View QR Code clicked")},createDownloadable:async()=>{console.log("Download QR Code clicked")},createPrintable:async()=>{console.log("Print QR Code clicked")}},e.demoData||{},{arrayMerge:(e,o)=>o})}(e):function(e){var o;const r=i(),n=d(),g=s(),p=c(h),[u,v]=t(null),[C,R]=t(!1),[q,y]=t(!1),{data:E,loading:b}=l(w,{programId:r,engagementMedium:g},!(null==n?void 0:n.jwt)||void 0!==(null==p?void 0:p.shareLink)),[M]=m(f),k=null===(o=null==E?void 0:E.user)||void 0===o?void 0:o.shareLink,I=`${k}?qrCode`,j=b||q;a((()=>{k&&(async()=>{v(`${k}?qrCode&qrCodeImageFormat=svg&qrCodeQuietZoneSize=0`)})()}),[k]);const Q=async()=>{M({eventMeta:{programId:r,id:null==n?void 0:n.id,accountId:null==n?void 0:n.accountId,type:"USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",meta:{engagementMedium:g,shareMedium:"DIRECT"}}})};return{...e,loading:j,qrLink:u,error:C,createDownloadable:async()=>{try{const e=await fetch(`${I}&qrCodeSize=800&qrCodeImageFormat=png`),o=await e.blob(),t=URL.createObjectURL(o);o&&Q();const a=document.createElement("a");a.href=t,a.download="qrCode.png",document.body.appendChild(a),a.click(),document.body.removeChild(a)}catch(e){console.error("Failed to fetch QR code:",e),R(!0)}},createPrintable:async()=>{try{const e=await fetch(`${I}&qrCodeSize=1000&qrCodeImageFormat=png&qrCodeErrorCorrectionLevel=H`),o=await e.blob(),t=URL.createObjectURL(o);o&&Q();const a=window.open("about:blank","_new"),r=a.document.createElement("img");r.src=t,r.onload=()=>{a.print(),a.close()},a.document.body.appendChild(r)}catch(e){console.error("Failed to fetch QR code: ",e),R(!0)}}}}(e);return o(v,Object.assign({},r))}};export{C as sqm_qr_code}