1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/qr-code-styling-qEM6xCUA.js","assets/jsx-runtime-kF-aRxYe.js"])))=>i.map(i=>d[i]); 2import{_ as as,S as is}from"./preload-helper-5-obDp7m.js";import{R as b,r,j as e}from"./jsx-runtime-kF-aRxYe.js";import{H as Oo}from"./HelpButton-N4iO3c3k.js";import{u as Wo,d as Qo,e as Bo,f as Go,b as zo,a as Ho}from"./components-CSHUtzmt.js";import{F as Vo,T as Yo}from"./Toast-BwCc1jBO.js";import{P as Zo,C as te,a as ls,A as Jo,T as qr}from"./Page-CddT1F_F.js";import{L as de}from"./Layout-DiCbQo8Q.js";import{T as $r}from"./Tabs-D2Cclvpv.js";import{B as Ve}from"./Banner-DCLqbZgI.js";import{T as i,q as Br,j as cr,b as j,t as Xo,v as Ko,d as lr,B as S,I as B,a as Z,c as X,f as ea,g as cs,e as ds}from"./components-DP1wKgXB.js";import{S as Fr}from"./ImportIcon.svg-BqqBJJhj.js";import{D as $e}from"./Divider-B4k2WAbA.js";import{S as us}from"./Select-B1ULropN.js";import{T as ta}from"./Tag-CJZ_dJJG.js";import{I as ra}from"./Image-DSDlm4cs.js";import{S as ir}from"./ClipboardIcon.svg-BQKyE9tk.js";import{S as na}from"./LinkIcon.svg-ComnPtCJ.js";import{M as Le}from"./Modal-3tWrutKv.js";import{D as hs}from"./DropZone-DlSc-dZa.js";import{C as ms}from"./Checkbox-CHHREvb3.js";import{E as ps}from"./EmptyState-mJHciNFx.js";import{I as ue}from"./IndexTable-B7N4mB9m.js";import{S as sa}from"./EditIcon.svg-KdZqT_l7.js";import{S as oa}from"./ExportIcon.svg-Cf26VJyf.js";import{D as aa}from"./DataTable-QhhMVdsS.js";import"./HelpContext-4hSThiYJ.js";import"./browser-CUo-fxFH.js";import"./set-root-property-BAPp4t5F.js";import"./CSSTransition-x_kELu2F.js";import"./XIcon.svg-Br6A-429.js";import"./index-Dm6-7Kuv.js";import"./FormLayout-DLDIJEjW.js";import"./InfoIcon.svg-DKxf2q_E.js";import"./context-DqE-dl7J.js";import"./InlineGrid-BGRTJnde.js";import"./Sticky-CduOJVK0.js";var Cs=function(s){return b.createElement("svg",Object.assign({viewBox:"0 0 20 20"},s),b.createElement("path",{fillRule:"evenodd",d:"M3.5 10a.75.75 0 0 1 .75-.75h9.69l-2.72-2.72a.75.75 0 1 1 1.06-1.06l4 4a.75.75 0 0 1 0 1.06l-4 4a.75.75 0 0 1-1.06-1.06l2.72-2.72h-9.69a.75.75 0 0 1-.75-.75Z"}))};Cs.displayName="ArrowRightIcon";var Ss=function(s){return b.createElement("svg",Object.assign({viewBox:"0 0 20 20"},s),b.createElement("path",{fillRule:"evenodd",d:"M7.75 3.5a.75.75 0 0 0-1.5 0v.407a3.075 3.075 0 0 0-.702.252 3.75 3.75 0 0 0-1.64 1.639c-.226.444-.32.924-.365 1.47-.043.531-.043 1.187-.043 2v1.464c0 .813 0 1.469.043 2 .045.546.14 1.026.366 1.47a3.75 3.75 0 0 0 1.639 1.64c.444.226.924.32 1.47.365.531.043 1.187.043 2 .043h3.383c.323 0 .542 0 .735-.02a3.75 3.75 0 0 0 3.344-3.344c.02-.193.02-.412.02-.735v-2.883c0-.813 0-1.469-.043-2-.045-.546-.14-1.026-.366-1.47a3.75 3.75 0 0 0-1.639-1.64 3.076 3.076 0 0 0-.702-.251v-.407a.75.75 0 0 0-1.5 0v.259c-.373-.009-.794-.009-1.268-.009h-1.964c-.474 0-.895 0-1.268.009v-.259Zm-1.521 1.995c.197-.1.458-.17.912-.207.462-.037 1.057-.038 1.909-.038h1.9c.853 0 1.447 0 1.91.038.453.037.714.107.912.207.423.216.767.56.983.984.1.197.17.458.207.912.014.18.024.38.029.609h-9.982c.006-.228.015-.429.03-.61.036-.453.106-.714.206-.911a2.25 2.25 0 0 1 .984-.984Zm-1.229 4.005v1.2c0 .853 0 1.447.038 1.91.037.453.107.714.207.912.216.423.56.767.984.983.197.1.458.17.912.207.462.037 1.057.038 1.909.038h3.306c.385 0 .52-.001.626-.012a2.25 2.25 0 0 0 2.006-2.006c.011-.106.012-.241.012-.626v-2.606h-10Z"}))};Ss.displayName="CalendarIcon";var ks=function(s){return b.createElement("svg",Object.assign({viewBox:"0 0 20 20"},s),b.createElement("path",{d:"M13 8a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"}),b.createElement("path",{fillRule:"evenodd",d:"M11.276 3.5a3.75 3.75 0 0 0-2.701 1.149l-4.254 4.417a2.75 2.75 0 0 0 .036 3.852l2.898 2.898a2.5 2.5 0 0 0 3.502.033l4.747-4.571a3.25 3.25 0 0 0 .996-2.341v-2.187a3.25 3.25 0 0 0-3.25-3.25h-1.974Zm-1.62 2.19a2.25 2.25 0 0 1 1.62-.69h1.974c.966 0 1.75.784 1.75 1.75v2.187c0 .475-.194.93-.536 1.26l-4.747 4.572a1 1 0 0 1-1.401-.014l-2.898-2.898a1.25 1.25 0 0 1-.016-1.75l4.253-4.418Z"}))};ks.displayName="ProductIcon";const ia=7;function la(a,s,l=0){const d=new Date(s,a,1),w=d.getDay(),T=[[]];let x=T[0],R=d;const u=js(l);for(let p=0;p<u.indexOf(w);p++)x.push(null);for(;R.getMonth()===a;)x.length===ia&&(x=[],T.push(x)),x.push(R),R=new Date(s,a,R.getDate()+1);for(;x.length<7;)x.push(null);return T}function ca(a,s){if(a==null)return!1;const{start:l,end:d}=s;return!!(l&&a>l&&d&&a<d)}function da(a,s){if(a==null)return!1;const{start:l,end:d}=s;return!!(l&&he(l,a)||d&&he(d,a))}function he(a,s){return a.getDate()===s.getDate()&&a.getMonth()===s.getMonth()&&a.getFullYear()===s.getFullYear()}function ua(a,s){if(a==null)return{start:s,end:s};const{start:l,end:d}=a;return d&&(St(l,d)||Fe(l,d))?{start:s,end:s}:l?Fe(s,l)?{start:s,end:s}:{start:l,end:s}:d?Fe(s,d)?{start:s,end:d}:{start:l||d,end:s}:{start:s,end:s}}function fs(a){return a===11?0:a+1}function gs(a,s){return a===11?s+1:s}function ha(a){return a===0?11:a-1}function ma(a,s){return a===0?s-1:s}function St(a,s){return a.getTime()>s.getTime()}function Fe(a,s){return a.getTime()<s.getTime()}function bt(a,s){return s.some(l=>a.getTime()===l.getTime())}const pa=[0,1,2,3,4,5,6];function js(a){const s=[...pa];return[...s.splice(a),...s]}function Ct(a){switch(a){case 0:return"january";case 1:return"february";case 2:return"march";case 3:return"april";case 4:return"may";case 5:return"june";case 6:return"july";case 7:return"august";case 8:return"september";case 9:return"october";case 10:return"november";case 11:return"december"}}function xs(a){switch(a){case 0:return"sunday";case 1:return"monday";case 2:return"tuesday";case 3:return"wednesday";case 4:return"thursday";case 5:return"friday";case 6:return"saturday"}}var M={DatePicker:"Polaris-DatePicker",MonthLayout:"Polaris-DatePicker__MonthLayout",MonthContainer:"Polaris-DatePicker__MonthContainer",Month:"Polaris-DatePicker__Month",DayCell:"Polaris-DatePicker__DayCell","DayCell-inRange":"Polaris-DatePicker__DayCell--inRange",Day:"Polaris-DatePicker__Day","Day-inRange":"Polaris-DatePicker__Day--inRange","Day-selected":"Polaris-DatePicker__Day--selected","Day-disabled":"Polaris-DatePicker__Day--disabled",EmptyDayCell:"Polaris-DatePicker__EmptyDayCell",Weekday:"Polaris-DatePicker__Week
2day",Header:"Polaris-DatePicker__Header",Title:"Polaris-DatePicker__Title","Day-firstInRange":"Polaris-DatePicker__Day--firstInRange","Day-hasRange":"Polaris-DatePicker__Day--hasRange","Day-hoverRight":"Polaris-DatePicker__Day--hoverRight","Day-lastInRange":"Polaris-DatePicker__Day--lastInRange",Week:"Polaris-DatePicker__Week"};const fa=r.memo(function({label:s,title:l,current:d}){return b.createElement("th",{"aria-label":s,scope:"col",className:M.Weekday},b.createElement(i,{as:"span",variant:"bodySm",alignment:"center",fontWeight:d?"bold":"regular",tone:d?void 0:"subdued"},l))}),ys=r.memo(function({day:s,focused:l,onClick:d,onHover:w=Nr,onFocus:T=Nr,selected:x,inRange:R,inHoveringRange:u,disabled:p,lastDayOfMonth:Q,isLastSelectedDay:k,isFirstSelectedDay:J,isHoveringRight:z,rangeIsDifferent:o,weekday:E,selectedAccessibilityLabelPrefix:H}){const P=Br(),h=r.useRef(null),D=Q||s;if(r.useEffect(()=>{l&&h.current&&h.current.focus()},[l]),!s)return b.createElement("td",{className:M.EmptyDayCell,onMouseOver:()=>w(D)});const G=d&&!p?d.bind(null,s):Nr,V=he(new Date,s),F=cr(M.DayCell,x&&M["DayCell-selected"],(R||u)&&!p&&M["DayCell-inRange"],k&&M["DayCell-lastInRange"],J&&M["DayCell-firstInRange"],z&&M["DayCell-hoverRight"],o&&M["DayCell-hasRange"]),je=cr(M.Day,x&&M["Day-selected"],p&&M["Day-disabled"],(R||u)&&!p&&M["Day-inRange"],k&&M["Day-lastInRange"],J&&M["Day-firstInRange"],z&&M["Day-hoverRight"],o&&M["Day-hasRange"]),K=s.getDate(),v=(l||x||V||K===1)&&!p?0:-1,ie=[x&&H?`${H} `:"",`${V?P.translate("Polaris.DatePicker.today"):""}`,`${E||""} `,`${P.translate(`Polaris.DatePicker.months.${Ct(s.getMonth())}`)} `,`${K} `,`${s.getFullYear()}`].join("");return b.createElement("td",{className:F},b.createElement("button",{onFocus:()=>T(s),type:"button",ref:h,tabIndex:v,className:je,onMouseOver:()=>w(D),onClick:G,"aria-label":ie,"aria-disabled":p,"aria-pressed":x},b.createElement(i,{as:"span",variant:"bodySm",alignment:"center",fontWeight:V?"bold":"regular"},K)))});function Nr(){}function vs({focusedDate:a,selected:s,hoverDate:l,disableDatesBefore:d,disableDatesAfter:w,disableSpecificDates:T,allowRange:x,onChange:R=Or,onHover:u=Or,onFocus:p=Or,month:Q,year:k,weekStartsOn:J,accessibilityLabelPrefixes:z}){const o=Br(),E=x?ga:()=>!1,H=new Date,P=H.getMonth()===Q&&H.getFullYear()===k,h=r.useMemo(()=>la(Q,k,J),[Q,J,k]),D=js(J).map(v=>b.createElement(fa,{key:v,title:o.translate(`Polaris.DatePicker.daysAbbreviated.${xs(v)}`),label:K(v),current:P&&new Date().getDay()===v})),G=r.useCallback(v=>{R(ua(x?s:void 0,v))},[x,R,s]),V=r.useMemo(()=>new Date(k,Q+1,0),[Q,k]);function F(v,ie){if(v==null)return b.createElement(ys,{key:ie,onHover:u,lastDayOfMonth:V});const Ne=d&&Fe(v,d)||w&&St(v,w)||T&&bt(v,T),De=x&&s&&ya(v,s),Ee=x&&s&&(!he(s.start,s.end)&&xa(v,s)||l&&he(s.start,s.end)&&St(l,s.start)&&he(v,l)&&!De),Oe=!(s&&he(s.start,s.end)),Ye=l&&Fe(v,l),[we,Ze]=z;let Ie;return x&&De||!x&&we?Ie=we:x&&Ee&&(Ie=Ze),b.createElement(ys,{selectedAccessibilityLabelPrefix:Ie,weekday:K(ie),focused:a!=null&&he(v,a),day:v,key:ie,onFocus:p,onClick:G,onHover:u,selected:s!=null&&da(v,s),inRange:s!=null&&ca(v,s),disabled:Ne,inHoveringRange:s!=null&&l!=null&&E(v,s,l),isLastSelectedDay:Ee,isFirstSelectedDay:De,isHoveringRight:Ye,rangeIsDifferent:Oe})}const je=h.map((v,ie)=>b.createElement("tr",{className:M.Week,key:ie},v.map(F)));return b.createElement("div",{className:M.MonthContainer},b.createElement("table",{role:"grid",className:M.Month},b.createElement("caption",{className:M.Title},b.createElement(i,{as:"span",variant:"bodyMd",alignment:"center",fontWeight:P?"bold":"medium"},o.translate(`Polaris.DatePicker.months.${Ct(Q)}`)," ",k)),b.createElement("thead",null,b.createElement("tr",{className:M.WeekHeadings},D)),b.createElement("tbody",null,je)));function K(v){return o.translate(`Polaris.DatePicker.days.${xs(v)}`)}}function Or(){}function ga(a,s,l){if(a==null)return!1;const{start:d,end:w}=s;return!!(he(d,w)&&a>d&&a<=l)}function xa(a,s){if(a==null)return!1;const{end:l}=s;return!!(l&&he(l,a))}function ya(a,s){if(a==null)return!1;const{start:l}=s;return!!(l&&he(l,a))}function va({id:a,selected:s,month:l,year:d,allowRange:w,multiMonth:T,disableDatesBefore:x,disableDatesAfter:R,disableSpecificDates:u,weekStartsOn:p=0,dayAccessibilityLabelPrefix:Q,onMonthChange:k,onChange:J=ba}){const z=Br(),[o,E]=r.useState(void 0),[H,P]=r.useState(void 0);r.useEffect(()=>{P(void 0)},[s]);const h=r.useCallback(N=>{P(N)},[]),D=r.useCallback(N=>{k&&k(N.getMonth(),N.getFullYear()),E(N),P(N)},[k]),G=r.useCallback(N=>{const{end:se}=N;E(se),P(new Date(se)),J(N)},[J]),V=r.useCallback((N,se)=>{k&&(P(void 0),k(N,se))},[k]),F=r.useCallback(N=>{E(N)},[]),je=r.useCallback(N=>{const{key:se}=N,re=Wr(s),oe=H||re&&re.start;if(oe!=null){if(se==="ArrowUp"){const I=new Date(oe);I.setDate(oe.getDate()-7),x&&Fe(I,x)||u&&bt(I,u)||D(I)}if(se==="ArrowDown"){const I=new Date(oe);
2I.setDate(oe.getDate()+7),R&&St(I,R)||u&&bt(I,u)||D(I)}if(se==="ArrowRight"){const I=new Date(oe);I.setDate(oe.getDate()+1),R&&St(I,R)||u&&bt(I,u)||D(I)}if(se==="ArrowLeft"){const I=new Date(oe);I.setDate(oe.getDate()-1),x&&Fe(I,x)||u&&bt(I,u)||D(I)}}},[R,x,u,H,s,D]),K=gs(l,d),v=fs(l),ie=gs(v,K),Ne=fs(v),De=ma(l,d),Ee=ha(l),Oe=z.translate(`Polaris.DatePicker.months.${Ct(Ee)}`),Ye=T?z.translate(`Polaris.DatePicker.months.${Ct(Ne)}`):z.translate(`Polaris.DatePicker.months.${Ct(v)}`),we=T?ie:K,Ze=r.useMemo(()=>Wr(s),[s]),Ie=w?z.translate("Polaris.DatePicker.start"):Q,Je=z.translate("Polaris.DatePicker.end"),kt=[Ie,Je],Xe=T?b.createElement(vs,{onFocus:h,focusedDate:H,month:v,year:K,selected:Ze,hoverDate:o,onChange:G,onHover:F,disableDatesBefore:x,disableDatesAfter:R,disableSpecificDates:u,allowRange:w,weekStartsOn:p,accessibilityLabelPrefixes:kt}):null,be=cr(M.DatePicker);return b.createElement("div",{id:a,className:be,onKeyDown:Ca,onKeyUp:je},b.createElement("div",{className:M.Header},b.createElement(j,{variant:"tertiary",icon:Xo,accessibilityLabel:z.translate("Polaris.DatePicker.previousMonth",{previousMonthName:Oe,showPreviousYear:De}),onClick:()=>V(Ee,De)}),b.createElement(j,{variant:"tertiary",icon:Cs,accessibilityLabel:z.translate("Polaris.DatePicker.nextMonth",{nextMonth:Ye,nextYear:we}),onClick:()=>V(v,K)})),b.createElement("div",{className:M.MonthLayout},b.createElement(vs,{onFocus:h,focusedDate:H,month:l,year:d,selected:Wr(s),hoverDate:o,onChange:G,onHover:F,disableDatesBefore:x,disableDatesAfter:R,disableSpecificDates:u,allowRange:w,weekStartsOn:p,accessibilityLabelPrefixes:kt}),Xe))}function ba(){}function Ca(a){const{key:s}=a;(s==="ArrowUp"||s==="ArrowDown"||s==="ArrowLeft"||s==="ArrowRight")&&(a.preventDefault(),a.stopPropagation())}function Wr(a){return a instanceof Date?{start:a,end:a}:a}var Qr={Thumbnail:"Polaris-Thumbnail",sizeExtraSmall:"Polaris-Thumbnail--sizeExtraSmall",sizeSmall:"Polaris-Thumbnail--sizeSmall",sizeMedium:"Polaris-Thumbnail--sizeMedium",sizeLarge:"Polaris-Thumbnail--sizeLarge",transparent:"Polaris-Thumbnail--transparent"};function Sa({source:a,alt:s,size:l="medium",transparent:d}){const w=cr(Qr.Thumbnail,l&&Qr[Ko("size",l)],d&&Qr.transparent),T=typeof a=="string"?b.createElement(ra,{alt:s,source:a}):b.createElement(lr,{accessibilityLabel:s,source:a});return b.createElement("span",{className:w},T)}const ka=new Proxy({},{get(a,s){throw Error(`shopify.${String(s)} can't be used in a server environment. You likely need to move this code into an Effect.`)}});function ja(){if(typeof window>"u")return ka;if(!window.shopify)throw Error("The shopify global is not defined. This likely means the App Bridge script tag was not added correctly to this page");return window.shopify}function bs(a){const s=[];let l="",d=!1;for(let w=0;w<a.length;w++){const T=a[w];T==='"'?d&&a[w+1]==='"'?(l+='"',w++):d=!d:T===","&&!d?(s.push(l.trim().replace(/^["']|["']$/g,"")),l=""):l+=T}return s.push(l.trim().replace(/^["']|["']$/g,"")),s}const Da=[{label:"Last 7 days",value:"7d"},{label:"Last 14 days",value:"14d"},{label:"Last 30 days",value:"30d"},{label:"Last 60 days",value:"60d"},{label:"Last 90 days",value:"90d"},{label:"Last 12 months",value:"12m"},{label:"All time",value:"all"}];function wa({data:a,metric:s,color:l="#5c6ac4"}){var P;if(!a||a.length===0)return e.jsx("div",{style:{height:"300px",display:"flex",alignItems:"center",justifyContent:"center",color:"#888"},children:"No data available"});const d=a.map(h=>{switch(s){case"revenue":return h.revenue;case"users":return h.users;case"conversionRate":return h.users>0?h.conversions/h.users*100:0;case"revenuePerSession":return h.users>0?h.revenue/h.users:0;case"aov":return h.conversions>0?h.revenue/h.conversions:0;default:return 0}}),w=Math.max(...d,1),T=Math.min(...d,0),x=w-T||1,R=800,u=300,p={top:20,right:20,bottom:40,left:80},Q=R-p.left-p.right,k=u-p.top-p.bottom,J=d.map((h,D)=>{const G=p.left+D/(d.length-1||1)*Q,V=p.top+k-(h-T)/x*k;return{x:G,y:V}}),z=J.map((h,D)=>`${D===0?"M":"L"} ${h.x} ${h.y}`).join(" "),o=`${z} L ${((P=J[J.length-1])==null?void 0:P.x)||p.left} ${p.top+k} L ${p.left} ${p.top+k} Z`,E=h=>s==="revenue"||s==="revenuePerSession"||s==="aov"?`$${h.toLocaleStr
2ing(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`:s==="conversionRate"?`${h.toFixed(1)}%`:h.toLocaleString(),H=[0,.25,.5,.75,1].map(h=>T+h*x);return e.jsx("div",{style:{width:"100%"},children:e.jsxs("svg",{viewBox:`0 0 ${R} ${u}`,style:{width:"100%",height:"auto"},children:[H.map((h,D)=>{const G=p.top+k-D/4*k;return e.jsxs("g",{children:[e.jsx("line",{x1:p.left,y1:G,x2:R-p.right,y2:G,stroke:"#e5e7eb",strokeDasharray:"4"}),e.jsx("text",{x:p.left-10,y:G+4,textAnchor:"end",fontSize:"11",fill:"#666",children:E(h)})]},D)}),e.jsx("path",{d:o,fill:l,fillOpacity:"0.2"}),e.jsx("path",{d:z,fill:"none",stroke:l,strokeWidth:"2"}),J.map((h,D)=>e.jsx("circle",{cx:h.x,cy:h.y,r:"4",fill:l},D)),a.filter((h,D)=>D%Math.ceil(a.length/7)===0||D===a.length-1).map((h,D)=>{const G=a.indexOf(h),V=p.left+G/(d.length-1||1)*Q;return e.jsx("text",{x:V,y:u-10,textAnchor:"middle",fontSize:"11",fill:"#666",children:new Date(h.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})},D)})]})})}function pi(){const{shopDomain:a,links:s,qrCodes:l,chartData:d,influencerBreakdown:w,sourceBreakdown:T,mediumBreakdown:x,codeBreakdown:R,totals:u,dateRange:p,customStartDate:Q,customEndDate:k,initialTab:J,appUrl:z}=Wo(),o=Qo(),E=Bo(),H=Go(),P=zo(),[h]=Ho(),D=H.state==="submitting",G=parseInt(h.get("tab")||"0",10),V=isNaN(G)?0:Math.min(Math.max(G,0),2),[F,je]=r.useState(V);r.useEffect(()=>{je(V)},[V]);const K=r.useCallback(t=>{je(t);const n=new URLSearchParams(h);n.set("tab",String(t)),P(`/app/promo-links?${n.toString()}`,{replace:!0})},[P,h]),v=r.useMemo(()=>[{id:"create",content:"Create Promo Link",panelID:"create-panel"},{id:"history",content:"Link History",panelID:"history-panel"},{id:"performance",content:"Performance",panelID:"performance-panel"}],[]),[ie,Ne]=r.useState(!1),[De,Ee]=r.useState(""),[Oe,Ye]=r.useState(!1),we=r.useCallback((t,n=!1)=>{Ee(t),Ye(n),Ne(!0)},[]),Ze=r.useCallback(()=>Ne(!1),[]);r.useEffect(()=>{o!=null&&o.success?we(o.message||"Link updated successfully"):o!=null&&o.error&&we(o.error,!0)},[o,we]);const[Ie,Je]=r.useState(!1),[kt,Xe]=r.useState(!1),[be,N]=r.useState(null),[se,re]=r.useState(null),[oe,I]=r.useState(null),[Ds,Ae]=r.useState(!1),[dr,ws]=r.useState(!0),[ur,Ps]=r.useState(!0),hr=r.useRef(!1),Gr=r.useCallback(()=>{Je(t=>!t)},[]),zr=r.useCallback(()=>{const t=["discount_code","influencer_name","discount_amount","discount_type","utm_source","utm_medium","redirect_path","short_path"],n=["SUMMER20","John Doe","20","percent","John Doe","Instagram","/collections/sale","johndoe"],f=[t.join(","),n.join(",")].join(` 3`),m=new Blob([f],{type:"text/csv;charset=utf-8;"}),_=URL.createObjectURL(m),g=document.createElement("a");g.setAttribute("href",_),g.setAttribute("download","promo_links_template.csv"),document.body.appendChild(g),g.click(),document.body.removeChild(g),URL.revokeObjectURL(_),Je(!1)},[]),Ts=r.useCallback(()=>{Je(!1),Xe(!0),N(null),re(null)},[]),Hr=r.useCallback(()=>{Xe(!1),N(null),re(null)},[]),Rs=r.useCallback((t,n,f)=>{n.length>0&&(N(n[0]),re(null))},[]),Ms=r.useCallback(async()=>{if(be){Ae(!0),re(null);try{const n=(await be.text()).split(/\r?\n/).filter(A=>A.trim());if(n.length<2){re("CSV file must have a header row and at least one data row."),Ae(!1);return}const f=bs(n[0]).map(A=>A.trim().toLowerCase().replace(/['"]/g,"")),_=["discount_code","influencer_name","discount_amount","discount_type","utm_source","utm_medium"].filter(A=>!f.includes(A));if(_.length>0){re(`Missing required columns: ${_.join(", ")}`),Ae(!1);return}const g=n.slice(1),C=[];for(const A of g){const c=bs(A),L={};f.forEach((y,q)=>{L[y]=(c[q]||"").trim()}),!(!L.discount_code||!L.influencer_name||!L.discount_amount||!L.discount_type||!L.utm_source||!L.utm_medium)&&C.push(L)}if(C.length===0){re("No valid rows found in the CSV file."),Ae(!1);return}if(C.length>200){re("Please import 200 or fewer links at a time."),Ae(!1);return}const ye=new FormData;ye.set("actionType","csvImport"),ye.set("rows",JSON.stringify(C)),ye.set("createShortlinks",dr?"true":"false"),ye.set("dedupeByShortlink",ur?"true":"false"),hr.current=!0,E(ye,{method:"post"})}catch(t){re(t.message||"Failed to process CSV file."),Ae(!1)}}},[be,dr,ur,E]),mr=r.useRef(!1);r.useEffect(()=>{if(hr.current){if(H.state!=="idle"){mr.current=!0;return}mr.current&&(mr.current=!1,hr.current=!1,Ae(!1),o!=null&&o.csvImported?(Xe(!1),N(null),o.message&&(I(o.message),setTimeout(()=>I(null),8e3))):o!=null&&o.error&&re(o.error))}},[H.state,o]);const[Ce,Vr]=r.useState(""),[ae,Yr]=r.useState(""),[We,Zr]=r.useState(""),[Ke,Jr]=r.useState("percent"),[Qe,Xr]=r.useState(""),[Be,
3Kr]=r.useState(""),[jt,en]=r.useState(""),[tn,et]=r.useState(!1),[rn,tt]=r.useState(!1),[nn,rt]=r.useState(!1),[U,sn]=r.useState(!1),[me,pr]=r.useState(""),on=r.useRef(null),an=r.useRef(null),[Ls,fr]=r.useState(!1),[Pa,ln]=r.useState(""),cn=ja(),[Pe,gr]=r.useState(!1),[pe,xr]=r.useState(!1),[le,nt]=r.useState([]),st=Pe||pe,Es=r.useCallback(t=>{gr(t),t?xr(!1):pe||nt([])},[pe]),Is=r.useCallback(t=>{xr(t),t?gr(!1):Pe||nt([])},[Pe]),As=r.useCallback(async()=>{try{const t=await cn.resourcePicker({type:"product",action:"select",multiple:!0,selectionIds:le.map(n=>({id:n.id}))});t&&nt(t.map(n=>({id:n.id,title:n.title,handle:n.handle,images:n.images||[],variants:n.variants||[]})))}catch(t){console.error("Error selecting products:",t)}},[cn,le]),Us=r.useCallback(t=>{nt(n=>n.filter(f=>f.id!==t))},[]),dn=[{label:"Percent Off",value:"percent"},{label:"Fixed Amount",value:"fixed"}],yr=Ce&&ae&&We&&Qe&&Be,vr=jt.trim()||"/",br=encodeURIComponent(vr.startsWith("/")?vr:`/${vr}`),un=r.useCallback(()=>{if(!st||le.length===0)return null;const t=le.filter(n=>n.variants&&n.variants.length>0).map(n=>`${n.variants[0].id.split("/").pop()}:1`);return t.length===0?null:`/cart/${t.join(",")}`},[st,le]),ee=r.useMemo(()=>{if(!yr)return"";const t=`utm_source=${encodeURIComponent(Qe)}&utm_medium=${encodeURIComponent(Be)}&amount=${encodeURIComponent(We)}&type=${Ke}&name=${encodeURIComponent(ae)}&discount=${encodeURIComponent(Ce)}`,n=un();if(n&&st&&le.length>0)if(pe){const f=encodeURIComponent(`/discount/${encodeURIComponent(Ce)}?redirect=${encodeURIComponent("/")}&${t}&openCart=1`);return`https://${a}${n}?${t}&redirect=${f}`}else{const f=encodeURIComponent(`/discount/${encodeURIComponent(Ce)}?redirect=${br}&${t}`);return`https://${a}${n}?${t}&redirect=${f}`}return`https://${a}/discount/${encodeURIComponent(Ce)}?redirect=${br}&${t}`},[yr,a,Ce,br,Qe,Be,We,Ke,ae,un,st,pe,le.length]),Dt=me?`https://${a}/${me}`:"";r.useEffect(()=>{ae&&pr(ae.replace(/\s+/g,"").toLowerCase())},[ae]),r.useEffect(()=>{o!=null&&o.success&&(o!=null&&o.generatedUrl)&&(sn(!0),setTimeout(()=>{var t;(t=on.current)==null||t.scrollIntoView({behavior:"smooth",block:"start"})},100))},[o]),r.useEffect(()=>{o!=null&&o.shortlinkCreated&&(o!=null&&o.shortlinkUrl)&&setTimeout(()=>{var t;(t=an.current)==null||t.scrollIntoView({behavior:"smooth",block:"center"})},100)},[o==null?void 0:o.shortlinkCreated,o==null?void 0:o.shortlinkUrl]);const _s=r.useCallback(()=>{const t=new FormData;t.set("actionType","generateLink"),t.set("discountCode",Ce),t.set("influencerName",ae),t.set("discountAmount",We),t.set("discountType",Ke),t.set("utmSource",Qe),t.set("utmMedium",Be),t.set("redirectPath",jt);const n=Pe?"checkout":pe?"cart":"discount";t.set("linkType",n),E(t,{method:"post"})},[Ce,ae,We,Ke,Qe,Be,jt,Pe,pe,E]),Cr=r.useCallback((t=!1)=>{if(!ee)return;const n=new FormData;n.set("actionType","createRedirect"),n.set("shortPath",me),n.set("targetUrl",ee),t&&n.set("forceOverwrite","true"),E(n,{method:"post"})},[me,ee,E]),qs=r.useCallback(()=>{fr(!1),Cr(!0)},[Cr]),hn=r.useCallback(()=>{fr(!1),ln("")},[]),$s=r.useCallback(async()=>{if(ee)try{await navigator.clipboard.writeText(ee),et(!0),setTimeout(()=>et(!1),2e3)}catch{const n=document.createElement("textarea");n.value=ee,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),et(!0),setTimeout(()=>et(!1),2e3)}},[ee]),Fs=r.useCallback(async()=>{if(Dt)try{await navigator.clipboard.writeText(Dt),rt(!0),setTimeout(()=>rt(!1),2e3)}catch{const n=document.createElement("textarea");n.value=Dt,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),rt(!0),setTimeout(()=>rt(!1),2e3)}},[Dt]),Ns=r.useCallback(async()=>{if(o!=null&&o.shortlinkUrl)try{await navigator.clipboard.writeText(o.shortlinkUrl),tt(!0),setTimeout(()=>tt(!1),2e3)}catch{const n=document.createElement("textarea");n.value=o.shortlinkUrl,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),tt(!0),setTimeout(()=>tt(!1),2e3)}},[o==null?void 0:o.shortlinkUrl]),Os=r.useCallback(()=>{Vr(""),Yr(""),Zr(""),Jr("percent"),Xr(""),Kr(""),en(""),pr(""),sn(!1),et(!1),tt(!1),rt(!1),gr(!1),xr(!1),nt([]),P("/app/promo-links?tab=0",{replace:!0})},[P]),mn=r.useCallback(()=>
3{if(ee){const t=ae?`${ae} QR Code`:"";P(`/app/qr-codes?tab=0&url=${encodeURIComponent(ee)}&name=${encodeURIComponent(t)}`)}else P("/app/qr-codes?tab=0")},[ee,ae,P]),[wt,Pt]=r.useState(null),[Ge,pn]=r.useState(""),[Ws,fn]=r.useState(!1),ot=r.useMemo(()=>{if(!Ge)return s;const t=Ge.toLowerCase();return s.filter(n=>n.influencerName.toLowerCase().includes(t)||n.discountCode.toLowerCase().includes(t)||n.utmSource&&n.utmSource.toLowerCase().includes(t)||n.utmMedium&&n.utmMedium.toLowerCase().includes(t))},[s,Ge]),gn=r.useCallback(async(t,n)=>{try{await navigator.clipboard.writeText(t),Pt(n),setTimeout(()=>Pt(null),2e3)}catch{const m=document.createElement("textarea");m.value=t,document.body.appendChild(m),m.select(),document.execCommand("copy"),document.body.removeChild(m),Pt(n),setTimeout(()=>Pt(null),2e3)}},[]),[Qs,Sr]=r.useState(!1),[Y,kr]=r.useState(null),[Tt,xn]=r.useState(""),[Rt,yn]=r.useState(""),[Mt,vn]=r.useState(""),[jr,bn]=r.useState("percent"),[Lt,Cn]=r.useState(""),[Et,Sn]=r.useState(""),[Dr,kn]=r.useState(""),[wr,jn]=r.useState(""),Bs=r.useCallback(t=>{kr(t),xn(t.discountCode||""),yn(t.influencerName||""),vn(t.discountAmount||""),bn(t.discountType||"percent"),Cn(t.utmSource||""),Sn(t.utmMedium||"");let n="";try{const m=new URL(t.generatedUrl).searchParams.get("redirect");m&&m!=="/"&&(n=m)}catch{}kn(n);let f="";if(t.shortlinkUrl)try{f=new URL(t.shortlinkUrl).pathname.replace(/^\/+/,"")}catch{}jn(f),Sr(!0)},[]),Dn=r.useCallback(()=>{Sr(!1),kr(null)},[]),Gs=r.useCallback(()=>{if(!Y)return;const t=new FormData;t.set("actionType","updateLink"),t.set("linkId",Y.id),t.set("discountCode",Tt),t.set("influencerName",Rt),t.set("discountAmount",Mt),t.set("discountType",jr),t.set("utmSource",Lt),t.set("utmMedium",Et),t.set("redirectPath",Dr),t.set("shortPath",wr),E(t,{method:"post"})},[Y,Tt,Rt,Mt,jr,Lt,Et,Dr,wr,E]);r.useEffect(()=>{o!=null&&o.linkUpdated&&(Sr(!1),kr(null))},[o]);const zs=r.useCallback(()=>{if(s.length===0)return;const t=["Promoter","Discount Code","Amount","Type","Shortlink","UTM Source","UTM Medium","Generated URL","Created"],n=s.map(C=>[`"${C.influencerName.replace(/"/g,'""')}"`,`"${C.discountCode.replace(/"/g,'""')}"`,C.discountAmount,C.discountType,`"${C.shortlinkUrl?C.shortlinkUrl.replace(/"/g,'""'):""}"`,`"${C.utmSource.replace(/"/g,'""')}"`,`"${C.utmMedium.replace(/"/g,'""')}"`,`"${C.generatedUrl.replace(/"/g,'""')}"`,new Date(C.createdAt).toLocaleDateString()].join(",")),f=[t.join(","),...n].join(` 4`),m=new Blob([f],{type:"text/csv;charset=utf-8;"}),_=URL.createObjectURL(m),g=document.createElement("a");g.setAttribute("href",_),g.setAttribute("download",`Promo_Links_${new Date().toISOString().split("T")[0]}.csv`),document.body.appendChild(g),g.click(),document.body.removeChild(g),URL.revokeObjectURL(_)},[s]),Se=r.useRef(null),fe=r.useRef(null),[ze,Hs]=r.useState(""),[at,Vs]=r.useState(""),[It,Ys]=r.useState("300"),[At,Zs]=r.useState("300"),[Ut,Js]=r.useState("10"),[_t,Xs]=r.useState("M"),[Ue,Ks]=r.useState("square"),[qt,wn]=r.useState("square"),[it,Pn]=r.useState("#000000"),[lt,Tn]=r.useState("none"),[$t,eo]=r.useState("#000000"),[Ft,to]=r.useState("#4a4a4a"),[Nt,ro]=r.useState("0"),[Ot,Rn]=r.useState("square"),[Wt,Mn]=r.useState("#000000"),[ct,Ln]=r.useState("none"),[Qt,no]=r.useState("#000000"),[Bt,so]=r.useState("#4a4a4a"),[Gt,oo]=r.useState("0"),[zt,En]=r.useState("square"),[Ht,In]=r.useState("#000000"),[dt,An]=r.useState("none"),[Vt,ao]=r.useState("#000000"),[Yt,io]=r.useState("#4a4a4a"),[Zt,lo]=r.useState("0"),[ut,Un]=r.useState("#ffffff"),[ht,_n]=r.useState("none"),[Jt,co]=r.useState("#ffffff"),[Xt,uo]=r.useState("#f0f0f0"),[Kt,ho]=r.useState("0"),[mt,qn]=r.useState("0"),[_e,$n]=r.useState(""),[er,mo]=r.useState("0"),[tr,po]=r.useState("0.4"),[rr,fo]=r.useState(!0),[Pr,go]=r.useState("square"),[xo,Tr]=r.useState(!1),[Rr,Mr]=r.useState([]),[Fn,Nn]=r.useState(!1),[yo,On]=r.useState(null),[vo,Wn]=r.useState(!1),[ge,Qn]=r.useState(!1),[nr,Bn]=r.useState("#000000"),[sr,Gn]=r.useState("2"),[pt,zn]=r.useState("solid"),[or,Hn]=r.useState("5"),[Lr,Vn]=r.useState(null),[Ta,Er]=r.useState(!1),[Ra,ar]=r.useState(null),[ce,bo]=r.useState(!0),xe=r.useCallback((t,n,f,m)=>{if(t!=="none")return{type:t,rotation:parseInt(m,10),colorStops:[{offset:0,color:n},{offset:1,color:f}]}},[]),Yn=r.useMemo(()=>({modern:{name:"Modern",dotsStyle:"rounded",dotsColor:"#000000",cornersSquareStyle:"extra-rounded",cornersSquareColor:"#000000",cornersDotStyle:"dot",cornersDotColor:"#000000",backgroundColor:"#ffffff",backgroundRound:"0.5",frameEnabled:!1},classic:{name:"Classic",dotsStyle:"square",dotsColor:"#000000",cornersSquareStyle:"square",cornersSquareColor:"#000000",cornersDotStyle:"square",cornersDotColor:"#000000",backgroundColor:"#ffffff",backgroundRound:"0",frameEnabled:!0,frameColor:"#000000",frameWidth:"2",frameStyle:"solid",framePadding:"8"}
4,minimal:{name:"Minimal",dotsStyle:"dots",dotsColor:"#333333",cornersSquareStyle:"dot",cornersSquareColor:"#333333",cornersDotStyle:"dot",cornersDotColor:"#333333",backgroundColor:"#ffffff",backgroundRound:"0",frameEnabled:!1},bold:{name:"Bold",dotsStyle:"classy-rounded",dotsColor:"#1a1a1a",cornersSquareStyle:"extra-rounded",cornersSquareColor:"#1a1a1a",cornersDotStyle:"dot",cornersDotColor:"#1a1a1a",backgroundColor:"#ffffff",backgroundRound:"1",frameEnabled:!0,frameColor:"#1a1a1a",frameWidth:"3",frameStyle:"solid",framePadding:"6"},elegant:{name:"Elegant",dotsStyle:"classy",dotsColor:"#2c3e50",cornersSquareStyle:"extra-rounded",cornersSquareColor:"#2c3e50",cornersDotStyle:"square",cornersDotColor:"#2c3e50",backgroundColor:"#f8f9fa",backgroundRound:"0.3",frameEnabled:!0,frameColor:"#2c3e50",frameWidth:"1",frameStyle:"solid",framePadding:"10"},gradient:{name:"Gradient",dotsStyle:"rounded",dotsColor:"#6366f1",cornersSquareStyle:"extra-rounded",cornersSquareColor:"#8b5cf6",cornersDotStyle:"dot",cornersDotColor:"#a855f7",backgroundColor:"#ffffff",backgroundRound:"0.5",frameEnabled:!0,frameColor:"#6366f1",frameWidth:"2",frameStyle:"solid",framePadding:"8"},retro:{name:"Retro",dotsStyle:"extra-rounded",dotsColor:"#d97706",cornersSquareStyle:"dot",cornersSquareColor:"#b45309",cornersDotStyle:"square",cornersDotColor:"#92400e",backgroundColor:"#fef3c7",backgroundRound:"0",frameEnabled:!0,frameColor:"#92400e",frameWidth:"3",frameStyle:"dashed",framePadding:"6"}}),[]);r.useCallback(t=>{const n=Yn[t];n&&(Vn(t),wn(n.dotsStyle),Pn(n.dotsColor),Tn("none"),Rn(n.cornersSquareStyle),Mn(n.cornersSquareColor),Ln("none"),En(n.cornersDotStyle),In(n.cornersDotColor),An("none"),Un(n.backgroundColor),_n("none"),qn(n.backgroundRound),Qn(n.frameEnabled),n.frameEnabled&&"frameColor"in n&&(Bn(n.frameColor),Gn("frameWidth"in n?n.frameWidth:"2"),zn("frameStyle"in n?n.frameStyle:"solid"),Hn("framePadding"in n?n.framePadding:"5")))},[Yn]),r.useEffect(()=>{F!==3&&(fe.current=null)},[F]),r.useEffect(()=>{if(typeof window>"u"||F!==3)return;const t=setTimeout(async()=>{if(!Se.current)return;const n=(await as(async()=>{const{default:A}=await import("./qr-code-styling-qEM6xCUA.js").then(c=>c.q);return{default:A}},__vite__mapDeps([0,1]))).default,f=parseInt(It,10)||300,m=parseInt(At,10)||300,_=parseInt(Ut,10)||10,g={width:f,height:m,margin:_,data:at||"https://example.com",shape:Ue,qrOptions:{errorCorrectionLevel:_t},dotsOptions:{type:qt,color:it,gradient:xe(lt,$t,Ft,Nt)},cornersSquareOptions:{type:Ot,color:Wt,gradient:xe(ct,Qt,Bt,Gt)},cornersDotOptions:{type:zt,color:Ht,gradient:xe(dt,Vt,Yt,Zt)},backgroundOptions:{color:ut,gradient:xe(ht,Jt,Xt,Kt),round:parseFloat(mt)||0}};_e&&(g.image=_e,g.imageOptions={margin:parseInt(er,10)||0,imageSize:parseFloat(tr)||.4,crossOrigin:"anonymous",hideBackgroundDots:rr});const C=()=>{var ns;if(!ge&&!ce)return;const A=(ns=Se.current)==null?void 0:ns.querySelector("canvas");if(!A)return;const c=A.getContext("2d");if(!c)return;const L=A.width,y=A.height,q=ge?parseInt(sr,10)||2:0,Re=ge?parseInt(or,10)||5:0,qe=Math.max(8,Math.floor(L*.032)),rs=ce&&Ue==="circle"?qe+4:0,$o=ge?Math.ceil(q/2):0;if(ce&&rs>0){const ve=y+rs,$=document.createElement("canvas");$.width=L,$.height=y;const O=$.getContext("2d");O&&O.drawImage(A,0,0),A.height=ve,c.fillStyle=ut,c.fillRect(0,0,L,ve),c.drawImage($,0,0)}if(A.height,ge){if(c.strokeStyle=nr,c.lineWidth=q,pt==="dashed"?c.setLineDash([q*3,q*2]):pt==="dotted"?c.setLineDash([q,q]):c.setLineDash([]),Ue==="circle"){const ve=Math.min(L,y)/2-Re-q/2;c.beginPath(),c.arc(L/2,y/2,ve,0,Math.PI*2),c.stroke()}else{const $=(parseFloat(mt)||0)*Math.min(L,y)*.1,O=Re+q/2,W=Re+q/2,Me=L-Re*2-q,ke=y-Re*2-q;$>0?(c.beginPath(),c.moveTo(O+$,W),c.lineTo(O+Me-$,W),c.quadraticCurveTo(O+Me,W,O+Me,W+$),c.lineTo(O+Me,W+ke-$),c.quadraticCurveTo(O+Me,W+ke,O+Me-$,W+ke),c.lineTo(O+$,W+ke),c.quadraticCurveTo(O,W+ke,O,W+ke-$),c.lineTo(O,W+$),c.quadraticCurveTo(O,W,O+$,W),c.closePath(),c.stroke()):c.strokeRect(O,W,Me,ke)}c.setLineDash([])}if(ce){const ve="PRIVACY.ONBRAND.ONLINE";if(c.fillStyle=it,c.font=`bold ${qe}px Arial, sans-serif`,Ue==="circle"){const $=L/2,O=y/2,W=y/2+qe/2+1,ke=c.measureText(ve).width/W;c.save(),c.translate($,O),c.textAlign="center",c.textBaseline="middle";let vt=Math.PI/2+ke/2;for(let _r=0;_r<ve.length;_r++){const ss=ve[_r],os=c.measureText(ss).width;vt-=os/2/W;const Fo=Math.cos(vt)*W,No=Math.sin(vt)*W;c.save(),c.translate(Fo,No),c.rotate(vt-Math.PI/2),c.fillText(ss,0,0),c.restore(
4),vt-=os/2/W}c.restore()}else{c.textAlign="center",c.textBaseline="middle";let $;ge?$=y-Re-$o-qe/2-2:$=y-qe/2-4,c.fillText(ve,L/2,$)}}};if(!fe.current||!Se.current.hasChildNodes()?(fe.current=new n(g),Se.current.innerHTML="",fe.current.append(Se.current)):fe.current.update(g),setTimeout(C,_e?500:100),_e&&(ge||ce)){const A=new MutationObserver(()=>{setTimeout(C,50)});Se.current&&A.observe(Se.current,{childList:!0,subtree:!0}),setTimeout(()=>A.disconnect(),2e3)}},300);return()=>clearTimeout(t)},[F,at,It,At,Ut,_t,Ue,ce,qt,it,lt,$t,Ft,Nt,Ot,Wt,ct,Qt,Bt,Gt,zt,Ht,dt,Vt,Yt,Zt,ut,ht,Jt,Xt,Kt,mt,_e,er,tr,rr,Pr,ge,nr,sr,pt,or,xe]),r.useCallback(async t=>{var n;if(fe.current){if(ce&&t!=="svg"){const f=(n=Se.current)==null?void 0:n.querySelector("canvas");if(f){const m=t==="png"?"image/png":t==="jpeg"?"image/jpeg":"image/webp",_=f.toDataURL(m,.92),g=document.createElement("a");g.href=_,g.download=`${ze||"qr-code"}.${t}`,document.body.appendChild(g),g.click(),document.body.removeChild(g);return}}await fe.current.download({extension:t,name:ze||"qr-code"})}},[ze,ce]),r.useCallback(async()=>{var f;if(!ze||!at){ar("Name and Target URL are required");return}let t=null;if(fe.current)try{if(ce){const m=(f=Se.current)==null?void 0:f.querySelector("canvas");m&&(t=m.toDataURL("image/png"))}if(!t){const m=await fe.current.getRawData("png");m&&m instanceof Blob&&(t=await new Promise(_=>{const g=new FileReader;g.onloadend=()=>_(g.result),g.readAsDataURL(m)}))}}catch(m){console.error("Failed to get QR data URL:",m)}const n=new FormData;n.set("actionType","createQRCode"),n.set("name",ze),n.set("targetUrl",at),n.set("shape",Ue),n.set("dotsStyle",qt),n.set("dotsColor",it),n.set("dotsGradient",lt!=="none"?JSON.stringify(xe(lt,$t,Ft,Nt)):""),n.set("cornersSquareStyle",Ot),n.set("cornersSquareColor",Wt),n.set("cornersSquareGradient",ct!=="none"?JSON.stringify(xe(ct,Qt,Bt,Gt)):""),n.set("cornersDotStyle",zt),n.set("cornersDotColor",Ht),n.set("cornersDotGradient",dt!=="none"?JSON.stringify(xe(dt,Vt,Yt,Zt)):""),n.set("backgroundColor",ut),n.set("backgroundGradient",ht!=="none"?JSON.stringify(xe(ht,Jt,Xt,Kt)):""),n.set("backgroundRound",mt),n.set("imageUrl",_e),n.set("imageMargin",er),n.set("imageSize",tr),n.set("imageHideBackgroundDots",rr.toString()),n.set("imageShape",Pr),n.set("width",It),n.set("height",At),n.set("margin",Ut),n.set("errorCorrectionLevel",_t),n.set("qrDataUrl",t||""),n.set("trackingEnabled",ce.toString()),n.set("frameEnabled",ge.toString()),n.set("frameColor",nr),n.set("frameWidth",sr),n.set("frameStyle",pt),n.set("framePadding",or),Lr&&n.set("templateName",Lr),E(n,{method:"post"}),Er(!0),ar(null)},[ze,at,Ue,qt,it,lt,$t,Ft,Nt,Ot,Wt,ct,Qt,Bt,Gt,zt,Ht,dt,Vt,Yt,Zt,ut,ht,Jt,Xt,Kt,mt,_e,er,tr,rr,Pr,It,At,Ut,_t,ce,ge,nr,sr,pt,or,Lr,E,xe]),r.useCallback(()=>{Hs(""),Vs(""),Ys("300"),Zs("300"),Js("10"),Xs("M"),Ks("square"),wn("square"),Pn("#000000"),Tn("none"),eo("#000000"),to("#4a4a4a"),ro("0"),Rn("square"),Mn("#000000"),Ln("none"),no("#000000"),so("#4a4a4a"),oo("0"),En("square"),In("#000000"),An("none"),ao("#000000"),io("#4a4a4a"),lo("0"),Un("#ffffff"),_n("none"),co("#ffffff"),uo("#f0f0f0"),ho("0"),qn("0"),$n(""),mo("0"),po("0.4"),fo(!0),go("square"),Qn(!1),Bn("#000000"),Gn("2"),zn("solid"),Hn("5"),Vn(null),Er(!1),ar(null),bo(!0),fe.current=null},[]);const Ir=r.useCallback(async t=>{var n,f;Nn(!0);try{const m=new FormData;m.set("actionType","fetchMediaFiles"),t&&m.set("cursor",t);const g=await(await fetch("/app/promo-links",{method:"POST",body:m})).json();g.success&&g.mediaFiles&&(Mr(t?C=>[...C,...g.mediaFiles]:g.mediaFiles),On(((n=g.pageInfo)==null?void 0:n.endCursor)||null),Wn(((f=g.pageInfo)==null?void 0:f.hasNextPage)||!1))}catch(m){console.error("Error fetching media files:",m)}finally{Nn(!1)}},[]);r.useCallback(()=>{Tr(!0),Mr([]),On(null),Wn(!1),Ir()},[Ir]);const Co=r.useCallback(t=>{$n(t),Tr(!1)},[]);r.useEffect(()=>{o!=null&&o.qrCodeCreated&&Er(!0),o!=null&&o.error&&F===3&&ar(o.error)},[o,F]),r.useEffect(()=>{o!=null&&o.redirectExists&&(o!=null&&o.error)&&F===0&&(ln(me),fr(!0))},[o,F,me]);const[Ma,Zn]=r.useState(!1),[Ar,Jn]=r.useState(null),[La,Xn]=r.useState(null);r.useCallback(t=>{Jn(t),Zn(!0)},[]),r.useCallback(()=>
4{if(Ar){const t=new FormData;t.set("actionType","deleteQRCode"),t.set("qrCodeId",Ar),E(t,{method:"post"})}Zn(!1),Jn(null)},[Ar,E]),r.useCallback(async(t,n)=>{if(t.qrDataUrl&&n==="png"){const C=document.createElement("a");C.href=t.qrDataUrl,C.download=`${t.name}.${n}`,document.body.appendChild(C),C.click(),document.body.removeChild(C),Xn(null);return}const f=(await as(async()=>{const{default:C}=await import("./qr-code-styling-qEM6xCUA.js").then(ye=>ye.q);return{default:C}},__vite__mapDeps([0,1]))).default,m=C=>{if(C)try{return JSON.parse(C)}catch{return}},_={width:t.width||300,height:t.height||300,margin:t.margin||10,data:t.targetUrl,qrOptions:{errorCorrectionLevel:t.errorCorrectionLevel||"M"},dotsOptions:{type:t.dotsStyle,color:t.dotsColor,gradient:m(t.dotsGradient)},cornersSquareOptions:{type:t.cornersSquareStyle,color:t.cornersSquareColor,gradient:m(t.cornersSquareGradient)},cornersDotOptions:{type:t.cornersDotStyle,color:t.cornersDotColor,gradient:m(t.cornersDotGradient)},backgroundOptions:{color:t.backgroundColor,gradient:m(t.backgroundGradient)}};t.imageUrl&&(_.image=t.imageUrl,_.imageOptions={margin:t.imageMargin||0,imageSize:t.imageSize||.4,crossOrigin:"anonymous"}),await new f(_).download({extension:n,name:t.name||"qr-code"}),Xn(null)},[]);const[Ur,So]=r.useState(0),[Kn,ft]=r.useState(!1),[gt,ko]=r.useState(0),es=new Date,jo=new Date(es.getTime()-30*24*60*60*1e3),[He,Do]=r.useState({start:Q?new Date(Q):jo,end:k?new Date(k):es}),[{month:wo,year:Po},To]=r.useState({month:He.start.getMonth(),year:He.start.getFullYear()}),Ro=r.useCallback((t,n)=>{To({month:t,year:n})},[]),xt=r.useCallback(t=>{ft(!1),P(`/app/promo-links?tab=2&range=${t}`)},[P]),Mo=r.useCallback(()=>{ft(!1);const t=He.start.toISOString().split("T")[0],n=He.end.toISOString().split("T")[0];P(`/app/promo-links?tab=2&range=custom&startDate=${t}&endDate=${n}`)},[P,He]),Lo=r.useCallback(()=>{if(p==="custom"&&Q&&k){const n=new Date(Q),f=new Date(k);return`${n.toLocaleDateString("en-US",{month:"short",day:"numeric"})} - ${f.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}`}const t=Da.find(n=>n.value===p);return(t==null?void 0:t.label)||"Last 30 days"},[p,Q,k]),Eo=r.useCallback(t=>{So(t)},[]),Io=[{id:"revenue",content:"Revenue"},{id:"users",content:"Users"},{id:"conversionRate",content:"Conversion Rate"},{id:"revenuePerSession",content:"Revenue/Session"},{id:"aov",content:"AOV"}],Ao={0:"revenue",1:"users",2:"conversionRate",3:"revenuePerSession",4:"aov"},Uo={0:"#22c55e",1:"#3b82f6",2:"#8b5cf6",3:"#f59e0b",4:"#ec4899"},Te=r.useMemo(()=>{const t=u.users>0?u.conversions/u.users*100:0,n=u.users>0?u.revenue/u.users:0,f=u.conversions>0?u.revenue/u.conversions:0;return{conversionRate:t,revenuePerSession:n,aov:f}},[u]),ne=r.useMemo(()=>{switch(gt){case 1:return R;case 2:return T;case 3:return x;default:return w}},[gt,w,R,T,x]),yt=r.useMemo(()=>{switch(gt){case 1:return"Code";case 2:return"Source";case 3:return"Medium";default:return"Promoter"}},[gt]),_o=ne.map(t=>{const n=t.users>0?(t.conversions/t.users*100).toFixed(2)+"%":"0%",f=t.users>0?"$"+(t.revenue/t.users).toFixed(2):"$0.00",m=t.conversions>0?"$"+(t.revenue/t.conversions).toFixed(2):"$0.00";return[t.name,t.users.toLocaleString(),n,"$"+t.revenue.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),t.codesUsed.toLocaleString(),"$"+t.codeRevenue.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),"$"+t.linkRevenue.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),t.codesUsed.toLocaleString(),f,m]}),ts=r.useCallback(t=>({"7d":"Last_7_Days","14d":"Last_14_Days","30d":"Last_30_Days","90d":"Last_90_Days","12m":"Last_12_Months",all:"All_Time"})[t]||t,[]),qo=r.useCallback(()=>{if(ne.length===0)return;const t=[yt,"Users","Conv. Rate","Revenue","Codes Used","Code Revenue","Link Revenue","Codes Redeemed","Rev/Session","AOV"],n=ne.map(y=>{const q=y.users>0?(y.conversions/y.users*100).toFixed(2):"0",Re=y.users>0?(y.revenue/y.users).toFixed(2):"0",qe=y.conversions>0?(y.revenue/y.conversions).toFixed(2):"0";return[`"${y.name.replace(/"/g,'""')}"`,y.users,q,y.revenue.toFixed(2),y.codesUsed,y.codeRevenue.toFixed(2),y.linkRevenue.toFixed(2),y.codesUsed,Re,qe].join(",")}),f=u.users>0?(u.conversions/u.users*100).toFixed(2):"0",m=ne.reduce((y,q)=>y+q.codesUsed,0),_=ne.reduce((y,q)=>y+q.codeRevenue,0),g=ne.reduce((y,q)=>y+q.linkRevenue,0),C=['"Total"',u.users,f,u.revenue.toFixed(2),m,_.toFixed(2),g.toFixed(2),m,Te.revenuePerSession.toFixed(2),Te.aov.toFixed(2)].join(","),ye=[t.join(","),...n,C].join(` 5`),A=new Blob([ye],{type:"text/csv;charset=utf-8;"}),c=URL.createObjectURL(A),L=document.createElement("a");L.setAttribute("href",c),L.setAttribute("download",`${yt}_Performance_${ts(p)}_${new Date().toISOString().split("T")[0]}.csv`),document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(c)},[ne,yt,u,Te,p,ts]);return e.jsx(Vo,{children:e.jsx(Zo,{title:"Promo Links",titleMetadata:e.jsx(Oo,{category:"promo-links",tooltip:"Get help with Promo Links"}),subtitle:"Create trackable, personalized auto apply discount & auto add to cart links and monitor performance",backAction:{url:"/app"},children:e.jsxs(de,{children:[e.jsx(de.Section,{children:e.jsx(te,{padding:"0",children:e.jsx($r,{tabs:v,selected:F,onSelect:K})})}),(o==null?void 0:o.error)&&F===0&&!(o!=null&&o.redirectExists)&&e.jsx(de.Section,{children:e.jsx(Ve,{tone:"critical",title:"Error",children:o.error})}),F===0&&e.jsxs(e.Fragment,{children:[oe&&e.jsx(de.Section,{children:e.jsx(Ve,{tone:"success",title:"Import Successful",onDismiss:()=>I(null),children:oe})}),e.jsx(de.Section,{children:e.jsx(te,{children:e.jsxs(S,{gap:"400",children:[e.jsxs(B,{align:"space-between",blockAlign:"center",children:[e.jsx(i,{as:"h2",variant:"headingMd",children:"Campaign Details"}),e.jsx(ls,{active:Ie,activator:e.jsx(j,{icon:Fr,onClick:Gr,children:"Import via CSV"}),onClose:Gr,children:e.jsx(Jo,{items:[{content:"Download Template",onAction:zr},{content:"Upload CSV",onAction:Ts}]})})]}),e.jsx(Z,{padding:"300",background:"bg-surface-secondary",borderRadius:"200",children:e.jsx(i,{as:"p",variant:"bodyMd",fontWeight:"semibold",children:a})}),e.jsx(X,{label:"Redirect Page (Optional)",value:jt,onChange:en,autoComplete:"off",placeholder:"/products/product-name",helpText:"Leave empty to redirect to homepage, or enter a path like /collections/sale",disabled:U}),e.jsx($e,{}),e.jsx(X,{label:"Discount Code",value:Ce,onChange:Vr,autoComplete:"off",placeholder:"e.g., 83WEEKS1
55",helpText:"The discount code that will be applied at checkout",disabled:U}),e.jsx(X,{label:"Promoter Display Name",value:ae,onChange:Yr,autoComplete:"off",placeholder:"e.g., 83 Weeks",helpText:"The name to display and track for this campaign",disabled:U}),e.jsxs(B,{gap:"400",wrap:!1,children:[e.jsx(Z,{width:"50%",children:e.jsx(X,{label:"Discount Amount",type:"number",value:We,onChange:Zr,autoComplete:"off",placeholder:"e.g., 15",disabled:U})}),e.jsx(Z,{width:"50%",children:e.jsx(us,{label:"Discount Type",options:dn,value:Ke,onChange:Jr,disabled:U})})]}),e.jsx($e,{}),e.jsx(i,{as:"h2",variant:"headingMd",children:"UTM Parameters"}),e.jsx(X,{label:"UTM Source",value:Qe,onChange:Xr,autoComplete:"off",placeholder:"e.g., 83 Weeks",helpText:"Identifies the source of traffic (usually the influencer/partner name)",disabled:U}),e.jsx(X,{label:"UTM Medium",value:Be,onChange:Kr,autoComplete:"off",placeholder:"e.g., Podcast",helpText:"Identifies the marketing medium (e.g., Podcast, YouTube, Instagram)",disabled:U}),e.jsx($e,{}),e.jsxs(S,{gap:"400",children:[e.jsxs(S,{gap:"300",children:[e.jsxs(B,{gap:"200",blockAlign:"center",children:[e.jsx("div",{onClick:()=>!U&&Es(!Pe),style:{width:"44px",height:"24px",borderRadius:"12px",backgroundColor:Pe?"#008060":"#b5b5b5",position:"relative",cursor:U?"not-allowed":"pointer",transition:"background-color 0.2s",opacity:U?.5:1},children:e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",position:"absolute",top:"2px",left:Pe?"22px":"2px",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}})}),e.jsx(i,{as:"span",variant:"bodyMd",children:"Automatically add products to cart and go to checkout"})]}),e.jsxs(B,{gap:"200",blockAlign:"center",children:[e.jsx("div",{onClick:()=>!U&&Is(!pe),style:{width:"44px",height:"24px",borderRadius:"12px",backgroundColor:pe?"#008060":"#b5b5b5",position:"relative",cursor:U?"not-allowed":"pointer",transition:"background-color 0.2s",opacity:U?.5:1},children:e.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",position:"absolute",top:"2px",left:pe?"22px":"2px",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}})}),e.jsx(i,{as:"span",variant:"bodyMd",children:"Automatically add products to cart and open cart"})]})]}),st&&e.jsxs(S,{gap:"300",children:[e.jsx(j,{icon:ks,onClick:As,disabled:U,children:le.length>0?"Change Products":"Select Products"}),le.length>0&&e.jsxs(S,{gap:"200",children:[e.jsxs(i,{as:"p",variant:"bodySm",fontWeight:"semibold",children:["Selected Products (",le.length,"):"]}),e.jsx(B,{gap:"200",wrap:!0,children:le.map(t=>e.jsx(ta,{onRemove:U?void 0:()=>Us(t.id),children:e.jsxs(B,{gap:"100",blockAlign:"center",children:[t.images&&t.images.length>0&&e.jsx(Sa,{source:t.images[0].originalSrc,alt:t.title,size:"extraSmall"}),e.jsx(i,{as:"span",variant:"bodySm",children:t.title})]})},t.id))}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"These products will be added to the cart with quantity of 1 each."})]})]})]}),ee&&e.jsxs(e.Fragment,{children:[e.jsx($e,{}),e.jsx(Z,{padding:"300",background:"bg-surface-secondary",borderRadius:"200",children:e.jsxs(S,{gap:"300",children:[e.jsxs(B,{align:"space-between",blockAlign:"center",children:[e.jsx(i,{as:"p",variant:"bodySm",fontWeight:"semibold",children:"Generated Link:"}),e.jsx(j,{size:"slim",icon:ir,onClick:$s,variant:tn?"primary":"tertiary",children:tn?"Copied!":"Copy"})]}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",breakWord:!0,children:ee}),U&&!(o!=null&&o.shortlinkCreated)&&e.jsx(j,{size:"slim",icon:is,onClick:mn,children:"Create QR Code"})]})})]}),e.jsx(j,{variant:U?"secondary":"primary",size:"large",fullWidth:!0,onClick:_s,loading:D&&!U,disabled:!yr||U,children:U?"Saved":"Save & Create Shortlink"}),U&&ee&&e.jsxs("div",{ref:on,children:[e.jsx($e,{}),e.jsxs(S,{gap:"400",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-start",gap:"8px"},children:[e.jsx("span",{style:{display:"inline-flex",flexShrink:0},children:e.jsx(lr,{source:na,tone:"success"})}),e.jsx(i,{as:"h2",variant:"headingMd",children:"Create Shortlink"})]}
5),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"Create a short, memorable URL that redirects to your tracking link."}),e.jsx(X,{label:"Short Path",value:me,onChange:pr,autoComplete:"off",prefix:`${a}/`,helpText:"This will be the short URL path (e.g., 83weeks)"}),e.jsx(Z,{padding:"300",background:"bg-surface-secondary",borderRadius:"200",children:e.jsxs(S,{gap:"200",children:[e.jsxs(B,{align:"space-between",blockAlign:"center",children:[e.jsx(i,{as:"p",variant:"bodySm",fontWeight:"semibold",children:"Shortlink will be:"}),e.jsx(j,{size:"slim",icon:ir,onClick:Fs,variant:nn?"primary":"tertiary",children:nn?"Copied!":"Copy"})]}),e.jsxs(i,{as:"p",variant:"bodyMd",fontWeight:"bold",children:["https://",a,"/",me]}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"â redirects to â"}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",breakWord:!0,children:ee})]})}),(o==null?void 0:o.shortlinkCreated)&&(o==null?void 0:o.shortlinkUrl)&&e.jsx("div",{ref:an,children:e.jsxs(S,{gap:"400",children:[e.jsx(Ve,{tone:"success",title:"Shortlink Created!",children:e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodyMd",fontWeight:"bold",children:o.shortlinkUrl}),e.jsx(j,{size:"slim",icon:ir,onClick:Ns,variant:rn?"primary":"secondary",children:rn?"Copied!":"Copy Shortlink"})]})}),e.jsxs(S,{gap:"200",children:[e.jsx(j,{variant:"primary",size:"large",onClick:Os,fullWidth:!0,children:"Add Another Promo Link"}),e.jsx(j,{variant:"secondary",size:"large",icon:is,onClick:mn,fullWidth:!0,children:"Create QR Code"})]})]})}),!(o!=null&&o.shortlinkCreated)&&e.jsx(j,{variant:"primary",onClick:()=>Cr(!1),loading:D,disabled:!me,children:"Create Redirect"})]})]})]})})}),e.jsxs(de.Section,{variant:"oneThird",children:[e.jsx(te,{children:e.jsxs(S,{gap:"300",children:[e.jsx(i,{as:"h3",variant:"headingMd",children:"How it works"}),e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",children:"1. Enter your discount code (must already exist in Shopify)"}),e.jsx(i,{as:"p",variant:"bodySm",children:"2. Add the influencer name for tracking"}),e.jsx(i,{as:"p",variant:"bodySm",children:"3. Set the discount amount and type"}),e.jsx(i,{as:"p",variant:"bodySm",children:"4. Configure UTM parameters for analytics"}),e.jsx(i,{as:"p",variant:"bodySm",children:'5. Click "Save & Create Shortlink"'}),e.jsx(i,{as:"p",variant:"bodySm",children:"6. Customize and create your short URL"}),e.jsx(i,{as:"p",variant:"bodySm",children:"7. Next, create a QR code or personalized promo bar"})]})]})}),e.jsx(Z,{paddingBlockStart:"400",children:e.jsx(te,{children:e.jsxs(S,{gap:"300",children:[e.jsx(i,{as:"h3",variant:"headingMd",children:"Tips"}),e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"⢠Make sure your discount code is created in Shopify first"}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"⢠Use consistent naming for better analytics"}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"⢠The link auto-applies the discount at checkout"}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"⢠Shortlinks are easier to share and are more personalized"}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"⢠Create a promo bar with a promo link trigger, or promo link personalization, to display a personalized promo bar with the promoter's name and discount when someone visits the link"})]})]})})})]}),e.jsx(Le,{open:kt,onClose:Hr,title:"Import Promo Links from CSV",primaryAction:{content:"Import",onAction:Ms,loading:Ds,disabled:!be},secondaryActions:[{content:"Cancel",onAction:Hr}],children:e.jsx(Le.Section,{children:e.jsxs(S,{gap:"400",children:[se&&e.jsx(Ve,{tone:"critical",title:"Import Error",children:se}),e.jsx(i,{as:"p",variant:"bodyMd",children:"Upload a CSV file containing promo link data. The file must include the following columns:"}),e.jsx(Z,{padding:"300",background:"bg-surface-secondary",borderRadius:"200",children:e.jsxs(S,{gap:"100",children:[e.jsx(i,{as:"p",variant:"bodySm",fontWeight:"semibold",children:"Required columns:"}),e.jsx(i,{as:"p",variant:"bodySm",children:"⢠discount_code - The discount code"}),e.jsx(i,{as:"p",variant:"bodySm",children:"⢠influencer_name - The influencer display name"}),e.jsx(i,{as:"p",variant:"bodySm",children:"⢠discount_amount - The discount amount (number)"}),e.jsx(i,{as:"p",variant:"bodySm",children:'⢠discount_type - "percent" or "fixed"'}),e.jsx(i,{as:"p",variant:"bodySm",children:"⢠utm_source - UTM source for tracking"}),e.jsx(i,{as:"p",variant:"bodySm",children:"⢠utm_medium - UTM medium for tracking"}),e.jsx(i,{as:"p",variant:"bodySm",fontWeight:"semibold",tone:"subdued",children:"Optional:"}
5),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:'⢠redirect_path - Path to redirect to (defaults to "/")'}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:'⢠short_path - Vanity path for a shortlink (e.g. "summer20")'})]})}),e.jsx(hs,{accept:".csv",type:"file",onDrop:Rs,allowMultiple:!1,children:be?e.jsx(Z,{padding:"400",children:e.jsxs(S,{gap:"200",inlineAlign:"center",children:[e.jsx(lr,{source:Fr,tone:"success"}),e.jsx(i,{as:"p",variant:"bodyMd",fontWeight:"semibold",children:be.name}),e.jsxs(i,{as:"p",variant:"bodySm",tone:"subdued",children:[(be.size/1024).toFixed(2)," KB"]})]})}):e.jsx(hs.FileUpload,{actionHint:"or drop a CSV file to upload"})}),e.jsx(ms,{label:"Also create shortlinks (vanity redirect URLs)",checked:dr,onChange:ws,helpText:"Uses the short_path column when present, otherwise the discount code."}),e.jsx(ms,{label:"Overwrite existing links with the same shortlink",checked:ur,onChange:Ps,helpText:"De-duplicates by shortlink: a row whose shortlink already exists updates that link (and refreshes its redirect) instead of creating a duplicate."}),e.jsx(j,{variant:"plain",onClick:zr,children:"Download template CSV"})]})})})]}),F===1&&e.jsxs(de.Section,{children:[s.length===0?e.jsx(te,{children:e.jsx(ps,{heading:"No links generated yet",action:{content:"Generate your first link",onAction:()=>K(0)},image:"https://cdn.shopify.com/s/files/1/0262/4071/2726/files/emptystate-files.png",children:e.jsx("p",{children:"Create trackable, personalized auto apply discount & auto add to cart links for your influencer campaigns."})})}):e.jsxs(te,{padding:"0",children:[e.jsx(Z,{padding:"400",children:e.jsxs(B,{align:"space-between",blockAlign:"center",children:[e.jsxs(B,{gap:"300",blockAlign:"center",children:[e.jsxs(i,{as:"h2",variant:"headingMd",children:[s.length," Promo Link",s.length!==1?"s":""]}),Ws?e.jsx("div",{style:{width:"220px"},children:e.jsx(X,{label:"Search links",labelHidden:!0,placeholder:"Search links...",value:Ge,onChange:pn,autoComplete:"off",prefix:e.jsx(lr,{source:cs}),suffix:Ge?e.jsx(j,{variant:"plain",onClick:()=>{pn(""),fn(!1)},icon:ea,accessibilityLabel:"Clear search"}):null})}):e.jsx(j,{size:"slim",icon:cs,onClick:()=>fn(!0),accessibilityLabel:"Search links"})]}),e.jsx(j,{icon:Fr,onClick:zs,children:"Export"})]})}),e.jsx(ue,{resourceName:{singular:"link",plural:"links"},itemCount:ot.length,headings:[{title:"Promoter"},{title:"Link Type"},{title:"Discount Code"},{title:"Amount"},{title:"Shortlink"},{title:"UTM Source"},{title:"UTM Medium"},{title:"Created"},{title:"Actions"}],selectable:!1,children:ot.map((t,n)=>e.jsxs(ue.Row,{id:t.id,position:n,children:[e.jsx(ue.Cell,{children:e.jsx(i,{as:"span",variant:"bodyMd",fontWeight:"semibold",children:t.influencerName})}),e.jsx(ue.Cell,{children:e.jsx(ds,{tone:t.linkType==="checkout"?"attention":t.linkType==="cart"?"info":"success",children:t.linkType==="checkout"?"Checkout":t.linkType==="cart"?"Cart":"Discount"})}),e.jsx(ue.Cell,{children:e.jsx(i,{as:"span",variant:"bodyMd",fontWeight:"medium",children:t.discountCode})}),e.jsx(ue.Cell,{children:e.jsx(ds,{tone:t.discountType==="percent"?"info":"success",children:`${t.discountAmount}${t.discountType==="percent"?"%":"$"}`})}),e.jsx(ue.Cell,{children:t.shortlinkUrl?e.jsx(qr,{content:wt===`shortlink-${t.id}`?"Copied!":"Copy shortlink",children:e.jsx(j,{size:"slim",variant:wt===`shortlink-${t.id}`?"primary":"tertiary",onClick:()=>gn(t.shortlinkUrl,`shortlink-${t.id}`),children:new URL(t.shortlinkUrl).pathname})}):e.jsx(i,{as:"span",variant:"bodySm",tone:"subdued",children:"â"})}),e.jsx(ue.Cell,{children:e.jsx(i,{as:"span",variant:"bodySm",children:t.utmSource})}),e.jsx(ue.Cell,{children:e.jsx(i,{as:"span",variant:"bodySm",children:t.utmMedium})}),e.jsx(ue.Cell,{children:e.jsx(i,{as:"span",variant:"bodySm",tone:"subdued",children:new Date(t.createdAt).toLocaleDateString()})}),e.jsx(ue.Cell,{children:e.jsxs(B,{gap:"100",wrap:!1,children:[e.jsx(qr,{content:wt===t.id?"Copied!":"Copy link",children:e.jsx(j,{icon:ir,variant:wt===t.id?"primary":"tertiary",onClick:()=>gn(t.generatedUrl,t.id),accessibilityLabel:"Copy link to clipboard"})}),e.jsx(qr,{content:"Edit link",children:e.jsx(j,{icon:sa,variant:"tertiary",onClick:()=>Bs(t),accessibilityLabel:"Edit link"})})]})})]},t.id))})]}),ot.length>0&&e.jsx(Z,{paddingBlockStart:"400",children:e.jsx(B,{align:"center",children:e.jsxs(i,{as:"p",variant:"bodySm",tone
5:"subdued",children:["Showing ",ot.length,Ge?` of ${s.length}`:""," link",ot.length!==1?"s":""]})})}),e.jsx(Le,{open:Qs,onClose:Dn,title:"Edit Promo Link",primaryAction:{content:"Save changes",onAction:Gs,loading:D,disabled:!Tt||!Rt||!Mt||!Lt||!Et},secondaryActions:[{content:"Cancel",onAction:Dn}],children:e.jsx(Le.Section,{children:e.jsxs(S,{gap:"400",children:[Y&&(Y.linkType==="cart"||Y.linkType==="checkout")&&e.jsxs(Ve,{tone:"info",children:["This is an auto-add (",Y.linkType,") link. You can update its tracking details and shortlink here; the embedded product link is preserved."]}),e.jsx(X,{label:"Discount Code",value:Tt,onChange:xn,autoComplete:"off"}),e.jsx(X,{label:"Influencer Display Name",value:Rt,onChange:yn,autoComplete:"off"}),e.jsxs(B,{gap:"400",wrap:!1,children:[e.jsx(Z,{width:"50%",children:e.jsx(X,{label:"Discount Amount",type:"number",value:Mt,onChange:vn,autoComplete:"off"})}),e.jsx(Z,{width:"50%",children:e.jsx(us,{label:"Discount Type",options:dn,value:jr,onChange:bn})})]}),e.jsx(X,{label:"UTM Source",value:Lt,onChange:Cn,autoComplete:"off"}),e.jsx(X,{label:"UTM Medium",value:Et,onChange:Sn,autoComplete:"off"}),e.jsx(X,{label:"Redirect Page (Optional)",value:Dr,onChange:kn,autoComplete:"off",placeholder:"/collections/sale",helpText:"Leave empty to redirect to the homepage.",disabled:(Y==null?void 0:Y.linkType)==="cart"||(Y==null?void 0:Y.linkType)==="checkout"}),e.jsx($e,{}),e.jsx(X,{label:"Shortlink Path",value:wr,onChange:jn,autoComplete:"off",prefix:`${a}/`,helpText:Y!=null&&Y.shortlinkUrl?"Update this link's vanity URL.":"Add a short, memorable vanity URL (e.g. johndoe). Leave empty for none."})]})})})]}),F===2&&e.jsxs(e.Fragment,{children:[e.jsx(de.Section,{children:e.jsx(te,{children:e.jsxs(B,{align:"space-between",blockAlign:"center",children:[e.jsx(i,{as:"h2",variant:"headingMd",children:"Performance Overview"}),e.jsx(ls,{active:Kn,activator:e.jsx(j,{onClick:()=>ft(!Kn),icon:Ss,disclosure:!0,children:Lo()}),onClose:()=>ft(!1),preferredAlignment:"right",children:e.jsx("div",{style:{padding:"16px",minWidth:"340px"},children:e.jsxs(S,{gap:"400",children:[e.jsx(i,{as:"h3",variant:"headingSm",children:"Quick select"}),e.jsxs(B,{gap:"200",wrap:!0,children:[e.jsx(j,{size:"slim",variant:p==="30d"?"primary":"secondary",onClick:()=>xt("30d"),children:"30 days"}),e.jsx(j,{size:"slim",variant:p==="60d"?"primary":"secondary",onClick:()=>xt("60d"),children:"60 days"}),e.jsx(j,{size:"slim",variant:p==="90d"?"primary":"secondary",onClick:()=>xt("90d"),children:"90 days"}),e.jsx(j,{size:"slim",variant:p==="12m"?"primary":"secondary",onClick:()=>xt("12m"),children:"12 months"}),e.jsx(j,{size:"slim",variant:p==="all"?"primary":"secondary",onClick:()=>xt("all"),children:"All time"})]}),e.jsx($e,{}),e.jsx(i,{as:"h3",variant:"headingSm",children:"Custom range"}),e.jsx(va,{month:wo,year:Po,onChange:t=>Do({start:t.start,end:t.end}),onMonthChange:Ro,selected:He,allowRange:!0}),e.jsxs(B,{align:"end",gap:"200",children:[e.jsx(j,{onClick:()=>ft(!1),children:"Cancel"}),e.jsx(j,{variant:"primary",onClick:Mo,children:"Apply"})]})]})})})]})})}),e.jsx(de.Section,{children:e.jsxs(B,{gap:"400",wrap:!0,children:[e.jsx("div",{style:{flex:1,minWidth:"150px"},children:e.jsx(te,{children:e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"Total Revenue"}),e.jsxs(i,{as:"p",variant:"headingXl",children:["$",u.revenue.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})]})]})})}),e.jsx("div",{style:{flex:1,minWidth:"150px"},children:e.jsx(te,{children:e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"Total Users"}),e.jsx(i,{as:"p",variant:"headingXl",children:u.users.toLocaleString()})]})})}),e.jsx("div",{style:{flex:1,minWidth:"150px"},children:e.jsx(te,{children:e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"Conversion Rate"}),e.jsxs(i,{as:"p",variant:"headingXl",children:[Te.conversionRate.toFixed(2),"%"]})]})})}),e.jsx("div",{style:{flex:1,minWidth:"150px"},children:e.jsx(te,{children:e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",tone
5:"subdued",children:"Revenue/Session"}),e.jsxs(i,{as:"p",variant:"headingXl",children:["$",Te.revenuePerSession.toFixed(2)]})]})})}),e.jsx("div",{style:{flex:1,minWidth:"150px"},children:e.jsx(te,{children:e.jsxs(S,{gap:"200",children:[e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"AOV"}),e.jsxs(i,{as:"p",variant:"headingXl",children:["$",Te.aov.toFixed(2)]})]})})})]})}),e.jsx(de.Section,{children:e.jsx(te,{children:e.jsxs(S,{gap:"400",children:[e.jsx($r,{tabs:Io,selected:Ur,onSelect:Eo}),e.jsx(Z,{paddingBlockStart:"400",children:e.jsx(wa,{data:d,metric:Ao[Ur],color:Uo[Ur]})})]})})}),e.jsx(de.Section,{children:e.jsx(te,{children:e.jsxs(S,{gap:"400",children:[e.jsxs(B,{align:"space-between",blockAlign:"center",children:[e.jsx(i,{as:"h2",variant:"headingMd",children:"Performance Breakdown"}),ne.length>0&&e.jsx(j,{icon:oa,onClick:qo,children:"Export CSV"})]}),e.jsx($r,{tabs:[{id:"promoter",content:"Promoter"},{id:"code",content:"Code"},{id:"source",content:"Source"},{id:"medium",content:"Medium"}],selected:gt,onSelect:ko}),ne.length===0?e.jsx(ps,{heading:`No ${yt.toLowerCase()} data yet`,image:"https://cdn.shopify.com/s/files/1/0262/4071/2726/files/emptystate-files.png",children:e.jsx("p",{children:"Traffic from your promo links will appear here once visitors start arriving."})}):e.jsx("div",{style:{overflowX:"auto"},children:e.jsx(aa,{columnContentTypes:["text","numeric","numeric","numeric","numeric","numeric","numeric","numeric","numeric","numeric"],headings:[yt,"Users","Conv. Rate","Revenue","Codes Used","Code Revenue","Link Revenue","Codes Redeemed","Rev/Session","AOV"],rows:_o,totals:["Total",u.users.toLocaleString(),(u.users>0?u.conversions/u.users*100:0).toFixed(2)+"%","$"+u.revenue.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),ne.reduce((t,n)=>t+n.codesUsed,0).toLocaleString(),"$"+ne.reduce((t,n)=>t+n.codeRevenue,0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),"$"+ne.reduce((t,n)=>t+n.linkRevenue,0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}),ne.reduce((t,n)=>t+n.codesUsed,0).toLocaleString(),"$"+Te.revenuePerSession.toFixed(2),"$"+Te.aov.toFixed(2)],showTotalsInFooter:!0})})]})})})]}),e.jsx(Le,{open:xo,onClose:()=>Tr(!1),title:"Select from Media Library",size:"large",children:e.jsx(Le.Section,{children:Fn&&Rr.length===0?e.jsx(Z,{padding:"800",children:e.jsx(S,{gap:"400",align:"center",children:e.jsx(i,{as:"p",tone:"subdued",children:"Loading media files..."})})}):Rr.length===0?e.jsx(Z,{padding:"800",children:e.jsxs(S,{gap:"400",align:"center",children:[e.jsx(i,{as:"p",tone:"subdued",children:"No images found in your media library."}),e.jsx(i,{as:"p",variant:"bodySm",tone:"subdued",children:"Upload images to your Shopify Files to see them here."})]})}):e.jsxs(S,{gap:"400",children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(120px, 1fr))",gap:"12px"},children:Rr.map(t=>e.jsx("button",{onClick:()=>Co(t.url),style:{padding:"0",border:"2px solid transparent",borderRadius:"8px",background:"#f6f6f7",cursor:"pointer",aspectRatio:"1",overflow:"hidden",transition:"border-color 0.2s, transform 0.2s"},onMouseEnter:n=>{n.currentTarget.style.borderColor="#008060",n.currentTarget.style.transform="scale(1.02)"},onMouseLeave:n=>{n.currentTarget.style.borderColor="transparent",n.currentTarget.style.transform="scale(1)"},children:e.jsx("img",{src:t.url,alt:t.alt||"Media file",style:{width:"100%",height:"100%",objectFit:"cover"}})},t.id))}),vo&&e.jsx(Z,{paddingBlockStart:"400",children:e.jsx(B,{align:"center",children:e.jsx(j,{onClick:()=>Ir(yo),loading:Fn,children:"Load More"})})})]})})}),e.jsx(Le,{open:Ls,onClose:hn,title:"Shortlink Already Exists",primaryAction:{content:"Overwrite",destructive:!0,onAction:qs},secondaryActions:[{content:"Cancel",onAction:hn}],children:e.jsx(Le.Section,{children:e.jsxs(S,{gap:"300",children:[e.jsxs(i,{as:"p",children:["A redirect already exists for ",e.jsxs("strong",{children:["/",me]}),"."]}),e.jsx(i,{as:"p",children:"Do you want to overwrite the existing redirect with your new target URL?"}),e.jsx(Ve,{tone:"warning",children:"This will delete the existing redirect and create a new one pointing to your tracking link."})]})})}),ie&&e.jsx(Yo,{content:De,error:Oe,onDismiss:Ze,duration:Oe?5e3:3e3})]})})})}export{pi 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.