@getspot/spot-widget 3.0.3 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
- (function(_,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(_=typeof globalThis<"u"?globalThis:_||self,_.SpotWidget=v())})(this,function(){"use strict";async function _(l,t,o){try{const n=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(o)}),i=await n.json();if(!n.ok){const e=new Error((i==null?void 0:i.message)||"Failed to fetch quote");throw e.status=n.status,e.responseBody=i,e}return i}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching quote")}}async function v(l,t,o){try{const n=l.replace("/quote","/quote/batch"),i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(o)}),e=await i.json();if(!i.ok){const s=new Error((e==null?void 0:e.message)||"Failed to fetch batch quote");throw s.status=i.status,s.responseBody=e,s}return e}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching batch quote")}}async function E(l,t,o){var n;try{const i={cartId:o.cartInfo.cartId,cartName:o.cartInfo.cartName,currencyCode:o.cartInfo.currencyCode,items:o.items.map((a,u)=>({cartItemId:a.cartItemId||`item-${u+1}`,productPrice:a.productPrice,productType:a.productType,productDuration:a.productDuration,productId:a.productId,productName:a.productName,participantDescription:a.participantDescription,eventType:a.eventType,startDate:a.startDate,endDate:a.endDate}))},e=await v(l,t,i);if(e.status!=="QUOTES_AVAILABLE"&&e.status!=="QUOTE_AVAILABLE")return{status:"NO_MATCHING_QUOTE"};const s=e.quotes.map(a=>{const u=o.items.find((f,h)=>(f.cartItemId||`item-${h+1}`)===a.cartItemId);return u?u.participantDescription?`${u.productName} - ${u.participantDescription}`:u.productName:`Item ${a.id}`}),r=Math.round((e.totalSpotPrice||e.spotPrice||0)*100)/100;return{status:"QUOTE_AVAILABLE",data:{id:e.quotes?e.quotes.map(a=>a.id).join(","):((n=e.data)==null?void 0:n.id)||"",spotPrice:r,currencyCode:e.currencyCode||"",communication:{...e.communication,yesOptionText:e.communication.yesOptionText.replace(String(e.totalSpotPrice),String(r))},payoutSchedule:e.payoutSchedule.map(a=>({...a,amount:a.amount!==void 0?a.amount:0})),coveredItems:s,originalQuotes:e.quotes||(e.data?[e.data]:[])},spotPrice:r,coveredItems:s}}catch(i){throw i instanceof Error?i:new Error("Unknown error occurred while fetching multiple quotes")}}const M={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote",local:"http://localhost:3999/api/v1/quote"};function x(l){const{apiConfig:t={},quoteRequestData:o,callbacks:n={},location:i,theme:e}=l,{environment:s="sandbox",partnerId:r,customEndpoint:a}=t;if(!r||typeof r!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(a||M[s]))throw new Error(`Invalid environment in apiConfig: ${s}`);if(!o||typeof o!="object"&&!Array.isArray(o))throw new Error("quoteRequestData must be a non-null object or array");const f=["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"];function h(c,d=null){const m=d!==null?`quoteRequestData[${d}]`:"quoteRequestData";f.forEach(w=>{if(!Object.prototype.hasOwnProperty.call(c,w)||c[w]===void 0||c[w]===null)throw new Error(`Missing required ${m} field: '${w}'`)});const b=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!b.test(c.startDate))throw new Error(`${m}.startDate must be a valid ISO8601 string`);if(!b.test(c.endDate))throw new Error(`${m}.endDate must be a valid ISO8601 string`);if(typeof c.currencyCode!="string")throw new Error(`${m}.currencyCode must be a string`);if(!["USD","CAD","AUD"].includes(c.currencyCode))throw new Error(`Invalid ${m}.currencyCode: ${c.currencyCode}`);if(typeof c.eventType!="string")throw new Error(`${m}.eventType must be a string`);if(typeof c.productType!="string")throw new Error(`${m}.productType must be a string`);const g=["Pass","Trip","Registration"];if(!g.includes(c.productType))throw new Error(`${m}.productType must be one of ${g.join(", ")}`);if(typeof c.productDuration!="string")throw new Error(`${m}.productDuration must be a string`);const C=["Daily","Seasonal","Trip","Event"];if(!C.includes(c.productDuration))throw new Error(`${m}.productDuration must be one of ${C.join(", ")}`);if(typeof c.productPrice!="number"||isNaN(c.productPrice))throw new Error(`${m}.productPrice must be a valid number`);if(typeof c.productId!="string")throw new Error(`${m}.productId must be a string`);if(typeof c.cartId!="string")throw new Error(`${m}.cartId must be a string`);if(typeof c.productName!="string")throw new Error(`${m}.productName must be a string`)}if("cartInfo"in o&&"items"in o){const c=o,{cartInfo:d,items:m}=c;if(!d||typeof d!="object")throw new Error("quoteRequestData.cartInfo must be a non-null object");if(!d.cartId||typeof d.cartId!="string")throw new Error("quoteRequestData.cartInfo.cartId must be a string");if(!d.cartName||typeof d.cartName!="string")throw new Error("quoteRequestData.cartInfo.cartName must be a string");if(!d.currencyCode||typeof d.currencyCode!="string")throw new Error("quoteRequestData.cartInfo.currencyCode must be a string");if(!["USD","CAD","AUD"].includes(d.currencyCode))throw new Error(`Invalid quoteRequestData.cartInfo.currencyCode: ${d.currencyCode}`);if(!Array.isArray(m)||m.length===0)throw new Error("quoteRequestData.items must be a non-empty array");const D=["startDate","endDate","eventType","productType","productDuration","productPrice","productId","productName"];m.forEach((g,C)=>{if(!g||typeof g!="object")throw new Error(`quoteRequestData.items[${C}] must be a non-null object`);const w=`quoteRequestData.items[${C}]`;D.forEach(q=>{if(!Object.prototype.hasOwnProperty.call(g,q)||g[q]===void 0||g[q]===null)throw new Error(`Missing required ${w} field: '${q}'`)});const I=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!I.test(g.startDate))throw new Error(`${w}.startDate must be a valid ISO8601 string`);if(!I.test(g.endDate))throw new Error(`${w}.endDate must be a valid ISO8601 string`);if(typeof g.eventType!="string")throw new Error(`${w}.eventType must be a string`);if(typeof g.productType!="string")throw new Error(`${w}.productType must be a string`);const T=["Pass","Trip","Registration"];if(!T.includes(g.productType))throw new Error(`${w}.productType must be one of ${T.join(", ")}`);if(typeof g.productDuration!="string")throw new Error(`${w}.productDuration must be a string`);const H=["Daily","Seasonal","Trip","Event"];if(!H.includes(g.productDuration))throw new Error(`${w}.productDuration must be one of ${H.join(", ")}`);if(typeof g.productPrice!="number"||isNaN(g.productPrice))throw new Error(`${w}.productPrice must be a valid number`);if(typeof g.productId!="string")throw new Error(`${w}.productId must be a string`);if(typeof g.productName!="string")throw new Error(`${w}.productName must be a string`)})}else if(Array.isArray(o)){if(o.length===0)throw new Error("quoteRequestData array cannot be empty");o.forEach((c,d)=>{if(!c||typeof c!="object")throw new Error(`quoteRequestData[${d}] must be a non-null object`);h(c,d)})}else h(o);if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(c=>{const d=n[c];if(d&&typeof d!="function")throw new Error(`Callback '${c}' must be a function.`)}),typeof i=="string"&&!document.querySelector(i))throw new Error(`Invalid location selector: '${i}'`);if(e&&typeof e!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function p(l,{text:t,className:o,parent:n,innerHTML:i,href:e,target:s}={}){const r=document.createElement(l);return o&&(r.className=o),t!=null&&(r.textContent=t),i!=null&&(r.innerHTML=i),e&&"href"in r&&(r.href=e),s&&"target"in r&&(r.target=s),n&&n.appendChild(r),r}function N(l,{name:t,description:o}){p("div",{className:"spot-header__title",text:t,parent:l}),p("div",{className:"spot-header__description",text:o,parent:l})}function z(l,t=[]){const o=p("ul",{className:"spot-benefits__list",parent:l});t.forEach(n=>{const i=p("li",{parent:o});i.innerHTML=`
2
- <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
1
+ (function(_,C){typeof exports=="object"&&typeof module<"u"?module.exports=C():typeof define=="function"&&define.amd?define(C):(_=typeof globalThis<"u"?globalThis:_||self,_.SpotWidget=C())})(this,function(){"use strict";async function _(m,t,r){try{const s=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(r)}),i=await s.json();if(!s.ok){const e=new Error((i==null?void 0:i.message)||"Failed to fetch quote");throw e.status=s.status,e.responseBody=i,e}return i}catch(s){throw s instanceof Error?s:new Error("Unknown error occurred while fetching quote")}}async function C(m,t,r){try{const s=m.replace("/quote","/quote/batch"),i=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(r)}),e=await i.json();if(!i.ok){const n=new Error((e==null?void 0:e.message)||"Failed to fetch batch quote");throw n.status=i.status,n.responseBody=e,n}return e}catch(s){throw s instanceof Error?s:new Error("Unknown error occurred while fetching batch quote")}}async function k(m,t,r){var s;try{const i={cartId:r.cartInfo.cartId,cartName:r.cartInfo.cartName,currencyCode:r.cartInfo.currencyCode,items:r.items.map((a,u)=>({cartItemId:a.cartItemId||`item-${u+1}`,productPrice:a.productPrice,productType:a.productType,productDuration:a.productDuration,productId:a.productId,productName:a.productName,participantDescription:a.participantDescription,eventType:a.eventType,startDate:a.startDate,endDate:a.endDate}))},e=await C(m,t,i);if(e.status!=="QUOTES_AVAILABLE"&&e.status!=="QUOTE_AVAILABLE")return{status:"NO_MATCHING_QUOTE"};const n=e.quotes.map(a=>{const u=r.items.find((h,f)=>(h.cartItemId||`item-${f+1}`)===a.cartItemId);return u?u.participantDescription?`${u.productName} - ${u.participantDescription}`:u.productName:`Item ${a.id}`}),o=Math.round((e.totalSpotPrice||e.spotPrice||0)*100)/100;return{status:"QUOTE_AVAILABLE",data:{id:e.quotes?e.quotes.map(a=>a.id).join(","):((s=e.data)==null?void 0:s.id)||"",spotPrice:o,currencyCode:e.currencyCode||"",communication:{...e.communication,yesOptionText:e.communication.yesOptionText.replace(String(e.totalSpotPrice),String(o))},payoutSchedule:e.payoutSchedule.map(a=>({...a,amount:a.amount!==void 0?a.amount:0})),coveredItems:n,originalQuotes:e.quotes||(e.data?[e.data]:[])},spotPrice:o,coveredItems:n}}catch(i){throw i instanceof Error?i:new Error("Unknown error occurred while fetching multiple quotes")}}const z={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote",local:"http://localhost:3999/api/v1/quote"};function x(m){const{apiConfig:t={},quoteRequestData:r,callbacks:s={},location:i,theme:e}=m,{environment:n="sandbox",partnerId:o,customEndpoint:a}=t;if(!o||typeof o!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(a||z[n]))throw new Error(`Invalid environment in apiConfig: ${n}`);if(!r||typeof r!="object"&&!Array.isArray(r))throw new Error("quoteRequestData must be a non-null object or array");const h=["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"];function f(c,d=null){const l=d!==null?`quoteRequestData[${d}]`:"quoteRequestData";h.forEach(v=>{if(!Object.prototype.hasOwnProperty.call(c,v)||c[v]===void 0||c[v]===null)throw new Error(`Missing required ${l} field: '${v}'`)});const b=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!b.test(c.startDate))throw new Error(`${l}.startDate must be a valid ISO8601 string`);if(!b.test(c.endDate))throw new Error(`${l}.endDate must be a valid ISO8601 string`);if(typeof c.currencyCode!="string")throw new Error(`${l}.currencyCode must be a string`);if(!["USD","CAD","AUD"].includes(c.currencyCode))throw new Error(`Invalid ${l}.currencyCode: ${c.currencyCode}`);if(typeof c.eventType!="string")throw new Error(`${l}.eventType must be a string`);if(typeof c.productType!="string")throw new Error(`${l}.productType must be a string`);const g=["Pass","Trip","Registration"];if(!g.includes(c.productType))throw new Error(`${l}.productType must be one of ${g.join(", ")}`);if(typeof c.productDuration!="string")throw new Error(`${l}.productDuration must be a string`);const w=["Daily","Seasonal","Trip","Event"];if(!w.includes(c.productDuration))throw new Error(`${l}.productDuration must be one of ${w.join(", ")}`);if(typeof c.productPrice!="number"||isNaN(c.productPrice))throw new Error(`${l}.productPrice must be a valid number`);if(typeof c.productId!="string")throw new Error(`${l}.productId must be a string`);if(typeof c.cartId!="string")throw new Error(`${l}.cartId must be a string`);if(typeof c.productName!="string")throw new Error(`${l}.productName must be a string`)}if("cartInfo"in r&&"items"in r){const c=r,{cartInfo:d,items:l}=c;if(!d||typeof d!="object")throw new Error("quoteRequestData.cartInfo must be a non-null object");if(!d.cartId||typeof d.cartId!="string")throw new Error("quoteRequestData.cartInfo.cartId must be a string");if(!d.cartName||typeof d.cartName!="string")throw new Error("quoteRequestData.cartInfo.cartName must be a string");if(!d.currencyCode||typeof d.currencyCode!="string")throw new Error("quoteRequestData.cartInfo.currencyCode must be a string");if(!["USD","CAD","AUD"].includes(d.currencyCode))throw new Error(`Invalid quoteRequestData.cartInfo.currencyCode: ${d.currencyCode}`);if(!Array.isArray(l)||l.length===0)throw new Error("quoteRequestData.items must be a non-empty array");const q=["startDate","endDate","eventType","productType","productDuration","productPrice","productId","productName"];l.forEach((g,w)=>{if(!g||typeof g!="object")throw new Error(`quoteRequestData.items[${w}] must be a non-null object`);const v=`quoteRequestData.items[${w}]`;q.forEach(E=>{if(!Object.prototype.hasOwnProperty.call(g,E)||g[E]===void 0||g[E]===null)throw new Error(`Missing required ${v} field: '${E}'`)});const D=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!D.test(g.startDate))throw new Error(`${v}.startDate must be a valid ISO8601 string`);if(!D.test(g.endDate))throw new Error(`${v}.endDate must be a valid ISO8601 string`);if(typeof g.eventType!="string")throw new Error(`${v}.eventType must be a string`);if(typeof g.productType!="string")throw new Error(`${v}.productType must be a string`);const T=["Pass","Trip","Registration"];if(!T.includes(g.productType))throw new Error(`${v}.productType must be one of ${T.join(", ")}`);if(typeof g.productDuration!="string")throw new Error(`${v}.productDuration must be a string`);const H=["Daily","Seasonal","Trip","Event"];if(!H.includes(g.productDuration))throw new Error(`${v}.productDuration must be one of ${H.join(", ")}`);if(typeof g.productPrice!="number"||isNaN(g.productPrice))throw new Error(`${v}.productPrice must be a valid number`);if(typeof g.productId!="string")throw new Error(`${v}.productId must be a string`);if(typeof g.productName!="string")throw new Error(`${v}.productName must be a string`)})}else if(Array.isArray(r)){if(r.length===0)throw new Error("quoteRequestData array cannot be empty");r.forEach((c,d)=>{if(!c||typeof c!="object")throw new Error(`quoteRequestData[${d}] must be a non-null object`);f(c,d)})}else f(r);if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(c=>{const d=s[c];if(d&&typeof d!="function")throw new Error(`Callback '${c}' must be a function.`)}),typeof i=="string"&&!document.querySelector(i))throw new Error(`Invalid location selector: '${i}'`);if(e&&typeof e!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function p(m,{text:t,className:r,parent:s,innerHTML:i,href:e,target:n}={}){const o=document.createElement(m);return r&&(o.className=r),t!=null&&(o.textContent=t),i!=null&&(o.innerHTML=i),e&&"href"in o&&(o.href=e),n&&"target"in o&&(o.target=n),s&&s.appendChild(o),o}function N(m,{name:t,description:r}){p("div",{className:"spot-header__title",text:t,parent:m}),p("div",{className:"spot-header__description",text:r,parent:m})}function M(m,t=[]){const r=p("ul",{className:"spot-benefits__list",parent:m});t.forEach(s=>{const i=p("li",{parent:r});i.innerHTML=`
2
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="none" class="spot-bullets__checkmark">
3
3
  <path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
4
- stroke="#2E2E2E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
5
- </svg>`,p("span",{text:n,parent:i})})}function O(l,t=[]){if(!t||t.length===0)return;const o=p("div",{className:"spot-qualifying-reasons__container",parent:l}),n=[...t].sort((r,a)=>r.rank-a.rank),i=p("div",{className:"spot-qualifying-reasons__grid",parent:o}),e={"Accident & Illness":"cross.svg","Family Emergencies":"users.svg",Layoffs:"building.svg","Jury Duty":"scale.svg","Work Travel Conflict":"briefcase.svg","Severe Weather":"umbrella.svg","Travel Interruption":"plane.svg","Military Duty":"medal.svg"};let s;try{const r=document.currentScript;if(r!=null&&r.src){const a=new URL(r.src);s=a.origin+a.pathname.replace(/\/[^/]*$/,"/")}else s=window.location.origin+window.location.pathname.replace(/\/[^/]*$/,"/");s+="assets/"}catch{s="./assets/"}n.forEach(r=>{var h,y,c;const a=p("div",{className:"spot-qualifying-reasons__item",parent:i}),u=p("div",{className:"spot-qualifying-reasons__icon-wrapper",parent:a}),f=e[((h=r.benefitType)==null?void 0:h.name)||""]||e[r.name||""];if(f){const d=p("img",{parent:u});d.src=s+f,d.alt=((y=r.benefitType)==null?void 0:y.name)||r.name||"",d.className="spot-qualifying-reasons__icon"}p("span",{className:"spot-qualifying-reasons__label",text:((c=r.benefitType)==null?void 0:c.name)||r.name||"",parent:a})})}function L(l,t=[]){if(t.length===0)return;const o=p("div",{className:"spot-covered-items__container",parent:l});p("div",{className:"spot-covered-items__title",text:"Items covered in your cart:",parent:o});const n=p("ul",{className:"spot-covered-items__list",parent:o});t.forEach(i=>{const e=p("li",{parent:n});p("span",{text:i,parent:e})})}function P(l,t=[]){const o=p("div",{className:"spot-table__container",parent:l}),n=p("table",{className:"spot-refund__table spot-table--dynamic",parent:o}),i=p("thead",{parent:n}),e=p("tr",{parent:i});p("th",{text:"When you cancel",parent:e}),p("th",{text:"You will receive",parent:e});const s=p("tbody",{parent:n});t.forEach(({text:r,percent:a,amount:u})=>{const f=p("tr",{parent:s});p("td",{text:r,parent:f});const h=a==="Not eligible for refund"?"Not eligible for a refund":`$${u} refund`;p("td",{text:h,parent:f})})}function $(l,t,o){const n=p("div",{className:"spot-selection__options",parent:l}),i=p("label",{className:`spot-selection__option ${t?"selected":""}`,parent:n}),e=p("input",{parent:i});e.type="radio",e.name="selection",e.value="yes",t&&(e.checked=!0),p("strong",{text:o.yesOptionText,parent:i}),p("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:i});const s=p("label",{className:"spot-selection__option",parent:n}),r=p("input",{parent:s});return r.type="radio",r.name="selection",r.value="no",p("span",{text:o.noOptionText,parent:s}),n}function V(l,t){var i;const o=(i=t.communication)==null?void 0:i.paymentTerms,n=p("div",{className:"spot-payment-terms",parent:l});return p("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:n}),p("div",{className:"spot-payment-terms__body",text:o||"",parent:n}),n}function R(l,t,o="bottom-right"){if(o==="top-right"){const e=p("div",{className:"spot-logo__top-right",parent:l});e.innerHTML=`
4
+ stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
5
+ </svg>`,p("span",{text:s,parent:i})})}function L(m,t=[]){if(!t||t.length===0)return;const r=p("div",{className:"spot-qualifying-reasons__container",parent:m}),s=[...t].sort((o,a)=>o.rank-a.rank),i=p("div",{className:"spot-qualifying-reasons__grid",parent:r}),e={"Accident & Illness":"cross.svg","Family Emergencies":"users.svg",Layoffs:"building.svg","Jury Duty":"scale.svg","Work Travel Conflict":"briefcase.svg","Severe Weather":"umbrella.svg","Travel Interruption":"plane.svg","Military Duty":"medal.svg"};let n;try{const o=document.currentScript;if(o!=null&&o.src){const a=new URL(o.src);n=a.origin+a.pathname.replace(/\/[^/]*$/,"/")}else n=window.location.origin+window.location.pathname.replace(/\/[^/]*$/,"/");n+="assets/"}catch{n="./assets/"}s.forEach(o=>{var f,y,c;const a=p("div",{className:"spot-qualifying-reasons__item",parent:i}),u=p("div",{className:"spot-qualifying-reasons__icon-wrapper",parent:a}),h=e[((f=o.benefitType)==null?void 0:f.name)||""]||e[o.name||""];if(h){const d=p("img",{parent:u});d.src=n+h,d.alt=((y=o.benefitType)==null?void 0:y.name)||o.name||"",d.className="spot-qualifying-reasons__icon"}p("span",{className:"spot-qualifying-reasons__label",text:((c=o.benefitType)==null?void 0:c.name)||o.name||"",parent:a})})}function O(m,t=[],r){if(t.length===0||!r||r<=1)return;const s=new Map;t.forEach(d=>{s.set(d,(s.get(d)||0)+1)});const e=Array.from(s.entries()).map(([d,l])=>({item:d,count:l,displayText:l>1?`${l} x ${d}`:d})).sort((d,l)=>{const b=d.item.charAt(0),q=l.item.charAt(0),g=/[a-zA-Z]/.test(b),w=/[a-zA-Z]/.test(q);return!g&&w?-1:g&&!w?1:d.item.localeCompare(l.item,void 0,{sensitivity:"base"})}),n=p("div",{className:"spot-covered-items__container",parent:m}),o=p("div",{className:"spot-covered-items__header",parent:n}),a=p("button",{className:"spot-covered-items__toggle",parent:o});p("span",{className:"spot-covered-items__title",text:`Items Covered in Your Cart (${t.length})`,parent:a});const u=p("div",{className:"spot-covered-items__right-section",parent:a});p("span",{className:"spot-covered-items__view-all",text:"View All",parent:u});const h=p("span",{className:"spot-covered-items__arrow",innerHTML:"▼",parent:u}),f=p("div",{className:"spot-covered-items__content",parent:n}),y=p("ul",{className:"spot-covered-items__list",parent:f});e.forEach(({displayText:d})=>{const l=p("li",{parent:y});p("span",{text:d,parent:l})});let c=!1;f.style.display="none",a.addEventListener("click",()=>{c=!c,f.style.display=c?"block":"none",h.innerHTML=c?"▲":"▼",a.setAttribute("aria-expanded",c.toString())}),a.setAttribute("aria-expanded","false"),a.setAttribute("aria-controls","covered-items-list"),f.setAttribute("id","covered-items-list")}function P(m,t=[]){const r=p("div",{className:"spot-table__container",parent:m}),s=p("table",{className:"spot-refund__table spot-table--dynamic",parent:r}),i=p("thead",{parent:s}),e=p("tr",{parent:i});p("th",{text:"When you cancel",parent:e}),p("th",{text:"You will receive",parent:e});const n=p("tbody",{parent:s});t.forEach(({text:o,percent:a,amount:u})=>{const h=p("tr",{parent:n});p("td",{text:o,parent:h});const f=a==="Not eligible for refund"?"Not eligible for a refund":`$${u} refund`;p("td",{text:f,parent:h})})}function $(m,t,r){const s=p("div",{className:"spot-selection__options",parent:m}),i=p("label",{className:`spot-selection__option ${t?"selected":""}`,parent:s}),e=p("input",{parent:i});e.type="radio",e.name="selection",e.value="yes",t&&(e.checked=!0),p("strong",{text:r.yesOptionText,parent:i}),p("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:i});const n=p("label",{className:"spot-selection__option",parent:s}),o=p("input",{parent:n});return o.type="radio",o.name="selection",o.value="no",p("span",{text:r.noOptionText,parent:n}),s}function R(m,t){var i;const r=(i=t.communication)==null?void 0:i.paymentTerms,s=p("div",{className:"spot-payment-terms",parent:m});return p("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:s}),p("div",{className:"spot-payment-terms__body",text:r||"",parent:s}),s}function V(m,t,r="bottom-right"){if(r==="top-right"){const e=p("div",{className:"spot-logo__top-right",parent:m});e.innerHTML=`
6
6
  <svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
7
7
  <rect width="145" height="28"/>
8
8
  <rect x="-655" y="-270" width="819" height="325" rx="10"/>
@@ -17,7 +17,7 @@
17
17
  <rect width="45.405" height="14.8867" fill="white" transform="translate(87 8)"/>
18
18
  </clipPath>
19
19
  </defs>
20
- </svg>`}const n=p("div",{className:"spot-footer__container",parent:l}),i=p("div",{className:"spot-footer__terms",parent:n});if(p("span",{innerHTML:t.communication.legalDisclaimer,parent:i}),p("br",{parent:i}),p("a",{href:t.communication.termsAndConditionsUrl,target:"_blank",className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:i}),o==="bottom-right"){const e=p("p",{className:"spot-footer__powered-by",parent:n});e.innerHTML=`
20
+ </svg>`}const s=p("div",{className:"spot-footer__container",parent:m}),i=p("div",{className:"spot-footer__terms",parent:s});if(p("span",{innerHTML:t.communication.legalDisclaimer,parent:i}),p("br",{parent:i}),p("a",{href:t.communication.termsAndConditionsUrl,target:"_blank",className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:i}),r==="bottom-right"){const e=p("p",{className:"spot-footer__powered-by",parent:s});e.innerHTML=`
21
21
  <svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
22
22
  <rect width="145" height="28"/>
23
23
  <rect x="-655" y="-270" width="819" height="325" rx="10"/>
@@ -32,4 +32,4 @@
32
32
  <rect width="45.405" height="14.8867" fill="white" transform="translate(87 8)"/>
33
33
  </clipPath>
34
34
  </defs>
35
- </svg>`}return n}const S=":root{--spot-font-family: Arial;--spot-padding: 1.25rem;--spot-background-color: #ffffff;--spot-font-color: #000000;--spot-border-radius: .5rem;--spot-title-font-size: 1.25rem;--spot-title-font-weight: 700;--spot-title-padding: 0 0 1.25rem 0;--spot-description-font-size: .875rem;--spot-description-font-weight: 400;--spot-description-padding: 0 0 .5rem 0;--spot-bullets-font-size: .875rem;--spot-bullets-font-weight: 400;--spot-bullets-padding: .3125rem;--spot-table-border-radius: .625rem;--spot-table-header-font-size: .875rem;--spot-table-header-font-weight: 700;--spot-table-header-padding: 0 .5rem .625rem;--spot-table-cell-font-size: .815rem;--spot-table-cell-font-weight: 400;--spot-table-cell-padding: 0 .625rem;--spot-radio-border: #000000;--spot-radio-border-radius: .625rem;--spot-radio-checked-background: #000000;--spot-radio-text-font-size: .875rem;--spot-radio-text-font-weight: 400;--spot-radio-text-padding: .625rem;--spot-radio-selection-background: #f4f4f4;--spot-radio-selection-border-radius: .625rem;--spot-radio-selection-padding: .625rem;--spot-recommended-tag-background: #000000;--spot-recommended-tag-font-color: #ffffff;--spot-recommended-tag-font-size: .875rem;--spot-recommended-tag-font-weight: 700;--spot-recommended-tag-padding: .25rem .5rem;--spot-recommended-tag-border-radius: .5rem;--spot-selection-error-font-color: #ff0000;--spot-selection-error-font-size: .875rem;--spot-qualifying-reasons-margin: .75rem 0;--spot-qualifying-reasons-padding: 0 .3125rem;--spot-qualifying-reasons-column-gap: 3rem;--spot-qualifying-reasons-row-gap: .25rem;--spot-qualifying-reasons-grid-padding-left: 1rem;--spot-qualifying-reasons-icon-wrapper-size: 1.125rem;--spot-qualifying-reasons-icon-size: .75rem;--spot-qualifying-reasons-icon-border-color: #2e2e2e;--spot-qualifying-reasons-icon-border-width: 1px;--spot-qualifying-reasons-icon-background: #ffffff;--spot-qualifying-reasons-item-gap: .625rem;--spot-qualifying-reasons-label-font-size: .8rem;--spot-qualifying-reasons-label-font-weight: 400;--spot-qualifying-reasons-label-font-color: #000000;--spot-qualifying-reasons-label-font-family: Arial;--spot-selection-error-padding: .5rem;--spot-payment-terms-background: #f4f4f4;--spot-payment-terms-border-radius: .625rem;--spot-payment-terms-padding: 1rem;--spot-payment-terms-font-color: #636569;--spot-payment-terms-font-size: .75rem;--spot-payment-terms-header-font-weight: 700;--spot-payment-terms-header-font-size: .875rem;--spot-payment-terms-header-margin-bottom: .5rem;--spot-payment-terms-header-border-color: #c2c2c2;--spot-payment-terms-header-padding: 0 0 .5rem 0;--spot-terms-font-size: .75rem;--spot-terms-font-weight: 400;--spot-terms-font-color: #636569;--spot-terms-padding: 0;--spot-terms-link-text-decoration: underline;--spot-terms-link-font-size: .75rem;--spot-terms-link-font-weight: 400;--spot-terms-link-font-color: #636569;--spot-terms-link-padding: 0;--spot-desktop-radio-margin-top: -1.5rem;--spot-benefits-margin-bottom: 0rem;--spot-covered-items-margin-bottom: 0rem;--spot-footer-gap: 1rem;--spot-footer-terms-margin-right: 7rem;--spot-payment-terms-margin-top: .5rem;--spot-logo-top-right-margin: 1rem}.spot-refund-guarantee{font-family:var(--spot-font-family);padding:var(--spot-padding);background-color:var(--spot-background-color);color:var(--spot-font-color);border:.0625rem solid #e0e0e0;border-radius:var(--spot-border-radius);max-width:51rem;margin:1rem;container-type:inline-size;position:relative;word-wrap:normal;overflow-wrap:normal;-webkit-hyphens:none;hyphens:none}.spot-refund-guarantee *{color:inherit}.spot-header__title{font-size:var(--spot-title-font-size);font-weight:var(--spot-title-font-weight);padding:var(--spot-title-padding);color:var(--spot-title-font-color);font-family:var(--spot-title-font-family);line-height:120%;letter-spacing:-.03125rem}.spot-header__description{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:var(--spot-description-padding);line-height:125%;letter-spacing:-.025rem}.spot-content__wrapper{display:flex;flex-direction:column}.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr auto;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container,.desktop-layout .spot-covered-items__container,.desktop-layout .spot-selection__options{min-width:0;word-wrap:normal}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container{grid-row:1;margin-bottom:var(--spot-benefits-margin-bottom)}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1;margin-bottom:var(--spot-covered-items-margin-bottom)}.desktop-layout .spot-selection__options{grid-row:3;margin-top:var(--spot-desktop-radio-margin-top)}.desktop-layout .spot-payment-terms__wrapper{grid-row:4;grid-column:1;margin-top:var(--spot-payment-terms-margin-top)}.desktop-layout .spot-table__container{grid-row:1 / span 4;grid-column:2;width:auto;min-width:20.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-table__container{display:flex;justify-content:flex-start;margin-top:1rem;margin-bottom:1rem;padding-left:.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-refund__table{width:100%;max-width:22rem;table-layout:auto}@media (max-width: 850px){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 500px){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 600px){.spot-refund__table th{padding:0rem}}.spot-benefits__list{list-style-type:none;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-benefits__list li{margin-bottom:.375rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.spot-qualifying-reasons__container{margin:var(--spot-qualifying-reasons-margin);padding:var(--spot-qualifying-reasons-padding)}.spot-qualifying-reasons__grid{display:grid;grid-template-columns:repeat(2,minmax(0,max-content));column-gap:var(--spot-qualifying-reasons-column-gap);row-gap:var(--spot-qualifying-reasons-row-gap);max-width:100%;padding-left:var(--spot-qualifying-reasons-grid-padding-left)}.spot-qualifying-reasons__item{display:flex;align-items:center;gap:var(--spot-qualifying-reasons-item-gap)}.spot-qualifying-reasons__icon-wrapper{width:var(--spot-qualifying-reasons-icon-wrapper-size);height:var(--spot-qualifying-reasons-icon-wrapper-size);border-radius:50%;border:var(--spot-qualifying-reasons-icon-border-width) solid var(--spot-qualifying-reasons-icon-border-color);background-color:var(--spot-qualifying-reasons-icon-background);display:flex;align-items:center;justify-content:center;flex-shrink:0}.spot-qualifying-reasons__icon{width:var(--spot-qualifying-reasons-icon-size);height:var(--spot-qualifying-reasons-icon-size)}.spot-qualifying-reasons__label{font-size:var(--spot-qualifying-reasons-label-font-size);font-weight:var(--spot-qualifying-reasons-label-font-weight);color:var(--spot-qualifying-reasons-label-font-color);font-family:var(--spot-qualifying-reasons-label-font-family);line-height:1.2}@media (max-width: 480px){.spot-qualifying-reasons__grid{grid-template-columns:1fr}}.spot-covered-items__container{margin-top:0;margin-bottom:1rem}.spot-covered-items__title{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:0 .3125rem .25rem;line-height:125%;margin:0}.spot-covered-items__list{list-style-type:disc;list-style-position:inside;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-covered-items__list li{margin-bottom:.3rem;text-align:left}.spot-table__container{width:100%}.spot-refund__table{max-width:22rem;border-radius:var(--spot-table-border-radius);overflow:hidden;border:.09375rem solid #636569;table-layout:fixed;margin-bottom:.5rem;margin-top:.25rem;padding:.625rem}.spot-refund__table--dynamic{height:auto!important;min-height:7.5rem}.spot-refund__table td,.spot-refund__table th{padding:.375rem .625rem;text-align:left}.spot-refund__table th{text-align:left;font-size:var(--spot-table-header-font-size);font-weight:var(--spot-table-header-font-weight);color:var(--spot-table-header-font-color);font-family:var(--spot-table-header-font-family);padding:var(--spot-table-header-padding)}.spot-refund__table td{text-align:left;font-size:var(--spot-table-cell-font-size);font-weight:var(--spot-table-cell-font-weight);color:var(--spot-table-cell-font-color);font-family:var(--spot-table-cell-font-family);padding:var(--spot-table-cell-padding)}input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:.75rem;height:.75rem;min-width:.75rem;border:.0625rem solid var(--spot-radio-border);border-radius:var(--spot-radio-border-radius);margin-right:.5rem;position:relative;vertical-align:middle;top:-.0625rem;cursor:pointer;flex-shrink:0}input[type=radio]:checked{background:var(--spot-radio-checked-background);box-shadow:inset 0 0 0 .0625rem #fff}.spot-selection__options{display:flex;flex-direction:column;gap:.5rem}.spot-selection__option{display:flex;align-items:center;flex-wrap:nowrap;position:relative;transition:background .2s;cursor:pointer;font-size:var(--spot-radio-text-font-size);font-weight:var(--spot-radio-text-font-weight);color:var(--spot-radio-text-font-color);font-family:var(--spot-radio-text-font-family);padding:var(--spot-radio-text-padding);margin-right:.5rem}.spot-selection__option.selected{background:var(--spot-radio-selection-background);border-radius:var(--spot-radio-selection-border-radius);padding:var(--spot-radio-selection-padding)}.spot-selection__recommended-tag{background:var(--spot-recommended-tag-background);color:var(--spot-recommended-tag-font-color);font-size:var(--spot-recommended-tag-font-size);font-weight:var(--spot-recommended-tag-font-weight);padding:var(--spot-recommended-tag-padding);border-radius:var(--spot-recommended-tag-border-radius);margin-left:.75rem;white-space:nowrap;flex-shrink:0}@media (max-width: 850px){.spot-selection__recommended-tag{margin-left:.5rem}}@media (max-width: 600px){.spot-selection__recommended-tag{margin-left:.5rem;font-size:.75rem;padding:.1875rem .4375rem}}.spot-selection__error{color:var(--spot-selection-error-font-color);font-size:var(--spot-selection-error-font-size);padding:var(--spot-selection-error-padding);display:none}.spot-payment-terms__wrapper{margin-top:1rem}.spot-payment-terms__header{font-weight:var(--spot-payment-terms-header-font-weight);margin-bottom:.5rem;padding:var(--spot-payment-terms-header-padding);font-size:var(--spot-payment-terms-header-font-size);border-bottom:1px solid var(--spot-payment-terms-header-border-color)}.spot-payment-terms{background-color:var(--spot-payment-terms-background);border-radius:var(--spot-payment-terms-border-radius);padding:var(--spot-payment-terms-padding);margin-right:.5rem;color:var(--spot-payment-terms-font-color);font-size:var(--spot-payment-terms-font-size)}.spot-footer__terms{margin-top:.625rem;margin-right:.25rem;font-size:var(--spot-terms-font-size);font-weight:var(--spot-terms-font-weight);color:var(--spot-terms-font-color);font-family:var(--spot-terms-font-family);padding:var(--spot-terms-padding);line-height:1.4;word-wrap:normal;-webkit-hyphens:none;hyphens:none;flex:1;min-width:0;overflow-wrap:normal}.spot-footer__terms-link{text-decoration:var(--spot-terms-link-text-decoration);font-size:var(--spot-terms-link-font-size);font-weight:var(--spot-terms-link-font-weight);color:var(--spot-terms-link-font-color);font-family:var(--spot-terms-link-font-family);padding:var(--spot-terms-link-padding)}.spot-footer__container{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;flex-wrap:nowrap;gap:var(--spot-footer-gap)}@container (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}@media (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}.spot-footer__powered-by{margin-top:0;flex-shrink:0}.spot-logo__top-right{position:absolute;top:-14px;right:40px;z-index:10;background:#fff;padding:0 8px}@container (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}@media (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}";function Q(l){const t=document.createElement("style");t.textContent=l,document.head.appendChild(t)}Q(S);const k={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote",local:"http://localhost:3999/api/v1/quote"};class Z{constructor(t={}){this.options={location:"body",showTable:!0,optInSelected:!1,logoPosition:"bottom-right",apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},useMockData:!1,...t},this._onResize=this._updateLayout.bind(this),this.root=typeof this.options.location=="string"?document.querySelector(this.options.location):this.options.location,this.currentSelection=this.options.optInSelected?"yes":null,this._init()}async _init(){var t,o,n,i,e;try{x(this.options);let s;if(this.options.useMockData&&this.options.mockData)s=this.options.mockData;else{const{environment:r,partnerId:a}=this.options.apiConfig,f=this.options.apiConfig.customEndpoint||k[r];s="cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?await E(f,a,this.options.quoteRequestData):await _(f,a,this.options.quoteRequestData)}if(s.status!=="QUOTE_AVAILABLE"){s.status==="NO_MATCHING_QUOTE"&&((t=this.options.callbacks)!=null&&t.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=s.data,!this.quote)throw new Error("No quote data in response");if(this._renderWidget(),this.options.optInSelected&&((o=this.options.callbacks)!=null&&o.onOptIn)){const r={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const a=this.options.quoteRequestData;r.batchQuoteDetails=this.quote.originalQuotes.map(u=>{var h;const f=(h=a.items)==null?void 0:h.find(y=>(y.cartItemId||`item-${a.items.indexOf(y)+1}`)===u.id);return{quoteId:u.id,productPrice:(f==null?void 0:f.productPrice)||u.spotPrice,cartItemId:u.id}})}this.options.callbacks.onOptIn(r)}if((n=this.options.callbacks)!=null&&n.onQuoteRetrieved){const r=this.options.callbacks.onQuoteRetrieved(this.quote);r&&this._applyQuoteUpdates(r)}}catch(s){if((i=this.options.callbacks)!=null&&i.onError){const r=s;(e=this.options.callbacks)==null||e.onError({message:r.message,status:r.status,responseBody:r.responseBody})}}}_renderWidget(){if(!this.quote)return;this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([n,i])=>{const e=`--${n}`;this.container.style.setProperty(e,i)}),N(this.container,this.quote.communication);const t=document.createElement("div");t.className="spot-content__wrapper",this.container.appendChild(t),this.quote.qualifyingReasons?O(t,this.quote.qualifyingReasons):z(t,this.quote.communication.bulletPoints),this.quote.coveredItems&&L(t,this.quote.coveredItems),this.options.showTable&&!this.quote.qualifyingReasons&&P(t,this.quote.payoutSchedule);const o=$(t,this.options.optInSelected,this.quote.communication);t.appendChild(o),this.paymentTermsEl=p("div",{className:"spot-payment-terms__wrapper",parent:t}),R(this.container,this.quote,this.options.logoPosition),window.addEventListener("resize",this._onResize),this._setupResizeObserver(),this._updateLayout(),this._setupOptionListeners(o)}_updateLayout(){if(!this.container||!this.quote)return;const t=this.container.querySelector(".spot-content__wrapper"),o=this.options.showTable&&!this.quote.qualifyingReasons;if(!t||!o){t==null||t.classList.remove("desktop-layout");return}const n=this._shouldUseDesktopLayout(t);t.classList.toggle("desktop-layout",n)}_shouldUseDesktopLayout(t){const o=this.container.offsetWidth-40,n=325,i=16;if(o>=900)return!0;if(o>=650){const e=t.classList.contains("desktop-layout");t.classList.remove("desktop-layout"),t.offsetHeight;const s=t.querySelector(".spot-benefits__list, .spot-qualifying-reasons__container");if(!s)return e&&t.classList.add("desktop-layout"),e;const a=Math.min(s.scrollWidth,400)+n+i;return e&&t.classList.add("desktop-layout"),o>=a}return!1}_setupResizeObserver(){!this.container||!window.ResizeObserver||(this._resizeObserver=new ResizeObserver(()=>{this._resizeTimeout&&clearTimeout(this._resizeTimeout),this._resizeTimeout=window.setTimeout(()=>{this._updateLayout()},100)}),this._resizeObserver.observe(this.container))}_applyQuoteUpdates(t){!this.quote||!this.container||(t.spotPriceWithFees!==void 0&&(this.quote.communication.yesOptionText=this.quote.communication.yesOptionText.replace(`$${this.quote.spotPrice.toFixed(2)}`,`$${t.spotPriceWithFees.toFixed(2)}`)),this.destroy(),this._renderWidget())}_setupOptionListeners(t){const o=t.querySelectorAll('input[type="radio"]'),n=t.querySelectorAll(".spot-selection__option");o.forEach(i=>{i.addEventListener("change",e=>{var a,u,f;const s=e.target,r=s.value;if(this.hideSelectionError(),this.currentSelection=r,n.forEach(h=>h.classList.remove("selected")),(a=s.closest(".spot-selection__option"))==null||a.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),r==="yes"&&(this.options.quoteRequestData.isPartialPayment&&V(this.paymentTermsEl,this.quote),(u=this.options.callbacks)!=null&&u.onOptIn)){const h={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;h.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var m;const d=(m=y.items)==null?void 0:m.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptIn(h)}if(r==="no"&&((f=this.options.callbacks)!=null&&f.onOptOut)){const h={status:"QUOTE_DECLINED",quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;h.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var m;const d=(m=y.items)==null?void 0:m.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptOut(h)}})})}showSelectionError(){var t;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const o=(t=this.container)==null?void 0:t.querySelector(".spot-selection__options");o&&o.insertAdjacentElement("afterend",this.errorEl)}this.errorEl.style.display="block"}hideSelectionError(){this.errorEl&&(this.errorEl.style.display="none")}validateSelection(){if(!this.container)return!1;const t=!!this.container.querySelector('input[name="selection"]:checked');return t?this.hideSelectionError():this.showSelectionError(),t}async updateQuote(t){var o,n,i,e;try{const s={...this.options,quoteRequestData:t};x(s);const{environment:r,partnerId:a,customEndpoint:u}=this.options.apiConfig,f=u||k[r],y="cartInfo"in s.quoteRequestData&&"items"in s.quoteRequestData?await E(f,a,s.quoteRequestData):await _(f,a,s.quoteRequestData);if(y.status!=="QUOTE_AVAILABLE")return y.status==="NO_MATCHING_QUOTE"&&((o=this.options.callbacks)!=null&&o.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:s.quoteRequestData}),!1;if(this.options.quoteRequestData=s.quoteRequestData,this.quote=y.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(n=this.options.callbacks)!=null&&n.onQuoteRetrieved){const c=this.options.callbacks.onQuoteRetrieved(this.quote);c&&this._applyQuoteUpdates(c)}return!0}catch(s){const r=s;return(e=(i=this.options.callbacks)==null?void 0:i.onError)==null||e.call(i,{message:r.message,status:r.status,responseBody:r.responseBody}),!1}}getSelection(){var o,n,i;if(this.currentSelection==null)return null;const t={selection:this.currentSelection,quoteId:(o=this.quote)==null?void 0:o.id,spotPrice:(n=this.quote)==null?void 0:n.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};if((i=this.quote)!=null&&i.originalQuotes&&this.quote.originalQuotes.length>0){const e=this.options.quoteRequestData;t.batchQuoteDetails=this.quote.originalQuotes.map(s=>{var a;const r=(a=e.items)==null?void 0:a.find(u=>(u.cartItemId||`item-${e.items.indexOf(u)+1}`)===s.id);return{quoteId:s.id,productPrice:(r==null?void 0:r.productPrice)||s.spotPrice,cartItemId:s.id}})}return t}destroy(){window.removeEventListener("resize",this._onResize),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeTimeout&&window.clearTimeout(this._resizeTimeout),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return Z});
35
+ </svg>`}return s}const S=":root{--spot-font-family: Arial;--spot-padding: 1.25rem;--spot-background-color: #ffffff;--spot-font-color: #000000;--spot-border-radius: .5rem;--spot-title-font-size: 1.25rem;--spot-title-font-weight: 700;--spot-title-padding: 0 0 1.25rem 0;--spot-description-font-size: .875rem;--spot-description-font-weight: 400;--spot-description-padding: 0 0 .5rem 0;--spot-bullets-font-size: .875rem;--spot-bullets-font-weight: 400;--spot-bullets-padding: .3125rem;--spot-bullets-checkmark-color: #2e2e2e;--spot-table-border-radius: .625rem;--spot-table-header-font-size: .875rem;--spot-table-header-font-weight: 700;--spot-table-header-padding: 0 .5rem .625rem;--spot-table-cell-font-size: .815rem;--spot-table-cell-font-weight: 400;--spot-table-cell-padding: 0 .625rem;--spot-radio-border: #000000;--spot-radio-border-radius: .625rem;--spot-radio-checked-background: #000000;--spot-radio-text-font-size: .875rem;--spot-radio-text-font-weight: 400;--spot-radio-text-padding: .625rem;--spot-radio-selection-background: #f4f4f4;--spot-radio-selection-border-radius: .625rem;--spot-radio-selection-padding: .625rem;--spot-recommended-tag-background: #000000;--spot-recommended-tag-font-color: #ffffff;--spot-recommended-tag-font-size: .875rem;--spot-recommended-tag-font-weight: 700;--spot-recommended-tag-padding: .25rem .5rem;--spot-recommended-tag-border-radius: .5rem;--spot-selection-error-font-color: #ff0000;--spot-selection-error-font-size: .875rem;--spot-qualifying-reasons-margin: .75rem 0;--spot-qualifying-reasons-padding: 0 .3125rem;--spot-qualifying-reasons-column-gap: 3rem;--spot-qualifying-reasons-row-gap: .25rem;--spot-qualifying-reasons-grid-padding-left: 1rem;--spot-qualifying-reasons-icon-wrapper-size: 1.125rem;--spot-qualifying-reasons-icon-size: .75rem;--spot-qualifying-reasons-icon-border-color: #2e2e2e;--spot-qualifying-reasons-icon-border-width: 1px;--spot-qualifying-reasons-icon-background: #ffffff;--spot-qualifying-reasons-item-gap: .625rem;--spot-qualifying-reasons-label-font-size: .8rem;--spot-qualifying-reasons-label-font-weight: 400;--spot-qualifying-reasons-label-font-color: #000000;--spot-qualifying-reasons-label-font-family: Arial;--spot-selection-error-padding: .5rem;--spot-payment-terms-background: #f4f4f4;--spot-payment-terms-border-radius: .625rem;--spot-payment-terms-padding: 1rem;--spot-payment-terms-font-color: #636569;--spot-payment-terms-font-size: .75rem;--spot-payment-terms-header-font-weight: 700;--spot-payment-terms-header-font-size: .875rem;--spot-payment-terms-header-margin-bottom: .5rem;--spot-payment-terms-header-border-color: #c2c2c2;--spot-payment-terms-header-padding: 0 0 .5rem 0;--spot-terms-font-size: .75rem;--spot-terms-font-weight: 400;--spot-terms-font-color: #636569;--spot-terms-padding: 0;--spot-terms-link-text-decoration: underline;--spot-terms-link-font-size: .75rem;--spot-terms-link-font-weight: 400;--spot-terms-link-font-color: #636569;--spot-terms-link-padding: 0;--spot-covered-items-background: #f1f3f5;--spot-covered-items-hover-background: #e9ecef;--spot-covered-items-border-radius: .5rem;--spot-covered-items-padding: .75rem 1rem;--spot-covered-items-font-size: .875rem;--spot-covered-items-font-weight: 400;--spot-covered-items-font-color: #000000;--spot-covered-items-font-family: Arial;--spot-covered-items-arrow-font-size: .6rem;--spot-covered-items-arrow-color: #636569;--spot-covered-items-view-all-color: #636569;--spot-covered-items-view-all-font-size: .875rem;--spot-covered-items-view-all-font-weight: 400;--spot-covered-items-content-background: #f8f9fa;--spot-covered-items-content-border: 1px solid #e0e0e0;--spot-covered-items-content-border-radius: .5rem;--spot-covered-items-content-padding: .75rem 1rem;--spot-desktop-radio-margin-top: -1.5rem;--spot-benefits-margin-bottom: 0rem;--spot-covered-items-margin-bottom: 1.5rem;--spot-footer-gap: 1rem;--spot-footer-terms-margin-right: 7rem;--spot-payment-terms-margin-top: .5rem;--spot-logo-top-right-margin: 1rem}.spot-refund-guarantee{font-family:var(--spot-font-family);padding:var(--spot-padding);background-color:var(--spot-background-color);color:var(--spot-font-color);border:.0625rem solid #e0e0e0;border-radius:var(--spot-border-radius);max-width:51rem;margin:1rem;container-type:inline-size;position:relative;word-wrap:normal;overflow-wrap:normal;-webkit-hyphens:none;hyphens:none}.spot-refund-guarantee *{color:inherit}.spot-header__title{font-size:var(--spot-title-font-size);font-weight:var(--spot-title-font-weight);padding:var(--spot-title-padding);color:var(--spot-title-font-color);font-family:var(--spot-title-font-family);line-height:120%;letter-spacing:-.03125rem}.spot-header__description{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:var(--spot-description-padding);line-height:125%;letter-spacing:-.025rem}.spot-content__wrapper{display:flex;flex-direction:column}.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr auto;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container,.desktop-layout .spot-covered-items__container,.desktop-layout .spot-selection__options{min-width:0;word-wrap:normal}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container{grid-row:1;margin-bottom:var(--spot-benefits-margin-bottom)}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1;margin-bottom:var(--spot-covered-items-margin-bottom)}.desktop-layout .spot-selection__options{grid-row:3;margin-top:var(--spot-desktop-radio-margin-top)}.desktop-layout .spot-payment-terms__wrapper{grid-row:4;grid-column:1;margin-top:var(--spot-payment-terms-margin-top)}.desktop-layout .spot-table__container{grid-row:1 / span 4;grid-column:2;width:auto;min-width:20.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-table__container{display:flex;justify-content:flex-start;margin-top:1rem;margin-bottom:1rem;padding-left:.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-refund__table{width:100%;max-width:22rem;table-layout:auto}@media (max-width: 850px){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 500px){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 600px){.spot-refund__table th{padding:0rem}}.spot-benefits__list{list-style-type:none;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-benefits__list li{margin-bottom:.375rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.spot-bullets__checkmark path{stroke:var(--spot-bullets-checkmark-color)}.spot-qualifying-reasons__container{margin:var(--spot-qualifying-reasons-margin);padding:var(--spot-qualifying-reasons-padding)}.spot-qualifying-reasons__grid{display:grid;grid-template-columns:repeat(2,minmax(0,max-content));column-gap:var(--spot-qualifying-reasons-column-gap);row-gap:var(--spot-qualifying-reasons-row-gap);max-width:100%;padding-left:var(--spot-qualifying-reasons-grid-padding-left)}.spot-qualifying-reasons__item{display:flex;align-items:center;gap:var(--spot-qualifying-reasons-item-gap)}.spot-qualifying-reasons__icon-wrapper{width:var(--spot-qualifying-reasons-icon-wrapper-size);height:var(--spot-qualifying-reasons-icon-wrapper-size);border-radius:50%;border:var(--spot-qualifying-reasons-icon-border-width) solid var(--spot-qualifying-reasons-icon-border-color);background-color:var(--spot-qualifying-reasons-icon-background);display:flex;align-items:center;justify-content:center;flex-shrink:0}.spot-qualifying-reasons__icon{width:var(--spot-qualifying-reasons-icon-size);height:var(--spot-qualifying-reasons-icon-size)}.spot-qualifying-reasons__label{font-size:var(--spot-qualifying-reasons-label-font-size);font-weight:var(--spot-qualifying-reasons-label-font-weight);color:var(--spot-qualifying-reasons-label-font-color);font-family:var(--spot-qualifying-reasons-label-font-family);line-height:1.2}@media (max-width: 480px){.spot-qualifying-reasons__grid{grid-template-columns:1fr}}.spot-covered-items__container{margin-top:.85rem;margin-bottom:.5rem;max-width:26rem}.spot-content__wrapper.desktop-layout:has(.spot-table__container) .spot-covered-items__container{margin-top:0rem;margin-bottom:1rem}.spot-covered-items__title{font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);padding:0 .3125rem .25rem;line-height:125%;margin:0}.spot-covered-items__list{list-style-type:disc;list-style-position:inside;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-covered-items__list li{margin-bottom:.3rem;text-align:left}.spot-covered-items__list li:last-child{margin-bottom:0}.spot-covered-items__header{margin-bottom:.5rem}.spot-covered-items__toggle{background:var(--spot-covered-items-background);border:none;border-radius:var(--spot-covered-items-border-radius);padding:var(--spot-covered-items-padding);cursor:pointer;display:flex;align-items:center;justify-content:space-between;width:100%;font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);line-height:125%;transition:all .2s ease}.spot-covered-items__toggle:hover{background-color:var(--spot-covered-items-hover-background)}.spot-covered-items__toggle:focus{outline:none;box-shadow:0 0 0 2px #0000001a}.spot-covered-items__title{font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);line-height:125%;margin:0;padding:0}.spot-covered-items__right-section{display:flex;align-items:center;gap:.5rem;margin-left:auto}.spot-covered-items__view-all{font-size:var(--spot-covered-items-view-all-font-size);font-weight:var(--spot-covered-items-view-all-font-weight);color:var(--spot-covered-items-view-all-color);font-family:var(--spot-covered-items-font-family);line-height:125%}.spot-covered-items__arrow{font-size:var(--spot-covered-items-arrow-font-size);transition:transform .2s ease;color:var(--spot-covered-items-arrow-color);flex-shrink:0;transform:scaleX(1.5)}.spot-covered-items__content{margin-top:.5rem;transition:all .2s ease;overflow:hidden}.spot-covered-items__list{background-color:var(--spot-covered-items-content-background);border:var(--spot-covered-items-content-border);border-radius:var(--spot-covered-items-content-border-radius);margin:0;padding:var(--spot-covered-items-content-padding)}.spot-table__container{width:100%}.spot-refund__table{max-width:22rem;border-radius:var(--spot-table-border-radius);overflow:hidden;border:.09375rem solid #636569;table-layout:fixed;margin-bottom:.5rem;margin-top:.25rem;padding:.625rem}.spot-refund__table--dynamic{height:auto!important;min-height:7.5rem}.spot-refund__table td,.spot-refund__table th{padding:.375rem .625rem;text-align:left}.spot-refund__table th{text-align:left;font-size:var(--spot-table-header-font-size);font-weight:var(--spot-table-header-font-weight);color:var(--spot-table-header-font-color);font-family:var(--spot-table-header-font-family);padding:var(--spot-table-header-padding)}.spot-refund__table td{text-align:left;font-size:var(--spot-table-cell-font-size);font-weight:var(--spot-table-cell-font-weight);color:var(--spot-table-cell-font-color);font-family:var(--spot-table-cell-font-family);padding:var(--spot-table-cell-padding)}input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:.75rem;height:.75rem;min-width:.75rem;border:.0625rem solid var(--spot-radio-border);border-radius:var(--spot-radio-border-radius);margin-right:.5rem;position:relative;vertical-align:middle;top:-.0625rem;cursor:pointer;flex-shrink:0}input[type=radio]:checked{background:var(--spot-radio-checked-background);box-shadow:inset 0 0 0 .0625rem #fff}.spot-selection__options{display:flex;flex-direction:column;gap:.5rem}.spot-selection__option{display:flex;align-items:center;flex-wrap:nowrap;position:relative;transition:background .2s;cursor:pointer;font-size:var(--spot-radio-text-font-size);font-weight:var(--spot-radio-text-font-weight);color:var(--spot-radio-text-font-color);font-family:var(--spot-radio-text-font-family);padding:var(--spot-radio-text-padding);margin-right:.5rem}.spot-selection__option.selected{background:var(--spot-radio-selection-background);border-radius:var(--spot-radio-selection-border-radius);padding:var(--spot-radio-selection-padding)}.spot-selection__recommended-tag{background:var(--spot-recommended-tag-background);color:var(--spot-recommended-tag-font-color);font-size:var(--spot-recommended-tag-font-size);font-weight:var(--spot-recommended-tag-font-weight);padding:var(--spot-recommended-tag-padding);border-radius:var(--spot-recommended-tag-border-radius);margin-left:.75rem;white-space:nowrap;flex-shrink:0}@media (max-width: 850px){.spot-selection__recommended-tag{margin-left:.5rem}}@media (max-width: 600px){.spot-selection__recommended-tag{margin-left:.5rem;font-size:.75rem;padding:.1875rem .4375rem}}.spot-selection__error{color:var(--spot-selection-error-font-color);font-size:var(--spot-selection-error-font-size);padding:var(--spot-selection-error-padding);display:none}.spot-payment-terms__wrapper{margin-top:1rem}.spot-payment-terms__header{font-weight:var(--spot-payment-terms-header-font-weight);margin-bottom:.5rem;padding:var(--spot-payment-terms-header-padding);font-size:var(--spot-payment-terms-header-font-size);border-bottom:1px solid var(--spot-payment-terms-header-border-color)}.spot-payment-terms{background-color:var(--spot-payment-terms-background);border-radius:var(--spot-payment-terms-border-radius);padding:var(--spot-payment-terms-padding);margin-right:.5rem;color:var(--spot-payment-terms-font-color);font-size:var(--spot-payment-terms-font-size)}.spot-footer__terms{margin-top:.625rem;margin-right:.25rem;font-size:var(--spot-terms-font-size);font-weight:var(--spot-terms-font-weight);color:var(--spot-terms-font-color);font-family:var(--spot-terms-font-family);padding:var(--spot-terms-padding);line-height:1.4;word-wrap:normal;-webkit-hyphens:none;hyphens:none;flex:1;min-width:0;overflow-wrap:normal}.spot-footer__terms-link{text-decoration:var(--spot-terms-link-text-decoration);font-size:var(--spot-terms-link-font-size);font-weight:var(--spot-terms-link-font-weight);color:var(--spot-terms-link-font-color);font-family:var(--spot-terms-link-font-family);padding:var(--spot-terms-link-padding)}.spot-footer__container{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;flex-wrap:nowrap;gap:var(--spot-footer-gap)}@container (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}@media (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}.spot-footer__powered-by{margin-top:0;flex-shrink:0}.spot-logo__top-right{position:absolute;top:-14px;right:40px;z-index:10;background:#fff;padding:0 8px}@container (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}@media (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}";function Q(m){const t=document.createElement("style");t.textContent=m,document.head.appendChild(t)}Q(S);const I={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote",local:"http://localhost:3999/api/v1/quote"};class A{constructor(t={}){this.options={location:"body",showTable:!0,optInSelected:!1,logoPosition:"bottom-right",apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},useMockData:!1,...t},this._onResize=this._updateLayout.bind(this),this.root=typeof this.options.location=="string"?document.querySelector(this.options.location):this.options.location,this.currentSelection=this.options.optInSelected?"yes":null,this._init()}async _init(){var t,r,s,i,e;try{x(this.options);let n;if(this.options.useMockData&&this.options.mockData)n=this.options.mockData;else{const{environment:o,partnerId:a}=this.options.apiConfig,h=this.options.apiConfig.customEndpoint||I[o];n="cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?await k(h,a,this.options.quoteRequestData):await _(h,a,this.options.quoteRequestData)}if(n.status!=="QUOTE_AVAILABLE"){n.status==="NO_MATCHING_QUOTE"&&((t=this.options.callbacks)!=null&&t.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=n.data,!this.quote)throw new Error("No quote data in response");if(this._renderWidget(),this.options.optInSelected&&((r=this.options.callbacks)!=null&&r.onOptIn)){const o={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const a=this.options.quoteRequestData;o.batchQuoteDetails=this.quote.originalQuotes.map(u=>{var f;const h=(f=a.items)==null?void 0:f.find(y=>(y.cartItemId||`item-${a.items.indexOf(y)+1}`)===u.id);return{quoteId:u.id,productPrice:(h==null?void 0:h.productPrice)||u.spotPrice,cartItemId:u.id}})}this.options.callbacks.onOptIn(o)}if((s=this.options.callbacks)!=null&&s.onQuoteRetrieved){const o=this.options.callbacks.onQuoteRetrieved(this.quote);o&&this._applyQuoteUpdates(o)}}catch(n){if((i=this.options.callbacks)!=null&&i.onError){const o=n;(e=this.options.callbacks)==null||e.onError({message:o.message,status:o.status,responseBody:o.responseBody})}}}_renderWidget(){if(!this.quote)return;this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([s,i])=>{const e=`--${s}`;this.container.style.setProperty(e,i)}),N(this.container,this.quote.communication);const t=document.createElement("div");if(t.className="spot-content__wrapper",this.container.appendChild(t),this.quote.qualifyingReasons?L(t,this.quote.qualifyingReasons):M(t,this.quote.communication.bulletPoints),this.quote.coveredItems){const s=this._getTotalItemsInRequest();O(t,this.quote.coveredItems,s)}this.options.showTable&&!this.quote.qualifyingReasons&&P(t,this.quote.payoutSchedule);const r=$(t,this.options.optInSelected,this.quote.communication);t.appendChild(r),this.paymentTermsEl=p("div",{className:"spot-payment-terms__wrapper",parent:t}),V(this.container,this.quote,this.options.logoPosition),window.addEventListener("resize",this._onResize),this._setupResizeObserver(),this._updateLayout(),this._setupOptionListeners(r)}_updateLayout(){if(!this.container||!this.quote)return;const t=this.container.querySelector(".spot-content__wrapper"),r=this.options.showTable&&!this.quote.qualifyingReasons;if(!t||!r){t==null||t.classList.remove("desktop-layout");return}const s=this._shouldUseDesktopLayout(t);t.classList.toggle("desktop-layout",s)}_shouldUseDesktopLayout(t){const r=this.container.offsetWidth-40,s=325,i=16;if(r>=900)return!0;if(r>=650){const e=t.classList.contains("desktop-layout");t.classList.remove("desktop-layout"),t.offsetHeight;const n=t.querySelector(".spot-benefits__list, .spot-qualifying-reasons__container");if(!n)return e&&t.classList.add("desktop-layout"),e;const a=Math.min(n.scrollWidth,400)+s+i;return e&&t.classList.add("desktop-layout"),r>=a}return!1}_setupResizeObserver(){!this.container||!window.ResizeObserver||(this._resizeObserver=new ResizeObserver(()=>{this._resizeTimeout&&clearTimeout(this._resizeTimeout),this._resizeTimeout=window.setTimeout(()=>{this._updateLayout()},100)}),this._resizeObserver.observe(this.container))}_getTotalItemsInRequest(){return"cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?this.options.quoteRequestData.items.length:1}_applyQuoteUpdates(t){!this.quote||!this.container||(t.spotPriceWithFees!==void 0&&(this.quote.communication.yesOptionText=this.quote.communication.yesOptionText.replace(`$${this.quote.spotPrice.toFixed(2)}`,`$${t.spotPriceWithFees.toFixed(2)}`)),this.destroy(),this._renderWidget())}_setupOptionListeners(t){const r=t.querySelectorAll('input[type="radio"]'),s=t.querySelectorAll(".spot-selection__option");r.forEach(i=>{i.addEventListener("change",e=>{var a,u,h;const n=e.target,o=n.value;if(this.hideSelectionError(),this.currentSelection=o,s.forEach(f=>f.classList.remove("selected")),(a=n.closest(".spot-selection__option"))==null||a.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),o==="yes"&&(this.options.quoteRequestData.isPartialPayment&&R(this.paymentTermsEl,this.quote),(u=this.options.callbacks)!=null&&u.onOptIn)){const f={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;f.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var l;const d=(l=y.items)==null?void 0:l.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptIn(f)}if(o==="no"&&((h=this.options.callbacks)!=null&&h.onOptOut)){const f={status:"QUOTE_DECLINED",quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;f.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var l;const d=(l=y.items)==null?void 0:l.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptOut(f)}})})}showSelectionError(){var t;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const r=(t=this.container)==null?void 0:t.querySelector(".spot-selection__options");r&&r.insertAdjacentElement("afterend",this.errorEl)}this.errorEl.style.display="block"}hideSelectionError(){this.errorEl&&(this.errorEl.style.display="none")}validateSelection(){if(!this.container)return!1;const t=!!this.container.querySelector('input[name="selection"]:checked');return t?this.hideSelectionError():this.showSelectionError(),t}async updateQuote(t){var r,s,i,e;try{const n={...this.options,quoteRequestData:t};x(n);const{environment:o,partnerId:a,customEndpoint:u}=this.options.apiConfig,h=u||I[o],y="cartInfo"in n.quoteRequestData&&"items"in n.quoteRequestData?await k(h,a,n.quoteRequestData):await _(h,a,n.quoteRequestData);if(y.status!=="QUOTE_AVAILABLE")return y.status==="NO_MATCHING_QUOTE"&&((r=this.options.callbacks)!=null&&r.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:n.quoteRequestData}),!1;if(this.options.quoteRequestData=n.quoteRequestData,this.quote=y.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(s=this.options.callbacks)!=null&&s.onQuoteRetrieved){const c=this.options.callbacks.onQuoteRetrieved(this.quote);c&&this._applyQuoteUpdates(c)}return!0}catch(n){const o=n;return(e=(i=this.options.callbacks)==null?void 0:i.onError)==null||e.call(i,{message:o.message,status:o.status,responseBody:o.responseBody}),!1}}getSelection(){var r,s,i;if(this.currentSelection==null)return null;const t={selection:this.currentSelection,quoteId:(r=this.quote)==null?void 0:r.id,spotPrice:(s=this.quote)==null?void 0:s.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};if((i=this.quote)!=null&&i.originalQuotes&&this.quote.originalQuotes.length>0){const e=this.options.quoteRequestData;t.batchQuoteDetails=this.quote.originalQuotes.map(n=>{var a;const o=(a=e.items)==null?void 0:a.find(u=>(u.cartItemId||`item-${e.items.indexOf(u)+1}`)===n.id);return{quoteId:n.id,productPrice:(o==null?void 0:o.productPrice)||n.spotPrice,cartItemId:n.id}})}return t}destroy(){window.removeEventListener("resize",this._onResize),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeTimeout&&window.clearTimeout(this._resizeTimeout),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return A});
package/dist/ui.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare function makeEl<K extends keyof HTMLElementTagNameMap>(tag: K, {
3
3
  export declare function renderHeader(container: HTMLElement, { name, description }: Pick<Communication, "name" | "description">): void;
4
4
  export declare function renderBenefits(container: HTMLElement, bullets?: string[]): void;
5
5
  export declare function renderQualifyingReasons(container: HTMLElement, qualifyingReasons?: QualifyingReason[]): void;
6
- export declare function renderCoveredItems(container: HTMLElement, coveredItems?: string[]): void;
6
+ export declare function renderCoveredItems(container: HTMLElement, coveredItems?: string[], totalItemsInRequest?: number): void;
7
7
  export declare function renderTable(container: HTMLElement, schedule?: PayoutScheduleItem[]): void;
8
8
  export declare function renderOptions(container: HTMLElement, optInSelected: boolean, communication: Communication): HTMLElement;
9
9
  export declare function renderPaymentTerms(container: HTMLElement, quote: Quote): HTMLElement;
package/dist/ui.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC1D,GAAG,EAAE,CAAC,EACN,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAE,cAAmB,GACxE,qBAAqB,CAAC,CAAC,CAAC,CAS1B;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,GACjE,IAAI,CAWN;AAGD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,MAAM,EAAO,GACrB,IAAI,CAcN;AAGD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,WAAW,EACtB,iBAAiB,GAAE,gBAAgB,EAAO,GACzC,IAAI,CAwEN;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,YAAY,GAAE,MAAM,EAAO,GAC1B,IAAI,CAoBN;AAGD,wBAAgB,WAAW,CACzB,SAAS,EAAE,WAAW,EACtB,QAAQ,GAAE,kBAAkB,EAAO,GAClC,IAAI,CAyBN;AAGD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,WAAW,EACtB,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,aAAa,GAC3B,WAAW,CAyCb;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,KAAK,GACX,WAAW,CAqBb;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,KAAK,EACZ,YAAY,GAAE,cAAc,GAAG,WAA4B,GAC1D,WAAW,CAwEb"}
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC1D,GAAG,EAAE,CAAC,EACN,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAE,cAAmB,GACxE,qBAAqB,CAAC,CAAC,CAAC,CAS1B;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,GACjE,IAAI,CAWN;AAGD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,MAAM,EAAO,GACrB,IAAI,CAcN;AAGD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,WAAW,EACtB,iBAAiB,GAAE,gBAAgB,EAAO,GACzC,IAAI,CA0EN;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,YAAY,GAAE,MAAM,EAAO,EAC3B,mBAAmB,CAAC,EAAE,MAAM,GAC3B,IAAI,CA+GN;AAGD,wBAAgB,WAAW,CACzB,SAAS,EAAE,WAAW,EACtB,QAAQ,GAAE,kBAAkB,EAAO,GAClC,IAAI,CAyBN;AAGD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,WAAW,EACtB,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,aAAa,GAC3B,WAAW,CAyCb;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,KAAK,GACX,WAAW,CAqBb;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,KAAK,EACZ,YAAY,GAAE,cAAc,GAAG,WAA4B,GAC1D,WAAW,CAwEb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -12,6 +12,16 @@
12
12
  "README.md",
13
13
  "CHANGELOG.md"
14
14
  ],
15
+ "scripts": {
16
+ "build": "vite build && npx -p typescript tsc --emitDeclarationOnly",
17
+ "docs": "node generate-docs.js",
18
+ "docs:readme": "npm run docs && node scripts/generate-readme.js",
19
+ "test": "jest --watchAll=false",
20
+ "test:watch": "jest --watch",
21
+ "test:coverage": "jest --coverage",
22
+ "test:ci": "jest --ci --coverage --watchAll=false",
23
+ "prepublishOnly": "npm run build"
24
+ },
15
25
  "devDependencies": {
16
26
  "vite": "^5.0.0",
17
27
  "typescript": "~5.4.0",
@@ -21,14 +31,5 @@
21
31
  "@types/jest": "^29.0.0",
22
32
  "jest-environment-jsdom": "^29.0.0",
23
33
  "ts-jest": "^29.0.0"
24
- },
25
- "scripts": {
26
- "build": "vite build && npx -p typescript tsc --emitDeclarationOnly",
27
- "docs": "node generate-docs.js",
28
- "docs:readme": "npm run docs && node scripts/generate-readme.js",
29
- "test": "jest",
30
- "test:watch": "jest --watch",
31
- "test:coverage": "jest --coverage",
32
- "test:ci": "jest --ci --coverage --watchAll=false"
33
34
  }
34
- }
35
+ }