1import{u as C,d as q,j as e,o as D,e as J,r as h,aR as H,i as W,F as X,n as F,t as Y,v as K,h as R,a3 as L,w as Z,x as E,y as ee,q as A,z as d,I as j,A as se,B as ne,p as te,k as ie,M as le,C as re,aS as ce,aT as k}from"./index-1ZwnxBtP.js";import{F as oe}from"./Dashboard-Dq9NbOWA.js";import{B as ae}from"./BackButton-gsucH3Mk.js";import{l as P}from"./index-CsLXu3s7.js";import"./AffiliateSalesLineItemsModalNew-C90JqFvV.js";import"./StateBasedPagination-GXnzMTTz.js";import"./useDebounce-DfXLfP9X.js";import"./Dropdown-Za-Ta5Bo.js";import"./ThemeProvider-DppOPtX1.js";import"./use-isomorphic-layout-effect.browser.esm-Dlv4p7Sx.js";import"./index-v2WCNqB0.js";import"./RenderCommission-CAGJj7T-.js";import"./BootStrapPagedTable-Dx9C5Ed-.js";import"./StoreDiscountCouponAutoRedeem-Bo7Iw-zJ.js";function me(s){const n=C(r=>r.settings.gifts),{id:o}=q(),i=n.find(r=>r.id===o);return e.jsxs("div",{children:[e.jsx(ae,{}),e.jsx(ue,{gift:i})]})}function ue({gift:s}){const{data:n,isLoading:o}=D("/seeding/contact_information",J),i=(n==null?void 0:n.address)||{},[r,a]=h.useState({first_name:"",last_name:"",email:"",phone:""}),x=t=>l=>{a(p=>({...p,[t]:l}))},g=t=>l=>{b(p=>({...p,[t]:l}))};h.useEffect(()=>{a({first_name:n==null?void 0:n.first_name,last_name:n==null?void 0:n.last_name,email:n==null?void 0:n.email,phone:n==null?void 0:n.phone}),b({address1:i==null?void 0:i.address1,address2:i==null?void 0:i.address2,city:i==null?void 0:i.city,province:i==null?void 0:i.province,zip:i==null?void 0:i.zip,country:i==null?void 0:i.country})},[n]);const[c,b]=h.useState({address1:"",address2:"",city:"",province:"",zip:"",country:""}),v=s.maxProducts&&Number(s.maxProducts)<s.products.length;h.useEffect(()=>{y(v?[]:s.products.map(t=>t._id))},[v,s]);const[f,N]=h.useState({}),[m,y]=h.useState([]),$=s.products.some(t=>t.quantity>1),O=t=>()=>{y(l=>l.includes(t)?l.filter(p=>p!==t).slice(0,Number(s.maxProducts)):[...l,t].slice(0,Number(s.maxProducts)))},_=(()=>{const t=[];return m.length===0?t.push("Please choose products to redeem"):v&&m.length<Number(s.maxProducts)&&t.push("Please choose more products to redeem"),r.first_name||t.push("Please enter first name"),r.last_name||t.push("Please enter last name"),r.email||t.push("Please enter email"),r.phone||t.push("Please enter phone"),c.address1||t.push("Please enter address"),c.city||t.push("Please enter city"),c.country||t.pu
1sh("Please enter country"),c.zip||t.push("Please enter postal code"),t})(),[G,z]=h.useState(!1),[ge,ve]=h.useState(null),T=H(),B=W(),V=()=>{z(!0),te("/seeding/redeem",{giftId:s.id,shippingAddress:c,customer:r,selectedProducts:m,selectedVariations:f}).then(t=>{if(z(!1),t.error)alert(t.error);else{const{statusPageUrl:l,name:p,metadata:S}=t;B(ie({metadata:JSON.stringify(S)})),T("/gift/success/".concat(s.id))}})},Q=C(t=>t.settings.website);return e.jsxs("div",{children:[e.jsx("h3",{children:s.title}),e.jsxs("div",{className:"row g-2 mb-2",children:[e.jsx("div",{className:"col-md-6",children:e.jsxs("div",{className:"card",children:[e.jsx("div",{className:"pt-2 ps-3",children:e.jsxs("div",{className:"d-flex align-items-center justify-content-between",children:[e.jsx("div",{className:"card-title",children:"Product Information"}),m.length>0?e.jsx(M,{selectedProducts:m,onChange:O,gift:s}):null]})}),e.jsxs("div",{className:"card-body text-center ".concat(m.length>0?"d-none":""),children:[e.jsx("div",{className:"text-muted",children:"Please choose products to redeem"}),e.jsx(M,{selectedProducts:m,onChange:O,gift:s})]}),e.jsx("ul",{className:"list-group list-group-flush",children:m.map(t=>{var I;const l=s.products.find(u=>u._id===t);if(!l)return null;const p="https://".concat(Q,"/products/").concat(l.handle),S=l.images&&l.images[0]&&l.images[0].url,U=l.variationOption==="any"?f[l._id]:l.variationOption;return e.jsxs("div",{className:"list-group-item d-flex position-relative space-between py-3",children:[v?e.jsx("button",{onClick:()=>y(u=>u.filter(w=>w!==t)),className:"position-absolute btn",style:{top:0,right:0},children:e.jsx(X,{})}):null,e.jsxs("div",{className:"d-flex align-items-start gap-2",children:[e.jsx("img",{src:S,alt:"",className:"rounded border shadow-sm",style:{width:64,height:64,objectFit:"cover"}}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-0",children:l.name}),e.jsx("small",{className:"free_gift_product_url",children:e.jsxs("a",{href:p,target:"_blank",className:"text-sm d-inline-flex align-items-center gap-1 text-decoration-underline",children:["View details ",e.jsx(F,{})]})}),e.jsxs("div",{className:"mt-2",children:[$?e.jsx("div",{children:e.jsxs("span",{className:"text-muted",children:["Quantity: ",l.quantity]})}):null,l.variationOption==="any"&&l.variations.length>1?e.jsx("div",{style:{width:"200px"},children:e.jsx(Y,{defaultSelectFirst:!0,value:f[l._id],onChange:u=>{N(w=>({...w,[l._id]:u}))},options:l.variations.map(u=>({value:u.id,label:u.name}))})}):e.jsx("span",{children:(I=l.variations.find(u=>u.id===U))==null?void 0:I.name})]})]})]})]},l._id)})})]})}),e.jsxs("div",{className:"col-md-6",children:[e.jsx("div",{className:"card",children:e.jsx(xe,{data:r,onChange:x})}),e.jsx("div",{className:"card mt-2",children:e.jsx(de,{address:c,onChange:g})})]})]}),!o&&_.length>0?e.jsx("div",{className:"mt-2 alert alert-warning",children:e.jsx("ol",{className:"mb-0",children:_.map((t,l)=>e.jsx("li",{children:t},l))})}):e.jsx("div",{className:"text-center",children:e.jsx(K,{onClick:V,loading:G,disabled:_.length>0,children:"Redeem"})})]})}function he({visible:s,gift:n,toggle:o,selectedProducts:i,onChange:r}){const a=n.products.some(c=>c.quantity>1),x=C(c=>c.settings.website),g=n.maxProducts&&i.length>=Number(n.maxProducts);return e.jsxs(A,{title:"Choose Products",visible:s,onClose:o,children:[e.jsx("p",{children:e.jsx(le,{id:"free_gift_choose",defaultMessage:"Choose {num, plural, one {a free product} other {{num} free products}}",values:{num:n.maxProducts}})}),e.jsx("ul",{className:"list-group list-group-flush",children:n.products.map(c=>{var N;const b="https://".concat(x,"/products/").concat(c.handle),v=i.includes(c._id),f=!v&&g;return e.jsxs("li",{className:"list-group-item py-3\n space-between \n ".concat(f?"opacity-50":"list-group-item-action"),onClick:r(c._id),children:[e.jsxs("div",{className:"d-flex align-items-start gap-2",children:[e.jsx("img",{src:(N=c.images[0])==null?void 0:N.url,alt:"",className:"rounded border shadow-sm",style:{width:64,height:64,objectFit:"cover"}}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-0",children:c.name}),e.jsx("small",{children:e.jsxs("a",{href:b,target:"_blank",onClick:m=>{m.stopPropagation()},className:"text-sm d-inline-flex align-items-center gap-1 text-decoration-underline",children:["View details ",e.jsx(F,{})]})}),e.jsx("div",{className:"mt-2",children:a?e.jsx("div",{children:e.jsxs("span",{className:"text-muted",children:["Quantity: ",c.quantity]})}):null})]})]}),e.jsx(re,{checked:v})]})})})]})}function M({selectedProducts:s,gift:n,onChange:o}){const[i,r]=R();return n.maxProducts&&Number(n.maxProducts)<n.products.length?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"btn btn-link btn-sm",children:"Choose products"}),e.jsx(he,{visible:i,toggle:r,selectedProducts:s,gift:n,onChange:o})]}):null}function de({address:s,onChange:n}){const[o,i]=R();return e.jsxs(L.Fragment,{children:[e.jsxs("div",{className:"card-body",children:[e.jsxs("div",{className:"d-flex align-items-center justify-content-between",children:[e.jsx("div",{className:"card-title",children:"Shipping Address"}),e.jsx("button",{onClick:i,className:"btn btn-link btn-sm",children:"Edit"})]}),e.jsxs("div",{children:[s==null?void 0:s.address1," ",s==null?void 0:s.address2,e.
1jsx("br",{}),s==null?void 0:s.city,", ",s==null?void 0:s.province,", ",s==null?void 0:s.zip,e.jsx("br",{}),s==null?void 0:s.country]})]}),e.jsxs(A,{visible:o,onClose:i,title:"Shipping Address",children:[e.jsx(d,{label:"Address Line 1",required:!0,children:e.jsx(j,{value:s==null?void 0:s.address1,onChange:n("address1")})}),e.jsx(d,{label:"Address Line 2",children:e.jsx(j,{value:s==null?void 0:s.address2,onChange:n("address2")})}),e.jsxs("div",{className:"row",children:[e.jsx("div",{className:"col-md-6",children:e.jsx(d,{label:"City",required:!0,children:e.jsx(j,{value:s==null?void 0:s.city,onChange:n("city")})})}),e.jsx("div",{className:"col-md-6",children:e.jsx(d,{label:"Province",children:e.jsx(j,{value:s==null?void 0:s.province,onChange:n("province")})})})]}),e.jsxs("div",{className:"row",children:[e.jsx("div",{className:"col-md-6",children:e.jsx(d,{label:"Country",required:!0,children:e.jsx(ne,{value:s==null?void 0:s.country,onChange:r=>{n("country")(r.target.value)}})})}),e.jsx("div",{className:"col-md-6",children:e.jsx(d,{label:"Postal Code",required:!0,children:e.jsx(j,{value:s==null?void 0:s.zip,onChange:n("zip")})})})]})]})]})}function xe({data:s,onChange:n}){const[o,i]=R();return e.jsxs(L.Fragment,{children:[e.jsxs("div",{className:"card-body",children:[e.jsxs("div",{className:"d-flex align-items-center justify-content-between",children:[e.jsx("div",{className:"card-title",children:"Contact Information"}),e.jsx("button",{onClick:i,className:"btn btn-link btn-sm",children:"Edit"})]}),e.jsxs("div",{className:"d-flex align-items-center gap-2",children:[e.jsx(Z,{})," ",e.jsxs("span",{children:[s==null?void 0:s.first_name," ",s==null?void 0:s.last_name]})]}),e.jsxs("div",{className:"d-flex align-items-center gap-2",children:[e.jsx(E,{})," ",e.jsx("span",{children:s==null?void 0:s.email})]}),e.jsxs("div",{className:"d-flex align-items-center gap-2",children:[e.jsx(ee,{})," ",e.jsx("span",{children:s==null?void 0:s.phone})]})]}),e.jsxs(A,{visible:o,title:"Contact Information",onClose:i,onOk:i,okText:"Submit",children:[e.jsxs("div",{className:"row",children:[e.jsx("div",{className:"col-md-6",children:e.jsx(d,{label:"First Name",children:e.jsx(j,{value:s==null?void 0:s.first_name,onChange:n("first_name")})})}),e.jsx("div",{className:"col-md-6",children:e.jsx(d,{label:"Last Name",children:e.jsx(j,{value:s==null?void 0:s.last_name,onChange:n("last_name")})})})]}),e.jsx(d,{label:"Email address",children:e.jsx(j,{value:s==null?void 0:s.email,onChange:n("email"),prefix:e.jsx(E,{})})}),e.jsx(d,{label:"Phone",children:e.jsx(se,{value:s==null?void 0:s.phone,onChange:r=>n("phone")(r.target.value)})})]})]})}function pe(s){const{id:n}=q(),o=C(g=>g.settings.metadata),r=(o?JSON.parse(o):{}).gift_redemptions||[],a=h.useRef(null),x=r.find(g=>g.giftId===n);return h.useEffect(()=>{if(a&&a.current)return P.confetti(a.current,{count:P.variation.range(50,100),size:P.variation.range(.5,2),spread:P.variation.range(50,70)}),()=>{}},[a]),x?e.jsxs("div",{children:[e.jsx("div",{className:"fs-2 text-center",ref:a,children:"ð Your order is on the way"}),e.jsx("div",{className:"text-center",children:e.jsxs("a",{href:x==null?void 0:x.statusPageUrl,target:"_blank",children:["Track order ",e.jsx(F,{})]})})]}):e.jsx("div",{children:"Order not found"})}function ze(s){return e.jsxs(ce,{children:[e.jsx(k,{path:"/",element:e.jsx(oe,{})}),e.jsx(k,{path:"success/:id",element:e.jsx(pe,{})}),e.jsx(k,{path:"/:id",element:e.jsx(me,{})})]})}export{ze as default}; 2//# sourceMappingURL=FreeGiftIndex-C92pAPqj.js.map
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.