1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2487],{71036:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/gift",function(){return a(7538)}])},69413:function(e,t,a){"use strict";a.d(t,{F:function(){return l},U:function(){return n}});var i=a(85893),s=a(33637);const n=e=>{let{label:t,value:a,separator:n}=e;return n?(0,i.jsx)(s.i,{className:"m-0!"}):(0,i.jsxs)("dl",{className:"grid md:grid-flow-col grid-flow-row text-[14px] md:text-[16px]",children:[(0,i.jsx)("dt",{className:"md:col-start-1 font-semibold min-w-full md:min-w-[120px]",children:t}),(0,i.jsx)("dd",{className:"md:col-start-2 md:text-right",children:a})]})},l=e=>{let{children:t,className:a,gap:s=2}=e;return(0,i.jsx)("div",{className:"flex flex-col gap-".concat(s," ").concat(a),children:t})}},33441:function(e,t,a){"use strict";a.d(t,{F:function(){return l}});var i=a(85893),s=a(20373),n=a(7515);const l=()=>(0,i.jsx)(n.T3,{title:"Redirecting...",children:(0,i.jsx)(s.Z,{cssOverride:{display:"block"},className:"m-auto"})})},46677:function(e,t,a){"use strict";a.d(t,{K:function(){return p}});var i=a(85893),s=a(67294),n=a(7456),l=a(89827),r=a(4037),o=a(72048),c=a(18083),d=a(44156),m=a(33378);const u=e=>{let{giftTemplateOptions:t,giftTemplatesData:a,onGiftSelect:s}=e;return(0,i.jsxs)("fieldset",{children:[(0,i.jsx)("legend",{className:"sr-only",children:"Select your design"}),(0,i.jsx)("div",{className:"grid gap-5 grid-cols-1 sm:grid-cols-2 lg:grid-cols-1 xl:grid-cols-2",children:null===t||void 0===t?void 0:t.map((e=>{var t;const n=null===a||void 0===a||null===(t=a.GiftTemplate)||void 0===t?void 0:t.find((t=>t.Id===e.value));return n?(0,i.jsx)("div",{children:(0,i.jsxs)("div",{className:"relative h-full mb-4",children:[(0,i.jsxs)(d.Hp,{className:"w-full",onClick:()=>s(n.Id),children:[(0,i.jsx)("div",{className:"overflow-clip hover:shadow-[0px_0px_20px_0px_rgba(0,0,0,0.25)] transition-shadow duration-300",children:(0,i.jsx)(c.E,{alt:n.Description,layout:"responsive",width:600,height:424,src:"".concat("https://assets.treesthatcount.co.nz","/").concat(n.Preview)})}),(0,i.jsx)("div",{className:"mt-3 mb-2",children:(0,i.jsx)(m.S,{variant:"h5",color:"forestDeep",children:n.Title})})]}),(0,i.jsx)(m.S,{variant:"paragraph",children:n.Description})]})},e.value):null}))})]})},p=e=>{let{onGiftTemplateSelect:t,category:a}=e;var c,d;const{data:m}=(0,l.zF)(),{currentPage:p,limit:f,offset:v,onPageClick:h}=(0,r.h)({limit:6}),x=(0,s.useMemo)((()=>{const e={IsBulkOnly:{_eq:!1},IsAvailable:{_eq:!0}};return a&&"all"!==a&&(e.TemplateCategories={GiftCategoryId:{_eq:a}}),e}),[a]),{data:g}=(0,l.LQp)({variables:{offset:v,where:x,limit:6}});(0,s.useEffect)((()=>{m&&g&&(0,o.L)("view_item_list",{items:g.GiftTemplate.map(((e,t)=>{var i;return{item_id:e.Id,item_name:e.Title,item_list_name:"Gift list",item_category:(null===m||void 0===m||null===(i=m.GiftCategory.find((e=>e.Id===a)))||void 0===i?void 0:i.Name)||"All",quantity:1,price:10,index:t}}))})}),[m,g,a]);const y=(null===g||void 0===g||null===(d=g.GiftTemplate_aggregate)||void 0===d||null===(c=d.aggregate)||void 0===c?void 0:c.count)||0,j=(0,s.useMemo)((()=>{return e=null===g||void 0===g?void 0:g.GiftTemplate,t=a,(null===e||void 0===e?void 0:e.reduce(((e,a)=>{var i;return"all"===t||(null===(i=a.TemplateCategories)||void 0===i?void 0:i.find((e=>e.GiftCategoryId===t)))?[...e,{label:"".concat(a.Title," - ").concat(a.Description),value:a.Id}]:[...e]}),[]))||[];var e,t}),[g,a]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(u,{giftTemplateOptions:j,giftTemplatesData:g,onGiftSelect:async e=>{var i;const s=g?null===g||void 0===g?void 0:g.GiftTemplate.findIndex((t=>t.Id===e)):-1,n=-1!==s&&(null===g||void 0===g?void 0:g.GiftTemplate[s]),l=(null===m||void 0===m||null===(i=m.GiftCategory.find((e=>e.Id===a)))||void 0===i?void 0:i.Name)||"All";n&&(0,o.L)("add_to_cart",{items:[{item_id:null===n||void 0===n?void 0:n.Id,item_name:null===n||void 0===n?void 0:n.Title,item_list_name:"Gift list",item_category:l,quantity:1,price:10,index:s}]}),await t(e)}}),(0,i.jsx)("div",{className:"flex justify-center",children:(0,i.jsx)(n.D,{count:y,onChange:e=>{h(e),window.scrollTo({behavior:"smooth",top:0})},page:p,pageSize:f})})]})}},7456:function(e,t,a){"use strict";a.d(t,{D:function(){return r}});var i=a(85893),s=a(8172),n=a(50788);const l={prev_page:"Previous page",next_page:"Next page"},r=e=>{let{count:t,page:a,pageSize:r,onChange:o,showQuickJumper:c=!1}=e;return t&&a&&r?(0,i.jsx)("div",{className:"my-6",children:(0,i.jsx)(s.Z,{current:a,jumpNextIcon:(0,i.jsx)("span",{"aria-hidden":!0,
1children:"\u2026"}),jumpPrevIcon:(0,i.jsx)("span",{"aria-hidden":!0,children:"\u2026"}),locale:l,nextIcon:(0,i.jsx)(n.FNi,{}),onChange:o,pageSize:r,prefixCls:"rc-pagination-rebrand",prevIcon:(0,i.jsx)(n.G1X,{}),total:t,showQuickJumper:c&&{goButton:"Go to page"}})}):null}},81438:function(e,t,a){"use strict";a.d(t,{S:function(){return o}});var i=a(85893),s=a(25675),n=a.n(s),l=a(24276),r=a(89827);const o=e=>{let{showLoader:t=!1,templateData:a,gift:s,alt:o,...c}=e;var d,m;const{data:u,loading:p}=(0,r.ZBX)({variables:{input:{FromName:s.FromName,ToName:s.ToName,Message:s.Message,Trees:s.Trees,TemplateId:a.Id}}});return(0,i.jsx)(l.T,{isLoading:t&&p||!(null===u||void 0===u||null===(d=u.get_gift_preview)||void 0===d?void 0:d.base64Data),children:(0,i.jsx)(n(),{alt:a.Description||o,className:"rounded-lg",layout:"responsive",src:"data:image/jpeg;base64, ".concat(null===u||void 0===u||null===(m=u.get_gift_preview)||void 0===m?void 0:m.base64Data),...c})})}},4037:function(e,t,a){"use strict";a.d(t,{h:function(){return l}});var i=a(11163),s=a(67294);const n={offset:0,page:1},l=e=>{const{limit:t=10}=e||{},a=(0,i.useRouter)(),l=(0,s.useMemo)((()=>({limit:parseInt(a.query.limit,10),offset:parseInt(a.query.offset,10),page:parseInt(a.query.page,10)})),[a.query]);(0,s.useEffect)((()=>{if(!a.query.limit||!a.query.offset||!a.query.page){const e={...n,limit:t};Object.entries(e).forEach((e=>{let[t,i]=e;a.query[t]=i})),a.replace({pathname:a.pathname,query:a.query},void 0,{shallow:!0})}}),[a.query]);return{currentPage:l.page||n.page,limit:l.limit||t,offset:l.offset||n.offset,onPageClick:e=>{const t=e&&(null===l||void 0===l?void 0:l.limit)?(e-1)*l.limit:0;a.query.offset="".concat(t),a.query.page="".concat(e),a.push({pathname:a.pathname,query:a.query},void 0,{shallow:!0})},resetPagination:()=>{delete a.query.limit,delete a.query.offset,delete a.query.page,a.push({pathname:a.pathname,query:a.query},void 0,{shallow:!0})}}}},54281:function(e,t,a){"use strict";a.d(t,{hS:function(){return r},nW:function(){return n},p3:function(){return l},vv:function(){return o}});var i=a(23450),s=a.n(i);const n=(e,t)=>{var a;return(null===e||void 0===e?void 0:e.reduce(((e,t)=>{var a,i;if(0===(null===(a=t.TemplateCategories_aggregate.aggregate)||void 0===a?void 0:a.count))return e;const n="".concat(t.Name," (").concat(s()("card",(null===(i=t.TemplateCategories_aggregate.aggregate)||void 0===i?void 0:i.count)||0,!0),")");return[...e,{label:n,value:t.Id}]}),[{label:"All categories (".concat(s()("card",(null===t||void 0===t||null===(a=t.aggregate)||void 0===a?void 0:a.count)||0,!0),")"),value:"all"}]))||[]};var l,r;!function(e){e.Immediately="immediately",e.SpecificDateTime="specific_datetime"}(l||(l={})),function(e){e.Self="self",e.Recipients="recipients"}(r||(r={}));const o=[{label:"Immediately",value:"immediately"},{label:"Schedule for later",value:"specific_datetime"}]},7538:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return je}});var i=a(85893),s=a(67294),n=a(47788),l=a(43748),r=a(33378),o=a(1027),c=a(7515),d=a(33712),m=a(20512),u=a(11163),p=a(93519),f=a(29854),v=a(53719),h=a(56959),x=a(59375),g=a(67423),y=a(54281),j=a(13508),b=a(82999),N=a(33637),I=a(82784),w=a(91522),G=a(46677),S=a(89827),C=a(27518),P=a(13612);const R=()=>{const e=(0,m.u6)(),{setFieldValue:t,values:a}=e,{loginWithCustomRedirect:n}=(0,j.a)(),{setValue:l}=(0,h.Y)({key:"giftForm"}),{user:o}=(0,v.a)(),c=(0,u.useRouter)(),{category:d}=c.query,{data:p}=(0,S.zF)(),f=(0,s.useMemo)((()=>(0,y.nW)(null===p||void 0===p?void 0:p.GiftCategory,null===p||void 0===p?void 0:p.GiftTemplate_aggregate)),[p]);return(0,s.useEffect)((()=>{if(d){const e=null===p||void 0===p?void 0:p.GiftCategory.find((e=>e.Name===d));e&&t("Category",e.Id)}}),[d,p,t]),(0,i.jsxs)("div",{className:"flex flex-col lg:flex-row gap-5 md:gap-10",children:[(0,i.jsxs)("div",{className:"bg-white p-5 md:p-10",children:[(0,i.jsxs)("div",{className:"mb-4",children:[(0,i.jsx)("div",{className:"mb-2",children:(0,i.jsx)(r.S,{variant:"h4",color:"forestDeep",children:(0,i.jsx)("strong",{children:"Select an e-card design"})})}),(0,i.jsx)(r.S,{variant:"paragraph",children:"Filter by category and browse the designs below to select an e-card to send. Each features precious n
1ative plant and wildlife species \u2014 from towering rimu to endemic t\u012beke."}),(0,i.jsx)(I.j,{type:"infoNew",className:"mb-10!",children:"You can add recipients and/or change card designs in the next step."})]}),(0,i.jsx)(w.W,{id:"Category",label:"Filter by category",labelClassName:"text-forestDeep! font-body-rebrand",options:f,type:P.IY.select,onChange:async e=>{const t=null===p||void 0===p?void 0:p.GiftCategory.find((t=>t.Id===e.currentTarget.value));await c.replace({query:{category:null===t||void 0===t?void 0:t.Name}},void 0,{scroll:!1})}}),(0,i.jsx)(G.K,{onGiftTemplateSelect:async e=>{l({...a,GiftTemplateId:e,Gifts:[{...a.Gifts[0]||{},GiftTemplateId:e}]}),o?await c.push((0,C.EL)({routeParams:{stepIndex:"0"}})):await n((0,C.zO)({queryParams:{stepIndex:0}}),(0,C.EL)({routeParams:{stepIndex:"0"}}))},category:a.Category})]}),(0,i.jsxs)("div",{className:"bg-white self-start flex shrink-0 flex-col w-full lg:w-[415px] p-5 md:p-10",children:[(0,i.jsxs)("div",{className:"mb-10",children:[(0,i.jsx)("div",{className:"mb-2",children:(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"More than 10 recipients?"})}),(0,i.jsx)(r.S,{variant:"paragraph",children:"If you've got a hefty list to tick off, try our bulk gift template."}),(0,i.jsx)(b.J,{href:(0,C.Me)(),variant:"lime",className:"self-start",children:"Use bulk gift"})]}),(0,i.jsx)(N.i,{className:"m-0!"}),(0,i.jsxs)("div",{className:"mt-10 mb-10",children:[(0,i.jsx)("div",{className:"mb-2",children:(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Need a hand?"})}),(0,i.jsx)(r.S,{variant:"paragraph",children:"Get in touch and we can help you with your order."}),(0,i.jsx)(b.J,{href:C.Le,variant:"outline",className:"self-start",children:"Contact us"})]})]})]})};var D=a(86250),_=a(50788),T=a(84e3),M=a(69413),E=a(59736),A=a(7456),F=a(4037),q=a(36620),k=a(43974);const W=e=>{const{resetForm:t}=(0,m.u6)();return(0,i.jsx)(k.x,{...e,onCancel:()=>t()})};var U=a(27060),L=a(55346),O=a(44156),Y=a(75850),V=a(33562),Z=a(98173),B=a(81438),Q=a(73967);const X=e=>{let{recipient:t}=e;const{data:a}=(0,S.LQp)({variables:{offset:0,where:{IsBulkOnly:{_eq:!1},IsAvailable:{_eq:!0}}}}),n=(0,s.useMemo)((()=>null===a||void 0===a?void 0:a.GiftTemplate.find((e=>e.Id===t.GiftTemplateId))),[null===a||void 0===a?void 0:a.GiftTemplate,t.GiftTemplateId]);return(0,i.jsxs)("div",{className:"flex flex-col xl:flex-row bg-linen p-5 lg:p-10 gap-[10px] lg:gap-10 text-left",children:[(0,i.jsx)("div",{className:"flex-1",children:(0,i.jsxs)(M.F,{gap:4,children:[(0,i.jsx)(M.U,{label:"To",value:t.RecipientName}),(0,i.jsx)(M.U,{label:"Email",value:t.RecipientEmail}),(0,i.jsx)(M.U,{label:"From",value:t.From}),(0,i.jsx)(M.U,{label:"Message",value:(0,i.jsx)("p",{children:t.Message})}),(0,i.jsx)(M.U,{label:"Number of trees",value:t.Quantity}),(0,i.jsx)(M.U,{separator:!0}),(0,i.jsx)(M.U,{label:"Send e-cards to",value:t.GiftsDestination===y.hS.Recipients?"Recipient":"Me"}),t.GiftsDestination===y.hS.Self?(0,i.jsx)("div",{className:"italic text-left",children:(0,i.jsx)(r.S,{variant:"paragraph",children:"We'll send you a link to the e-cards to this email address."})}):null,t.GiftsDestination===y.hS.Recipients?(0,i.jsx)(M.U,{label:"Scheduled time",value:t.DeliveryDatetimeWhen===y.p3.Immediately?"Immediately":(0,Q.p6)({date:t.DeliverOn.toString(),format:"DD/MM/YYYY HH:mm",isUtc:!0})}):null]})}),(0,i.jsx)("div",{className:"overflow-clip flex-1",children:n?(0,i.jsx)(B.S,{alt:"Gift preview",templateData:n,gift:{FromName:t.From,ToName:t.RecipientName,ToEmail:t.RecipientEmail,Message:t.Message,Trees:Number(t.Quantity)},width:520,height:387}):null})]})},z=e=>{let{Gifts:t}=e;const a=(0,V.Z)("(max-width: 1024px)"),[n]=(0,S.pJ1)(),[l,r]=(0,s.useState)({}),[o,c]=(0,s.useState)(new Set);(0,s.useEffect)((()=>{Array.from(new Set(t.map((e=>e.PlantingRegionId)).filter((e=>Boolean(e))))).forEach((async e=>{if(!o.has(e))try{var t;const{data:a}=await n({variables:{regionId:e}});if(null===a||void 0===a||null===(t=a.Region)||void 0===t?void 0:t[0]){const t=a.Region[0],i=[t.Name,t.AltName].filter(Boolean).join(" - ");r((t=>({...t,[e]:i})))}c((t=>new Set(t).add(e)))}catch(a){(0,Z.H)(a)}}))}),[t,n,o]);const d=e=>e?l[e]||"Loading...":"Where trees are needed most",m=(0,U.Cl)(),u=[m.accessor("Index",{cell:e=>{const{RecipientName:t,RecipientEmail:a,From:s,Message:n,Quantity:l,GiftsDestination:r,PlantingRegionId:o}=e.row.original;return(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsxs)(M.F,{className:"bg-transparent mb-4",children:[(0,i.jsx)(M.U,{label:"To",value:t}),(0,i.jsx)(M.U,{label:"Recipient email",value:r===y.hS.Self?"Me (".concat(a,")"):a}),(0,i.jsx)(M.U,{label:"From",value:s}),(0,i.jsx)(M.U,{label:"Message",value:n}),(0,i.jsx)(M.U,{label:"To",value:t}),(0,i.jsx)(M.U,{label:"Number of trees",value:l}),(0,i.jsx)(M.U,{label:"Preferred planting region",value:d(o)})]}),(0,i.jsxs)(O.Hp,{color:"forestDeep",className:"text-sm font-semibold",type:"button",children:["Preview card",e.row.getIsExpanded()?(0,i.jsx)(L.s$2,{className:"inline mx-2"}):(0,i.jsx)(L.RiI,{className:"inline mx-2"})]})]})}})],p=[m.accessor("RecipientName",{header:"To",cell:e=>(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsx)("span",{className:"block",children:e.getValue()}),(0,i.jsxs)(O.Hp,{color:"forestDeep",className:"text-sm font-semibold",type:"button",children:["Preview card",e.row.getIsExpanded()?(0,i.jsx)(L.s$2,{className:"inline mx-2"}):(0,i.jsx)(L.RiI,{className:"inline mx-2"})]})]})}),m.accessor("RecipientEmail",{header:"Recipient email",cell:e=>e.row.original.GiftsDestination===y.hS.Self?"Me (".concat(e.getValue(),")"):e.getValue()}),m.accessor("From",{header:"From",cell:e=>e.getValue()}),m.accessor("Message",{header:"Message",cell:e=>e.getValue()}),m.accessor("Quantity",{header:"Trees qty",size:140,meta:{align:"right"},cell:e=>e.getValue()}),m.accessor("PlantingRegionId",{header:"Planting region",cell:e=>d(e.getValue())})],f=a?u:p;
1return(0,i.jsx)(Y.i,{className:"table-auto! mt-0! lg:mt-8!",headerClasses:"py-5! text-left! lg:last:text-right!",cellClasses:"py-5! text-left! px-4! lg:last:text-right! align-top text-base font-medium",subComponentClasses:"pt-2!",isSelectable:()=>!0,onSelect:(e,t)=>{t.toggleExpanded()},data:t,columns:f,showHeader:!a,renderSubComponent:e=>{let{row:t}=e;return(0,i.jsx)(X,{recipient:t.original})}})},H=()=>{var e;const{nextStep:t,stepIndex:a,steps:n}=(0,f.t)(),l=(0,u.useRouter)(),o=(0,m.u6)(),{values:c,setFieldValue:d}=o,{currentPage:p,limit:h,onPageClick:x,resetPagination:j}=(0,F.h)({limit:10}),{user:I,memberships:w}=(0,v.a)(),G=(0,s.useMemo)((()=>c.Gifts.reduce(((e,t)=>e+Number(t.Quantity)),0)),[c.Gifts]),{productPrice:C}=(0,q.u)(G,!0);(0,s.useEffect)((()=>{j()}),[]),(0,s.useEffect)((()=>{if(C&&G){d("Amount",(C*(G||0)).toString())}}),[C,G]);const P=(0,s.useMemo)((()=>{const e=(p-1)*h;return c.Gifts.slice(e,p*h)}),[p,h,c.Gifts]),[R,{data:k}]=(0,S.pJ1)(),U=(0,s.useMemo)((()=>{const e=c.Gifts.map((e=>e.PlantingRegionId)).filter((e=>Boolean(e)));return[...new Set(e)]}),[c.Gifts]);(0,s.useEffect)((()=>{U.length>0&&U.forEach((e=>{R({variables:{regionId:e}})}))}),[R,U]);const L=(0,s.useMemo)((()=>{var e;const t={};if(null===k||void 0===k||null===(e=k.Region)||void 0===e?void 0:e[0]){const e=k.Region[0],a=[e.Name,e.AltName].filter(Boolean).join(" - ");U.forEach((e=>{t[e]=a}))}return t}),[null===k||void 0===k?void 0:k.Region,U]),O=(0,s.useMemo)((()=>{const e=c.Gifts.map((e=>e.PlantingRegionId));return e.every((t=>t===e[0]))}),[c.Gifts]),Y=(0,s.useMemo)((()=>{var e;if(!O)return null;const t=null===(e=c.Gifts[0])||void 0===e?void 0:e.PlantingRegionId;return t?L[t]:"Where trees are needed most"}),[O,c.Gifts,L]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"mb-5 md:mb-10",children:(0,i.jsx)(r.S,{variant:"h3",color:"forestDeep",children:(0,i.jsx)("strong",{children:"Review messages and details"})})}),(0,i.jsxs)("div",{className:"flex flex-col gap-5 md:gap-10",children:[(0,i.jsxs)("div",{className:"w-full lg:w-1/2",children:[(0,i.jsx)("div",{className:"mb-4",children:(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Summary"})}),(0,i.jsxs)(M.F,{className:"bg-linen p-5",children:[I?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(M.U,{label:(0,i.jsxs)("span",{className:"align-middle",children:["Account name",((null===w||void 0===w?void 0:w.length)||0)>1?(0,i.jsx)(E.u,{overlay:(0,i.jsxs)("div",{className:"text-center px-[18px] py-[10px]",children:["Looks like you have multiple accounts. You can change the account you're sending these gifts from using the account menu on the top-right."," ",(0,i.jsx)("br",{}),"Please note, you'll have to re-upload your order."]}),children:(0,i.jsx)(D.gOU,{className:"text-forestDeep w-5 h-5 inline ml-[10px]"})}):null]}),value:null===I||void 0===I||null===(e=I.Account)||void 0===e?void 0:e.Name}),(0,i.jsx)(M.U,{separator:!0})]}):null,(0,i.jsx)(M.U,{label:"No. of trees",value:G}),(0,i.jsx)(M.U,{label:"Price per tree",value:(0,i.jsx)(T.F,{amount:C})}),(0,i.jsx)(M.U,{label:"No. of recipients",value:c.Gifts.length}),Y&&"Where trees are needed most"!==Y?(0,i.jsxs)("dl",{className:"grid gap-y-2 mb-4",children:[(0,i.jsx)("dt",{className:"col-start-1 font-semibold mr-4",children:"Preferred planting region"}),(0,i.jsx)("dd",{className:"col-start-2 text-right",children:Y})]}):null,(0,i.jsx)(N.i,{className:"my-2!"}),(0,i.jsx)(M.U,{label:"Amount to pay (NZD)",value:(0,i.jsx)(T.F,{amount:c.Amount})})]})]}),(0,i.jsxs)("div",{className:"mb-10",children:[(0,i.jsx)("div",{className:"mb-2",children:(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Recipients"})}),(0,i.jsx)(r.S,{variant:"paragraph",children:"Preview and update your card and message details as needed."}),(0,i.jsx)(z,{Gifts:P}),(0,i.jsxs)(b.B,{className:"mt-5",variant:"forest",onClick:async()=>{d("Gifts",[...c.Gifts,{Amount:0,DeliverOn:null,DeliveryDatetimeWhen:y.p3.Immediately,GiftsDestination:y.hS.Recipients,From:"",GiftTemplateId:c.GiftTemplateId,Index:Math.max(...c.Gifts.map((e=>e.Index)))+1,Message:"",Quantity:1,RecipientEmail:"",RecipientName:"",PlantingRegionId:null}],!0).then((()=>{(0,g.t)(l,n.length,a-1)}))},children:["Add another recipient ",(0,i.jsx)(_.NcC,{className:"ml-2"})]}),(0,i.jsx)(A.D,{page:p,pageSize:h,count:c.Gifts.length,onChange:x})]})]}),(0,i.jsx)(W,{submitText:"Next",onSubmit:()=>{t()}})]})};var $=a(86664),J=a(27484),K=a.n(J),ee=a(50259),te=a(82950),ae=a(36634),ie=a(9488),se=a(71165),ne=a(67851),le=a(72048);const re=()=>{var e;const{executeRecaptcha:t}=(0,ee.xX)(),a=(0,s.useRef)(t);(0,s.useEffect)((()=>{a.current=t}),[t]);const{validateStep:n}=(0,f.t)(),{setValue:o}=(0,h.Y)({key:"giftForm"}),c=(0,m.u6)(),{isSubmitting:d,setFieldValue:p,values:g}
1=c,{processing:b,succeeded:G,setProcessing:R,setSucceeded:D}=(0,l.V)(),[_,E]=(0,s.useState)(!1),{data:A}=(0,S.zF)(),{data:F}=(0,S.LQp)({variables:{offset:0,where:{IsBulkOnly:{_eq:!1},IsAvailable:{_eq:!0}}}}),q=(0,$.useStripe)(),k=(0,$.useElements)(),U=(0,u.useRouter)(),{user:L}=(0,v.a)(),{login:Y}=(0,j.a)(),V=(0,s.useMemo)((()=>g.Gifts.reduce(((e,t)=>e+parseInt("".concat(t.Quantity))),0)),[g.Gifts]),Z=(0,s.useMemo)((()=>g.Gifts.every((e=>e.DeliveryDatetimeWhen===y.p3.SpecificDateTime))),[g.Gifts]),{productPrice:B}=(0,ne.u)(V,!0);(0,s.useEffect)((()=>{p("Amount",(V*B).toString()),g.Gifts.some((e=>e.DeliveryDatetimeWhen===y.p3.Immediately))&&p("PaymentMethod",x.XL.CreditCard)}),[V,B,p,g.Gifts]);const Q=!(!d&&q&&k&&!b&&!G);(0,s.useEffect)((()=>{B&&g.Gifts.forEach(((e,t)=>{p("Gifts.".concat(t,".Amount"),parseInt("".concat(e.Quantity))*B)}))}),[B]);const[X]=(0,S.iBL)(),[z]=(0,S.xFd)(),[H]=(0,S.skJ)(),J=(0,s.useMemo)((()=>L?Number(g.Amount)>99&&!Z?"Invoice payment is not available if you have one or more gifts:\n\n1. To be sent to you, and/or\n2. To be sent immediately":Number(g.Amount)>99&&Z&&g.PaymentMethod===x.XL.Invoice?"If your scheduled delivery date is soon, you may want to use a credit card as payment. Your gift will not be sent until your invoice clears.":null:null),[Z,L,g.Amount,g.PaymentMethod]),re=(0,s.useMemo)((()=>{var e,t;let a=[];return a=[{label:(null===L||void 0===L||null===(e=L.Account)||void 0===e?void 0:e.PaymentMethodDescriptor)?"Different card, Google Pay, or Apple Pay":"Credit or debit card",value:x.XL.CreditCard,disabled:!1}],(null===L||void 0===L||null===(t=L.Account)||void 0===t?void 0:t.PaymentMethodDescriptor)&&(a=[{label:"Saved card (".concat(L.Account.PaymentMethodDescriptor,")"),value:"SavedCreditCard",disabled:!L},...a]),Number(g.Amount)>99&&(a=[{label:"By invoice",value:x.XL.Invoice,disabled:!L||!Z},...a]),a}),[L,Z,g.Amount]),[oe,{data:ce}]=(0,S.pJ1)(),de=(0,s.useMemo)((()=>{var e;const t={};if(null===ce||void 0===ce||null===(e=ce.Region)||void 0===e?void 0:e[0]){const e=ce.Region[0],a=[e.Name,e.AltName].filter(Boolean).join(" - ");t[e.Id]=a}return t}),[null===ce||void 0===ce?void 0:ce.Region]);(0,s.useEffect)((()=>{Array.from(new Set(g.Gifts.map((e=>e.PlantingRegionId)).filter((e=>Boolean(e))))).forEach((e=>{e&&"choose_for_me"!==e&&oe({variables:{regionId:e}})}))}),[oe,g.Gifts]);const me=(0,s.useMemo)((()=>{const e=g.Gifts.map((e=>e.PlantingRegionId));return e.every((t=>t===e[0]))}),[g.Gifts]),ue=(0,s.useMemo)((()=>{var e;if(!me)return null;const t=null===(e=g.Gifts[0])||void 0===e?void 0:e.PlantingRegionId;return t&&"choose_for_me"!==t?de[t]||"Loading...":"Where trees are needed most"}),[me,g.Gifts,de]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"mb-4",children:(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Summary"})}),(0,i.jsx)("div",{className:"mb-5 md:mb-10 w-full lg:w-1/2",children:(0,i.jsxs)(M.F,{className:"bg-linen p-5",children:[(0,i.jsx)(M.U,{label:"No. of trees",value:V}),(0,i.jsx)(M.U,{label:"Price per tree",value:(0,i.jsx)(T.F,{amount:B})}),(0,i.jsx)(M.U,{label:"No. of recipients",value:g.Gifts.length}),ue&&"Where trees are needed most"!==ue?(0,i.jsxs)("dl",{className:"grid gap-y-2 mb-4",children:[(0,i.jsx)("dt",{className:"col-start-1 font-semibold mr-4",children:"Preferred planting region"}),(0,i.jsx)("dd",{className:"col-start-2 text-right",children:ue})]}):null,(0,i.jsx)(N.i,{className:"my-2!"}),(0,i.jsx)(M.U,{label:"Amount to pay (NZD)",value:(0,i.jsx)(T.F,{amount:g.Amount})})]})}),(0,i.jsx)(ae.B,{handleReceiptNameBlur:e=>{p("ReceiptName",e.target.value)},paymentMethod:g.PaymentMethod}),(0,i.jsx)(N.i,{}),(0,i.jsxs)("div",{className:"my-8",children:[(0,i.jsx)("div",{className:"mb-4",children:(0,i.jsx)(r.S,{variant:"h3",color:"forestDeep",children:(0,i.jsx)("strong",{children:"Payment"})})}),re.length>1&&(0,i.jsx)(w.W,{id:"PaymentMethod",label:"Payment method",description:L?"":(0,i.jsxs)("div",{children:["Please"," ",(0,i.jsx)(O.Hp,{color:"forestDeep",className:"underline hover:no-underline",onClick:Y,children:"sign in"})," ","to pay by invoice"]}),type:P.IY.radioGroup,options:re}),J?(0,i.jsx)(I.j,{className:"whitespace-pre-wrap",type:"warning",children:J}):null,g.PaymentMethod===x.XL.Invoice&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Pay by invoice"}),(0,i.jsx)(w.W,{id:"InvoiceAddress.InvoiceAddress0",label:"Address Line 1",type:P.IY.text}),(0,i.jsx)(w.W,{id:"InvoiceAddress.InvoiceAddress1",label:"Address Line 2",type:P.IY.text}),(0,i.jsxs)("div",{className:"flex space-x-4",children:[(0,i.jsx)(w.W,{id:"InvoiceAddress.InvoiceCity",label:"City",type:P.IY.text}),(0,i.jsx)(w.W,{id:"InvoiceAddress.InvoicePostCode",label:"Post Code",type:P.IY.text})]}),(0,i.jsx)(w.W,{id:"InvoiceAddress.InvoiceCountry",label:"Country",type:P.IY.text})]}),g.PaymentMethod===x.XL.CreditCard&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Credit/Debit card"}),(0,i.jsx)(ie.O,{onChange:e=>{var t,a;e.complete&&(t="add_payment_info",A&&F&&(0,le.L)(t,{currency:"NZD",value:Number(g.Amount),payment_type:g.PaymentMethod,transaction_id:a,items:g.Gifts.map(((e,t)=>{var a;const i=null===F||void 0===F?void 0:F.GiftTemplate.find((t=>t.Id===e.GiftTemplateId)),s=(null===A||void 0===A||null===(a=A.GiftCategory.find((e=>{var t;return e.Id===(null===i||void 0===i||null===(t=i.TemplateCategories[0])||void 0===t?void 0:t.GiftCategoryId)})))||void 0===a?void 0:a.Name)||"All";return{item_id:null===i||void 0===i?void 0:i.Id,item_name:null===i||void 0===i?void 0:i.Title,item_list_name:"Gift list",item_category:s,quantity:Number(e.Quantity),price:e.Amount,index:t}}))})),E("card"!==e.value.type)}}),!_&&(0,i.jsx)(w.W,{id:"SavePaymentMethod",label:"Remember my details",checkboxLabel:"Save my card details for a faster checkout next time",type:P.IY.checkbox,disabled:!L}
1),L&&g.SavePaymentMethod&&!_&&(0,i.jsxs)(I.j,{type:"infoNew",children:[(null===(e=L.Account)||void 0===e?void 0:e.PaymentMethodDescriptor)&&(0,i.jsxs)(r.S,{variant:"paragraph",children:["Saving a new payment card will replace your existing saved card (",L.Account.PaymentMethodDescriptor,")."," "]}),"We'll store your payment method (credit/debit card) through Stripe's secure platform. You'll be able to change your details at any time to ensure your donation goes smoothly."]}),!L&&!_&&(0,i.jsxs)(I.j,{type:"infoNew",children:[(0,i.jsx)(O.Hp,{color:"forestDeep",className:"underline hover:no-underline",onClick:Y,children:"Please log in"})," ","to save your credit/debit card details for faster donation next time."]})]})]}),(0,i.jsx)(W,{isSubmitDisabled:Q,processing:b,submitText:"Make payment",onSubmit:async()=>{if(!(await n()))return;R(!0),o(g);const{Amount:e,Gifts:t,InvoiceAddress:i,PaymentMethod:s=x.XL.CreditCard,SavePaymentMethod:l,ReceiptEmail:r,ReceiptName:c}=g,d=()=>({IsBulkGift:!1,Amount:e,PublicName:"",PublicMessage:"",ReceiptEmail:r,ReceiptName:c,PaymentMethod:s,SavePaymentMethod:l,InvoiceAddress:i,Gifts:t.map((e=>{let{DeliverOn:t,DeliveryDatetimeWhen:a,From:i,GiftTemplateId:s,Message:n,PlantingRegionId:l,Quantity:r,RecipientEmail:o,RecipientName:c}=e;return{DeliverOn:a===y.p3.SpecificDateTime?K()(t).toISOString():null,From:i,GiftTemplateId:s,Message:n||"",PlantingRegionId:"choose_for_me"!==l&&l?l:void 0,Quantity:parseInt("".concat(r)),RecipientEmail:o,RecipientName:c}}))}),m=async()=>{const e=await function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3;return new Promise(((a,i)=>{const s=e();if(s)return void a(s);const n=setInterval((()=>{const t=e();t&&(clearInterval(n),a(t))}),100);setTimeout((()=>{clearInterval(n),i(new Error("Payment verification failed to load. Please refresh the page and try again."))}),t)}))}((()=>a.current)),{ReceiptEmail:t,...i}=d();return delete i.InvoiceAddress,delete i.PaymentMethod,delete i.SavePaymentMethod,{...i,GuestEmail:t,RecaptchaToken:await e()}},u=e=>{R(!1),(0,te.h4)({message:e.message,type:te.k$.error})},p=e=>s===x.XL.Invoice?(async e=>{R(!1),D(!0);const t="".concat(se.env.NEXT_PUBLIC_APP_DOMAIN).concat((0,C._O)({queryParams:{token:e.Token,hash:e.Hash,purchaseId:e.PurchaseId,purchaseType:x.Oz.GiftedTree,path:U.pathname}}));await U.push(t)})(e):(async e=>{if(null===e||void 0===e?void 0:e.PaymentIntentClientSecret){const t="SavedCreditCard"===s?{}:{elements:k},a=await q.confirmPayment({...t,clientSecret:e.PaymentIntentClientSecret,confirmParams:{payment_method_data:{billing_details:{name:c}},return_url:"".concat(se.env.NEXT_PUBLIC_APP_DOMAIN).concat((0,C._O)({queryParams:{token:e.Token,hash:e.Hash,purchaseId:e.PurchaseId,purchaseType:x.Oz.GiftedTree,path:U.pathname}}))}});a.error&&(R(!1),(0,te.h4)({message:a.error.message,type:te.k$.error}),await H({variables:{input:{PurchaseId:e.PurchaseId,Error:a.error.message||"Unknown error"}}}))}else(0,te.h4)({message:"No Client Secret!",type:te.k$.error})})(e);if(s===x.XL.CreditCard){const{error:e}=await k.submit();if(e)return(0,te.h4)({message:e.message,type:te.k$.error}),void R(!1)}return L?(async()=>{await X({variables:{input:d()},onError:u,onCompleted:e=>{p(e.create_gift_payment)}})})():(async()=>{const e=await m().catch((e=>(u(e),null)));e&&z({variables:{input:e},onError:u,onCompleted:e=>{p(e.create_gift_guest_payment)}})})()}})]})};var oe=a(25675),ce=a.n(oe);const de=e=>{let{index:t}=e;const{user:a}=(0,v.a)(),n=(0,m.u6)(),{values:l,setFieldValue:o}=n,c=(0,s.useMemo)((()=>l.Gifts[t]),[t,l]),{data:d}=(0,S.LQp)({variables:{offset:0,where:{IsBulkOnly:{_eq:!1},IsAvailable:{_eq:!0}}}}),u=(0,s.useMemo)((()=>null===d||void 0===d?void 0:d.GiftTemplate.map((e=>({label:e.Title,value:e.Id})))),[d]),p=(0,s.useMemo)((()=>null===d||void 0===d?void 0:d.GiftTemplate.find((e=>e.Id===c.GiftTemplateId))),[null===d||void 0===d?void 0:d.GiftTemplate,c]),f=(0,s.useMemo)((()=>[{label:"To the recipient's email",value:y.hS.Recipients,selectedContentAwlaysVisible:!1,selectedContent:(0,i.jsxs)("div",{children:[(0,i.jsx)(w.W,{className:"mt-4 mb-0!",id:"Gifts[".concat(t,"].RecipientEmail"),label:"Send gifts to",labelClassName:"sr-only",type:P.IY.text,disabled:(null===c||void 0===c?void 0:c.GiftsDestination)===y.hS.Self,onChange:()=>{o("Gifts[".concat(t,"].ConfirmGiftEmailAddress"),!1)},formFieldClassName:"bg-white"}),(null===c||void 0===c?void 0:c.RecipientEmail)?(0,i.jsx)(w.W,{className:"mt-[10px]",formFieldClassName:"ml-0! border border-lavenderBright w-full px-3 py-1 [&_svg]:fill-lavenderBright!",id:"Gifts[".concat(t,"].ConfirmGiftEmailAddress"),label:"",checkboxLabel:"I confirm this email address is correct",labelClassName:"sr-only",type:P.IY.checkbox}):null]})},{label:"To me, so I can pass them on myself",value:y.hS.Self,selectedContent:"We\u2019ll email the e-card link to ".concat(null===c||void 0===c?void 0:c.RecipientEmail,". You can also download it anytime from your account."),selectedContentAwlaysVisible:!1}]),[t,c,o]);return c?(0,i.jsx)("div",{className:"flex flex-col bg-linen lg:p-10 p-5 ",children:(0,i.jsxs)("div",{className:"flex flex-col xl:flex-row gap-[10px] lg:gap-10 text-left",children:[(0,i.jsx)("div",{className:"xl:w-1/2",children:(0,i.jsxs)("div",{className:"flex flex-col",children:[(0,i.jsx)("div",{className:"mb-4",children:(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:"Gift details for recipient"})}),(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].RecipientName"),label:"To",type:P.IY.text,formFieldClassName:"bg-white"}),(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].From"),label:"From",type:P.IY.text,formFieldClassName:"bg-white"}),(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].Message"),label:"E-card message",description:"Tip: Proofread your message; it can\u2019t be changed once sent. Emojis aren\u2019t supported at the moment.",placeholder:"Type up to 200 characters...",type:P.IY.textarea,rows:3,formFieldClassName:"bg-white",maxCharacters:200}),(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].Quantity"),label:"Number of trees",type:P.IY.text,formFieldClassName:"bg-white"}),(0,i.jsx)(w.W,{className:"mb-5!",id:"Gifts[".concat(t,"].PlantingRegionId"),label:"Select a planting region (optional)",description:(0,i.jsx)("div",{className:"mt-[10px]",children:(0,i.jsx)(r.S,{variant:"paragraph",children:"We'll try to allocate your tree/s to your preferred region, but they may be planted where needed most."})}),type:P.IY.regionSelect,regionsOnly:!0}),a?(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].GiftsDestination"),type:P.IY.radioGroup,options:f,label:"Where shall we send the e-card",conditionForConditionalComponent:c.GiftsDestination===y.hS.Recipients,onChange:async e=>{var i;e.target.value===y.hS.Self?(await o("Gifts[".concat(t,"].RecipientEmail"),(null===a||void 0===a||null===(i=a.Account)||void 0===i?void 0:i.Email)||"",!0),await o("Gifts[".concat(t,"].ConfirmGiftEmailAddress"),!0,!0)):(await o("Gifts[".concat(t,"].RecipientEmail"),"",!0),await o("Gifts[".concat(t,"].ConfirmGiftEmailAddress"),!1,!0));await o("Gifts[".concat(t,"].DeliveryDatetimeWhen"),y.p3.Immediately)}}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].RecipientEmail"),className:"mb-[10px]",label:"Where shall we send the e-card",description:"Tip: Use your email address if you want to pass it along yourself.",type:P.IY.text,onChange:()=>{o("Gifts[".concat(t,"].ConfirmGiftEmailAddress"),!1)},formFieldClassName:"bg-white"}),c.RecipientEmail?(0,i.jsx)(w.W,{formFieldClassName:"ml-0! border border-lavenderBright w-full px-3 py-1 [&_svg]:fill-lavenderBright!",id:"Gifts[".concat(t,"].ConfirmGiftEmailAddress"),label:"confirm email",checkboxLabel:"I confirm this email address is correct",labelClassName:"sr-only",type:P.IY.checkbox}):null]}),c.GiftsDestination===y.hS.Recipients?(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].DeliveryDatetimeWhen"),type:P.IY.radioGroup,options:y.vv,label:"When do you want to send the e-cards?",conditionForConditionalComponent:c.DeliveryDatetimeWhen===y.p3.SpecificDateTime,conditionalComponent:(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].DeliverOn"),label:"Deliver on",description:"Tell us when to send out the e-cards",type:P.IY.datetime}),onChange:e=>{e.target.value===y.p3.Immediately&&o("Gifts[".concat(t,"].DeliverOn"),null)}}):null]})}),(0,i.jsxs)("div",{className:"flex-1",children:[(0,i.jsx)(w.W,{id:"Gifts[".concat(t,"].GiftTemplateId"),label:"",formFieldClassName:"bg-white",placeholder:"Change design",type:P.IY.select,options:u}
1),(null===p||void 0===p?void 0:p.BackgroundImage)?(0,i.jsxs)("div",{className:"flex flex-col gap-[10px]",children:[(0,i.jsx)(ce(),{src:"".concat(se.env.NEXT_PUBLIC_ASSETS_DOMAIN,"/").concat(p.Preview),alt:"Gift Preview",width:520,height:387,className:"object-contain overflow-clip"}),(0,i.jsx)(r.S,{variant:"h5",color:"forestDeep",children:p.Title}),(0,i.jsx)(r.S,{variant:"paragraph",children:p.Description})]}):null]})]})}):(0,i.jsx)(i.Fragment,{children:"Could not gift data"})},me=e=>{let{onRemoveRow:t}=e;const a=(0,m.u6)(),{values:n}=a,[l,r]=(0,s.useState)(1===n.Gifts.length?0:null),o=(0,V.Z)("(max-width: 1024px)"),c=(0,U.Cl)();(0,s.useEffect)((()=>{var e;const t=null===(e=n.Gifts.find((e=>""===e.RecipientName)))||void 0===e?void 0:e.Index;r(t||null)}),[n.Gifts]);const d=(0,s.useCallback)((e=>{null!==l&&(e.getIsExpanded()&&l===e.index||e.toggleExpanded(l===e.index))}),[l]),u=[c.accessor("Index",{cell:e=>{const{RecipientName:a,RecipientEmail:s,From:n,Message:l,Quantity:r,GiftsDestination:o}=e.row.original;return d(e.row),(0,i.jsxs)("div",{className:"flex flex-row gap-2",children:[(0,i.jsxs)("div",{className:"flex flex-1 flex-col gap-2",children:[(0,i.jsxs)(M.F,{className:"bg-transparent mb-4",children:[(0,i.jsx)(M.U,{label:"To",value:a}),(0,i.jsx)(M.U,{label:"Recipient email",value:o===y.hS.Self?(0,i.jsxs)("span",{children:["Me",(0,i.jsx)("br",{}),"(",s,")"]}):s}),(0,i.jsx)(M.U,{label:"From",value:n}),(0,i.jsx)(M.U,{label:"Message",value:l}),(0,i.jsx)(M.U,{label:"To",value:a}),(0,i.jsx)(M.U,{label:"Number of trees",value:r})]}),(0,i.jsxs)(O.Hp,{color:"forestDeep",className:"text-sm font-semibold",type:"button",children:["Preview card",e.row.getIsExpanded()?(0,i.jsx)(L.s$2,{className:"inline mx-2"}):(0,i.jsx)(L.RiI,{className:"inline mx-2"})]})]}),0!==e.row.index||e.table.getRowCount()>1?(0,i.jsx)(_.B4e,{size:"24px",className:"text-forestDeep hover:text-forestDeepHover",onClick:a=>{a.preventDefault(),t(e.getValue())}}):null]})}})],p=[c.accessor("RecipientName",{header:"To",size:180,cell:e=>(d(e.row),(0,i.jsxs)("div",{className:"flex flex-col gap-[10px]",children:[(0,i.jsx)("span",{className:"block",children:e.getValue()}),(0,i.jsxs)(O.Hp,{color:"forestDeep",className:"text-sm font-semibold justify-self-end",type:"button",children:["Preview card",e.row.getIsExpanded()?(0,i.jsx)(L.s$2,{className:"inline mx-2"}):(0,i.jsx)(L.RiI,{className:"inline mx-2"})]})]}))}),c.accessor("RecipientEmail",{header:"Recipient email",cell:e=>e.row.original.GiftsDestination===y.hS.Self?(0,i.jsxs)("span",{children:["Me",(0,i.jsx)("br",{}),"(",e.getValue(),")"]}):e.getValue()}),c.accessor("From",{header:"From",cell:e=>e.getValue()}),c.accessor("Message",{header:"Message",cell:e=>(0,i.jsx)("p",{className:"w-full line-clamp-5",children:e.getValue()})}),c.accessor("Quantity",{header:"Trees qty",cell:e=>e.getValue()}),c.accessor("Index",{header:"",size:20,cell:e=>0!==e.row.index||e.table.getRowCount()>1?(0,i.jsx)(_.B4e,{size:"24px",className:"text-forestDeep hover:text-forestDeepHover",onClick:a=>{a.preventDefault(),t(e.getValue())}}):null})],f=o?u:p;return(0,i.jsx)(Y.i,{className:"table-auto! mt-0! lg:mt-8!",headerClasses:"py-5! text-left! lg:last:text-right!",cellClasses:"py-5! text-left! lg:last:text-right! align-top text-base font-medium",subComponentClasses:"pt-2!",isSelectable:()=>!0,onSelect:(e,t)=>{const a=t.getIsExpanded();t.toggleExpanded(!a),r(a?null:t.index)},data:n.Gifts,columns:f,showHeader:!o,renderSubComponent:e=>{let{row:t}=e;return(0,i.jsx)(de,{index:t.index})}})},ue=()=>{const{nextStep:e,validateStep:t}=(0,f.t)(),a=(0,m.u6)(),{values:n,setFieldValue:l,isValid:o}=a,{setValue:c}=(0,h.Y)({key:"giftForm"}),d=(0,s.useMemo)((()=>n.Gifts.reduce(((e,t)=>e+Number(t.Quantity)),0)),[n.Gifts]),{productPrice:u}=(0,q.u)(d,!0);(0,s.useEffect)((()=>{if(u&&d){l("Amount",(u*(d||0)).toString())}}),[u,d]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{children:(0,i.jsx)(r.S,{variant:"h4",color:"forestDeep",children:(0,i.jsx)("strong",{children:"Add recipient details"})})}),(0,i.jsx)("div",{className:"flex flex-col gap-5 md:gap-10",children:(0,i.jsxs)("div",{className:"mb-10 flex-1",children:[(0,i.jsx)(me,{onRemoveRow:async e=>{const t=n.Gifts.filter((t=>t.Index!==e));await l("Gifts",t)}}),(0,i.jsxs)(b.B,{disabled:!o,className:"mt-5",variant:"forest",onClick:async()=>{await t()&&await l("Gifts",[...n.Gifts,{Amount:0,DeliverOn:null,DeliveryDatetimeWhen:y.p3.Immediately,GiftsDestination:y.hS.Recipients,From
1:"",GiftTemplateId:n.GiftTemplateId,Index:Math.max(...n.Gifts.map((e=>e.Index)))+1,Message:"",Quantity:1,RecipientEmail:"",RecipientName:"",PlantingRegionId:null}],!0)},children:["Add another recipient ",(0,i.jsx)(_.NcC,{className:"ml-2"})]})]})}),(0,i.jsx)(W,{submitText:"Next",onSubmit:async()=>{c(n),e()}})]})};var pe=a(7258),fe=a(22758);const ve=pe.Ry({Index:pe.Rx(),RecipientName:pe.Z_().typeError("Recipient name should be 30 characters or less").max(30,"Recipient name should be 30 characters or less").required("Please enter a recipient name"),RecipientEmail:pe.Z_().typeError("Please enter a valid email address").email("Please enter a valid email address").required("Please enter an email address"),From:pe.Z_().typeError("From name should be 30 characters or less").max(30,"From name should be 30 characters or less").required("Please enter a from name"),Message:pe.Z_().optional().default(""),GiftTemplateId:pe.Z_().required("This field is required"),Quantity:(0,fe.W)("At least one tree required",1),Amount:(0,fe.W)("",10),DeliveryDatetimeWhen:pe.Z_().oneOf(y.vv.map((e=>e.value))).required("Please select when you want to send the e-card"),DeliverOn:pe.hT().nullable().when("DeliveryDatetimeWhen",{is:y.p3.SpecificDateTime,then:e=>e.required("Please select a delivery date and time").min(K()(),"Delivery date should be in the future"),otherwise:e=>e.nullable()}),GiftsDestination:pe.Z_().oneOf(Object.values(y.hS)).required("Please select where you want the gift cards to be sent"),ConfirmGiftEmailAddress:pe.Xg().oneOf([!0],"Please check this to continue").required("Please check this to continue"),PlantingRegionId:pe.Z_().nullable().optional()}),he=pe.Ry({Gifts:pe.IX().of(ve).required(""),GiftTemplateId:pe.Z_().required()}),xe=pe.Ry({InvoiceAddress0:pe.Z_().required("Address line 1 is required"),InvoiceAddress1:pe.Z_().optional(),InvoiceCity:pe.Z_().required("City is required"),InvoiceCountry:pe.Z_().required("Country is required"),InvoicePostCode:pe.Z_().required("Post code is required")}),ge=pe.Ry({Amount:pe.Z_().required(),Category:pe.Z_().required(""),Gifts:pe.IX().of(ve).required(""),ReceiptEmail:pe.Z_().email("Please enter a valid email address").required("Please enter an email address"),ReceiptName:pe.Z_().required("Please enter a name for your receipt"),CopyDetails:pe.Xg(),PaymentMethod:pe.Z_().required("Please select a payment method"),SavePaymentMethod:pe.O7().optional().default(!1),InvoiceAddress:pe.nK().when("PaymentMethod",{is:x.XL.Invoice,then:xe.required(),otherwise:pe.nK().optional()}),GiftTemplateId:pe.Z_().required()}),ye=()=>{const e=(0,u.useRouter)(),{user:t}=(0,v.a)(),{selectedGiftTemplateId:a=""}=e.query,{handleReset:n}=(0,l.V)(),{value:r}=(0,h.Y)({key:"giftForm"}),o=(0,s.useMemo)((()=>[{name:"Add recipients",component:ue,validationSchema:he},{name:"Confirm",component:H},{name:"Payment",component:re,validationSchema:ge}]),[]),c=(0,g.V)(o.length,e.query.stepIndex),d=(0,s.useMemo)((()=>{var e;return{Amount:"0",Category:"all",Gifts:[{Index:0,RecipientEmail:null,RecipientName:null,From:null,Message:"",Quantity:1,Amount:10,DeliverOn:null,GiftTemplateId:a,DeliveryDatetimeWhen:y.p3.Immediately,GiftsDestination:y.hS.Recipients,PlantingRegionId:null}],ReceiptEmail:"",ReceiptName:"",CopyDetails:!1,PaymentMethod:(null===t||void 0===t||null===(e=t.Account)||void 0===e?void 0:e.PaymentMethodDescriptor)?"":x.XL.CreditCard,SavePaymentMethod:!1,SelectPlantingRegion:!1,InvoiceAddress:{InvoiceAddress0:"",InvoiceAddress1:"",InvoiceCity:"",InvoicePostCode:"",InvoiceCountry:"New Zealand"},GiftTemplateId:a}}),[t,a]);(0,s.useEffect)((()=>{c>0&&!r&&(delete e.query.stepIndex,e.replace({query:{...e.query}}))}),[r,e,c,o.length]);const j=(0,s.useMemo)((()=>{var a,i;const s=t?{ReceiptEmail:null===t||void 0===t||null===(a=t.Account)||void 0===a?void 0:a.Email,ReceiptName:null===t||void 0===t||null===(i=t.Account)||void 0===i?void 0:i.Name}:{},n={...d,...s};return void 0===e.query.stepIndex?{...n}:{...n,...r}}),[e,r]),b=(0,s.useMemo)((()=>o[c||0].validationSchema),[c,o]);return(0,i.jsx)(p.U,{margin:"small",children:(0,i.jsx)(m.J9,{enableReinitialize:!0,validateOnMount:!0,initialValues:j,onSubmit:()=>{},validationSchema:b,children:e=>{let{resetForm:t,values:a}=e;var s;return(0,i.jsx)(l.O,{amount:a.Amount,savePaymentMethod:a.SavePaymentMethod,children:(0,i.jsx)(m.l0,{className:"md:mb-24 [&_[role=radiogroup]_svg]:fill-lavenderBright! [&_.form-input-wrapper]:rounded-none! [&_.form-label]:hover:text-forestDeep! [&_.form-group:focus-within_.form-label]:text-forestDeep!",children:(null===(s=a.Gifts[0])||void 0===s?void 0:s.GiftTemplateId)?(0,i.jsx)("div",{className:"bg-white p-5 md:p-10",children:(0,i.jsx)(f.x,{steps:o,onReset:()=>{n(),t({values:j})}})}):(0,i.jsx)(R,{})})},"gift-".concat(a.SavePaymentMethod))}})})};var je=(0,d.j_)((()=>{const{setFocussedHeader:e}=(0,n.v)();return(0,s.useEffect)((()=>{e()}),[]),(0,i.jsx)(c.T3,{title:"Gift certificates for native trees",metaTitle:"Gift certificates for native trees",metaDescription:"Gift a $10 native tree e-gift card, we`ll do the rest. We`ll send your personalised gift certificate to your recipient by email\u2014then we`ll get their native tree to a planting project, and let you both know where.",isFullWidth:!0,children:(0,i.jsx)(o.f,{backgroundColor:o.u.linen,children:(0,i.jsxs)(l.O,{children:[(0,i.jsx)("div",{className:"col-md-8",children:(0,i.jsxs)("div",{className:"text-center mb-[15px] md:mb-10 md:mt-10",children:[(0,i.jsx)(r.S,{variant:"h2",as:"h1",color:"forestDeep",children:(0,i.jsx)("strong",{children:"Give the gift that grows"})}),(0,i.jsx)(r.S,{variant:"introduction",children:"Your gift will help nature thrive \u2014 now and for generations to come."})]})}),(0,i.jsx)(ye,{})]})})})}))},33712:function(e,t,a){"use strict";a.d(t,{Wb:function(){return m},hN:function(){return p},j_:function(){return f},mL:function(){return u}});var i=a(85893),s=a(88100),n=a(11163),l=a(67294),r=a(13508),o=a(53719),c=a(33441),d=a(27518);const m=e=>function(){const{isLoading:t,isStaff:a}=(0,r.a)(),o=(0,n.useRouter)();(0,l.useEffect)((()=>{t||a||o.replace(d.$x)}),[a,t]);const m=(0,s.u3)(e,{onRedirecting:c.F});return(0,i.jsx)(m,{})},u=e=>function(){const{isLoading:t,isAdvisor:a,isStaff:o}=(0,r.a)(),m=(0,n.useRouter)();(0,l.useEffect)((()=>{t||a||o||m.replace(d.$x)}),[a,o,t]);const u=(0,s.u3)(e,{onRedirecting:c.F});return(0,i.jsx)(u,{})},p=(e,t)=>(0,s.u3)(e,{onRedirecting:c.F,...t}),f=e=>function(){const{user:t,isLoading:a}=(0,o.a)(),s=(0,n.useRouter)(),r=(0,l.useMemo)((()=>!a&&t&&!(null===t||void 0===t?void 0:t.Account)),[t,a]);return(0,l.useEffect)((()=>{r&&s.replace({pathname:(0,d.Yh)(),query:{returnTo:s.asPath}})}),[r,s]),a||r?null:(0,i.jsx)(e,{})}},22758:function(e,t,a){"use strict";a.d(t,{W:function(){return s}});var i=a(7258);const s=(e,t,a)=>e?i.Vo((s=>""===s?i.Z_().required(e):i.Rx().typeError("Please enter a valid number").min(t||1,a||"Please enter a number greater than or equal to ".concat(t||1)).required(e))):i.Vo((e=>""===e?i.Z_():i.Rx().typeError("Please enter a valid number")))}},function(e){e.O(0,[5970,509,1255,5666,9759,4053,9503,9249,2156,1317,5850,298,2888,9774,179],(function(){return t=71036,e(e.s=t);var t}));var t=e.O();_N_E=t}]); 2//# sourceMappingURL=gift-188079143f67a8e8.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.