@getspot/spot-widget 1.2.0 → 1.4.0

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(w,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(w=typeof globalThis<"u"?globalThis:w||self,w.SpotWidget=v())})(this,function(){"use strict";async function w(p,e,o){try{const n=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":e},body:JSON.stringify(o)}),t=await n.json();if(!n.ok){const r=new Error((t==null?void 0:t.message)||"Failed to fetch quote");throw r.status=n.status,r.responseBody=t,r}return t}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching quote")}}async function v(p,e,o){try{const n=p.replace("/quote","/quote/batch"),t=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":e},body:JSON.stringify(o)}),r=await t.json();if(!t.ok){const c=new Error((r==null?void 0:r.message)||"Failed to fetch batch quote");throw c.status=t.status,c.responseBody=r,c}return r}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching batch quote")}}async function I(p,e,o){try{const n={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}))},t=await v(p,e,n);if(t.status!=="QUOTES_AVAILABLE"&&t.status!=="QUOTE_AVAILABLE")return{status:"NO_MATCHING_QUOTE"};const r=t.quotes.map(a=>{const u=o.items.find(h=>(h.cartItemId||`item-${o.items.indexOf(h)+1}`)===a.cartItemId);return u?u.participantDescription?`${u.productName} - ${u.participantDescription}`:u.productName:`Item ${a.cartItemId}`}),c=Math.round((t.totalSpotPrice||t.spotPrice||0)*100)/100;return{status:"QUOTE_AVAILABLE",data:{id:t.quotes?t.quotes.map(a=>a.id).join(","):t.id,spotPrice:c,currencyCode:t.currencyCode,communication:{...t.communication,yesOptionText:t.communication.yesOptionText.replace(t.totalSpotPrice,c)},payoutSchedule:t.payoutSchedule.map(a=>({...a,amount:a.amount!==void 0?a.amount:0})),coveredItems:r,originalQuotes:t.quotes||[t]},spotPrice:c,coveredItems:r}}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching multiple quotes")}}const N={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote",local:"http://localhost:3999/api/v1/quote"};function k(p){const{apiConfig:e={},quoteRequestData:o,callbacks:n={},location:t,theme:r}=p,{environment:c="sandbox",partnerId:a,endpoint:u}=e;if(!a||typeof a!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(u||N[c]))throw new Error(`Invalid environment in apiConfig: ${c}`);if(!o||typeof o!="object"&&!Array.isArray(o))throw new Error("quoteRequestData must be a non-null object or array");const m=["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"];function d(s,y=null){const f=y!==null?`quoteRequestData[${y}]`:"quoteRequestData";m.forEach(b=>{if(!Object.prototype.hasOwnProperty.call(s,b)||s[b]===void 0||s[b]===null)throw new Error(`Missing required ${f} field: '${b}'`)});const C=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!C.test(s.startDate))throw new Error(`${f}.startDate must be a valid ISO8601 string`);if(!C.test(s.endDate))throw new Error(`${f}.endDate must be a valid ISO8601 string`);if(typeof s.currencyCode!="string")throw new Error(`${f}.currencyCode must be a string`);if(!["USD","CAD","AUD"].includes(s.currencyCode))throw new Error(`Invalid ${f}.currencyCode: ${s.currencyCode}`);if(typeof s.eventType!="string")throw new Error(`${f}.eventType must be a string`);if(typeof s.productType!="string")throw new Error(`${f}.productType must be a string`);const _=["Pass","Trip","Registration"];if(!_.includes(s.productType))throw new Error(`${f}.productType must be one of ${_.join(", ")}`);if(typeof s.productDuration!="string")throw new Error(`${f}.productDuration must be a string`);const g=["Daily","Seasonal","Trip","Event"];if(!g.includes(s.productDuration))throw new Error(`${f}.productDuration must be one of ${g.join(", ")}`);if(typeof s.productPrice!="number"||isNaN(s.productPrice))throw new Error(`${f}.productPrice must be a valid number`);if(typeof s.productId!="string")throw new Error(`${f}.productId must be a string`);if(typeof s.cartId!="string")throw new Error(`${f}.cartId must be a string`);if(typeof s.productName!="string")throw new Error(`${f}.productName must be a string`)}if(o.cartInfo&&o.items){const{cartInfo:s,items:y}=o;if(!s||typeof s!="object")throw new Error("quoteRequestData.cartInfo must be a non-null object");if(!s.cartId||typeof s.cartId!="string")throw new Error("quoteRequestData.cartInfo.cartId must be a string");if(!s.cartName||typeof s.cartName!="string")throw new Error("quoteRequestData.cartInfo.cartName must be a string");if(!s.currencyCode||typeof s.currencyCode!="string")throw new Error("quoteRequestData.cartInfo.currencyCode must be a string");if(!["USD","CAD","AUD"].includes(s.currencyCode))throw new Error(`Invalid quoteRequestData.cartInfo.currencyCode: ${s.currencyCode}`);if(!Array.isArray(y)||y.length===0)throw new Error("quoteRequestData.items must be a non-empty array");const C=m.filter(l=>l!=="cartId"&&l!=="currencyCode");y.forEach((l,_)=>{if(!l||typeof l!="object")throw new Error(`quoteRequestData.items[${_}] must be a non-null object`);const g=`quoteRequestData.items[${_}]`;C.forEach(E=>{if(!Object.prototype.hasOwnProperty.call(l,E)||l[E]===void 0||l[E]===null)throw new Error(`Missing required ${g} field: '${E}'`)});const b=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!b.test(l.startDate))throw new Error(`${g}.startDate must be a valid ISO8601 string`);if(!b.test(l.endDate))throw new Error(`${g}.endDate must be a valid ISO8601 string`);if(typeof l.eventType!="string")throw new Error(`${g}.eventType must be a string`);if(typeof l.productType!="string")throw new Error(`${g}.productType must be a string`);const T=["Pass","Trip","Registration"];if(!T.includes(l.productType))throw new Error(`${g}.productType must be one of ${T.join(", ")}`);if(typeof l.productDuration!="string")throw new Error(`${g}.productDuration must be a string`);const x=["Daily","Seasonal","Trip","Event"];if(!x.includes(l.productDuration))throw new Error(`${g}.productDuration must be one of ${x.join(", ")}`);if(typeof l.productPrice!="number"||isNaN(l.productPrice))throw new Error(`${g}.productPrice must be a valid number`);if(typeof l.productId!="string")throw new Error(`${g}.productId must be a string`);if(typeof l.productName!="string")throw new Error(`${g}.productName must be a string`)})}else if(Array.isArray(o)){if(o.length===0)throw new Error("quoteRequestData array cannot be empty");o.forEach((s,y)=>{if(!s||typeof s!="object")throw new Error(`quoteRequestData[${y}] must be a non-null object`);d(s,y)})}else d(o);if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(s=>{const y=n[s];if(y&&typeof y!="function")throw new Error(`Callback '${s}' must be a function.`)}),typeof t=="string"&&!document.querySelector(t))throw new Error(`Invalid location selector: '${t}'`);if(r&&typeof r!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function i(p,{text:e,className:o,parent:n,innerHTML:t}={}){const r=document.createElement(p);return o&&(r.className=o),e!=null&&(r.textContent=e),t!=null&&(r.innerHTML=t),n&&n.appendChild(r),r}function O(p,{name:e,description:o}){i("div",{className:"spot-header__title",text:e,parent:p}),i("div",{className:"spot-header__description",text:o,parent:p})}function P(p,e=[]){const o=i("ul",{className:"spot-benefits__list",parent:p});e.forEach(n=>{const t=i("li",{parent:o});t.innerHTML=`
1
+ (function(w,q){typeof exports=="object"&&typeof module<"u"?module.exports=q():typeof define=="function"&&define.amd?define(q):(w=typeof globalThis<"u"?globalThis:w||self,w.SpotWidget=q())})(this,function(){"use strict";var w=typeof document<"u"?document.currentScript:null;async function q(c,t,e){try{const n=await fetch(c,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(e)}),o=await n.json();if(!n.ok){const r=new Error((o==null?void 0:o.message)||"Failed to fetch quote");throw r.status=n.status,r.responseBody=o,r}return o}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching quote")}}async function N(c,t,e){try{const n=c.replace("/quote","/quote/batch"),o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(e)}),r=await o.json();if(!o.ok){const p=new Error((r==null?void 0:r.message)||"Failed to fetch batch quote");throw p.status=o.status,p.responseBody=r,p}return r}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching batch quote")}}async function I(c,t,e){try{const n={cartId:e.cartInfo.cartId,cartName:e.cartInfo.cartName,currencyCode:e.cartInfo.currencyCode,items:e.items.map((a,d)=>({cartItemId:a.cartItemId||`item-${d+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}))},o=await N(c,t,n);if(o.status!=="QUOTES_AVAILABLE"&&o.status!=="QUOTE_AVAILABLE")return{status:"NO_MATCHING_QUOTE"};const r=o.quotes.map(a=>{const d=e.items.find(h=>(h.cartItemId||`item-${e.items.indexOf(h)+1}`)===a.cartItemId);return d?d.participantDescription?`${d.productName} - ${d.participantDescription}`:d.productName:`Item ${a.cartItemId}`}),p=Math.round((o.totalSpotPrice||o.spotPrice||0)*100)/100;return{status:"QUOTE_AVAILABLE",data:{id:o.quotes?o.quotes.map(a=>a.id).join(","):o.id,spotPrice:p,currencyCode:o.currencyCode,communication:{...o.communication,yesOptionText:o.communication.yesOptionText.replace(o.totalSpotPrice,p)},payoutSchedule:o.payoutSchedule.map(a=>({...a,amount:a.amount!==void 0?a.amount:0})),coveredItems:r,originalQuotes:o.quotes||[o]},spotPrice:p,coveredItems:r}}catch(n){throw n instanceof Error?n:new Error("Unknown error occurred while fetching multiple quotes")}}const R={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote",local:"http://localhost:3999/api/v1/quote"};function D(c){const{apiConfig:t={},quoteRequestData:e,callbacks:n={},location:o,theme:r}=c,{environment:p="sandbox",partnerId:a,endpoint:d}=t;if(!a||typeof a!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(d||R[p]))throw new Error(`Invalid environment in apiConfig: ${p}`);if(!e||typeof e!="object"&&!Array.isArray(e))throw new Error("quoteRequestData must be a non-null object or array");const g=["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"];function l(s,u=null){const m=u!==null?`quoteRequestData[${u}]`:"quoteRequestData";g.forEach(_=>{if(!Object.prototype.hasOwnProperty.call(s,_)||s[_]===void 0||s[_]===null)throw new Error(`Missing required ${m} field: '${_}'`)});const v=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!v.test(s.startDate))throw new Error(`${m}.startDate must be a valid ISO8601 string`);if(!v.test(s.endDate))throw new Error(`${m}.endDate must be a valid ISO8601 string`);if(typeof s.currencyCode!="string")throw new Error(`${m}.currencyCode must be a string`);if(!["USD","CAD","AUD"].includes(s.currencyCode))throw new Error(`Invalid ${m}.currencyCode: ${s.currencyCode}`);if(typeof s.eventType!="string")throw new Error(`${m}.eventType must be a string`);if(typeof s.productType!="string")throw new Error(`${m}.productType must be a string`);const C=["Pass","Trip","Registration"];if(!C.includes(s.productType))throw new Error(`${m}.productType must be one of ${C.join(", ")}`);if(typeof s.productDuration!="string")throw new Error(`${m}.productDuration must be a string`);const b=["Daily","Seasonal","Trip","Event"];if(!b.includes(s.productDuration))throw new Error(`${m}.productDuration must be one of ${b.join(", ")}`);if(typeof s.productPrice!="number"||isNaN(s.productPrice))throw new Error(`${m}.productPrice must be a valid number`);if(typeof s.productId!="string")throw new Error(`${m}.productId must be a string`);if(typeof s.cartId!="string")throw new Error(`${m}.cartId must be a string`);if(typeof s.productName!="string")throw new Error(`${m}.productName must be a string`)}if(e.cartInfo&&e.items){const{cartInfo:s,items:u}=e;if(!s||typeof s!="object")throw new Error("quoteRequestData.cartInfo must be a non-null object");if(!s.cartId||typeof s.cartId!="string")throw new Error("quoteRequestData.cartInfo.cartId must be a string");if(!s.cartName||typeof s.cartName!="string")throw new Error("quoteRequestData.cartInfo.cartName must be a string");if(!s.currencyCode||typeof s.currencyCode!="string")throw new Error("quoteRequestData.cartInfo.currencyCode must be a string");if(!["USD","CAD","AUD"].includes(s.currencyCode))throw new Error(`Invalid quoteRequestData.cartInfo.currencyCode: ${s.currencyCode}`);if(!Array.isArray(u)||u.length===0)throw new Error("quoteRequestData.items must be a non-empty array");const v=g.filter(f=>f!=="cartId"&&f!=="currencyCode");u.forEach((f,C)=>{if(!f||typeof f!="object")throw new Error(`quoteRequestData.items[${C}] must be a non-null object`);const b=`quoteRequestData.items[${C}]`;v.forEach(E=>{if(!Object.prototype.hasOwnProperty.call(f,E)||f[E]===void 0||f[E]===null)throw new Error(`Missing required ${b} field: '${E}'`)});const _=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!_.test(f.startDate))throw new Error(`${b}.startDate must be a valid ISO8601 string`);if(!_.test(f.endDate))throw new Error(`${b}.endDate must be a valid ISO8601 string`);if(typeof f.eventType!="string")throw new Error(`${b}.eventType must be a string`);if(typeof f.productType!="string")throw new Error(`${b}.productType must be a string`);const x=["Pass","Trip","Registration"];if(!x.includes(f.productType))throw new Error(`${b}.productType must be one of ${x.join(", ")}`);if(typeof f.productDuration!="string")throw new Error(`${b}.productDuration must be a string`);const T=["Daily","Seasonal","Trip","Event"];if(!T.includes(f.productDuration))throw new Error(`${b}.productDuration must be one of ${T.join(", ")}`);if(typeof f.productPrice!="number"||isNaN(f.productPrice))throw new Error(`${b}.productPrice must be a valid number`);if(typeof f.productId!="string")throw new Error(`${b}.productId must be a string`);if(typeof f.productName!="string")throw new Error(`${b}.productName must be a string`)})}else if(Array.isArray(e)){if(e.length===0)throw new Error("quoteRequestData array cannot be empty");e.forEach((s,u)=>{if(!s||typeof s!="object")throw new Error(`quoteRequestData[${u}] must be a non-null object`);l(s,u)})}else l(e);if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(s=>{const u=n[s];if(u&&typeof u!="function")throw new Error(`Callback '${s}' must be a function.`)}),typeof o=="string"&&!document.querySelector(o))throw new Error(`Invalid location selector: '${o}'`);if(r&&typeof r!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function i(c,{text:t,className:e,parent:n,innerHTML:o}={}){const r=document.createElement(c);return e&&(r.className=e),t!=null&&(r.textContent=t),o!=null&&(r.innerHTML=o),n&&n.appendChild(r),r}function O(c,{name:t,description:e}){i("div",{className:"spot-header__title",text:t,parent:c}),i("div",{className:"spot-header__description",text:e,parent:c})}function P(c,t=[]){const e=i("ul",{className:"spot-benefits__list",parent:c});t.forEach(n=>{const o=i("li",{parent:e});o.innerHTML=`
2
2
  <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
3
3
  <path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
4
4
  stroke="#2E2E2E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
5
- </svg>`,i("span",{text:n,parent:t})})}function $(p,e=[]){if(e.length===0)return;const o=i("div",{className:"spot-covered-items__container",parent:p});i("div",{className:"spot-covered-items__title",text:"Items covered in your cart:",parent:o});const n=i("ul",{className:"spot-covered-items__list",parent:o});e.forEach(t=>{const r=i("li",{parent:n});i("span",{text:t,parent:r})})}function Q(p,e=[]){const o=i("div",{className:"spot-table__container",parent:p}),n=i("table",{className:"spot-refund__table spot-table--dynamic",parent:o}),t=i("thead",{parent:n}),r=i("tr",{parent:t});i("th",{text:"When you cancel",parent:r}),i("th",{text:"You will receive",parent:r});const c=i("tbody",{parent:n});e.forEach(({text:a,percent:u,amount:h})=>{const m=i("tr",{parent:c});i("td",{text:a,parent:m});const d=u==="Not eligible for refund"?"Not eligible for a refund":`$${h} refund`;i("td",{text:d,parent:m})})}function S(p,e,o){const n=i("div",{className:"spot-selection__options",parent:p}),t=i("label",{className:`spot-selection__option ${e?"selected":""}`,parent:n}),r=i("input",{parent:t});r.type="radio",r.name="selection",r.value="yes",e&&(r.checked=!0),i("strong",{text:o.yesOptionText,parent:t}),i("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:t});const c=i("label",{className:"spot-selection__option",parent:n}),a=i("input",{parent:c});return a.type="radio",a.name="selection",a.value="no",i("span",{text:o.noOptionText,parent:c}),n}function H(p,e){var t;const o=(t=e.communication)==null?void 0:t.paymentTerms,n=i("div",{className:"spot-payment-terms",parent:p});return i("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:n}),i("div",{className:"spot-payment-terms__body",text:o,parent:n}),n}function z(p,e){const o=i("div",{className:"spot-footer__container",parent:p}),n=i("div",{className:"spot-footer__terms",parent:o});i("span",{innerHTML:e.communication.legalDisclaimer,parent:n}),i("br",{parent:n}),i("a",{href:e.communication.termsAndConditionsUrl,className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:n});const t=i("p",{className:"spot-footer__powered-by",parent:o});return t.innerHTML=`
5
+ </svg>`,i("span",{text:n,parent:o})})}function $(c,t=[]){if(!t||t.length===0)return;const e=i("div",{className:"spot-qualifying-reasons__container",parent:c}),n=[...t].sort((d,h)=>d.rank-h.rank),o=i("div",{className:"spot-qualifying-reasons__grid",parent:e}),r={"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"},p=new URL(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.umd.js",document.baseURI).href),a=p.origin+p.pathname.replace(/\/src\/[^/]*$/,"/assets/");n.forEach(d=>{var y,s,u;const h=i("div",{className:"spot-qualifying-reasons__item",parent:o}),g=i("div",{className:"spot-qualifying-reasons__icon-wrapper",parent:h}),l=r[(y=d.benefitType)==null?void 0:y.name]||r[d.name];if(l){const m=i("img",{parent:g});m.src=a+l,m.alt=((s=d.benefitType)==null?void 0:s.name)||d.name||"",m.className="spot-qualifying-reasons__icon"}i("span",{className:"spot-qualifying-reasons__label",text:((u=d.benefitType)==null?void 0:u.name)||d.name||"",parent:h})})}function z(c,t=[]){if(t.length===0)return;const e=i("div",{className:"spot-covered-items__container",parent:c});i("div",{className:"spot-covered-items__title",text:"Items covered in your cart:",parent:e});const n=i("ul",{className:"spot-covered-items__list",parent:e});t.forEach(o=>{const r=i("li",{parent:n});i("span",{text:o,parent:r})})}function S(c,t=[]){const e=i("div",{className:"spot-table__container",parent:c}),n=i("table",{className:"spot-refund__table spot-table--dynamic",parent:e}),o=i("thead",{parent:n}),r=i("tr",{parent:o});i("th",{text:"When you cancel",parent:r}),i("th",{text:"You will receive",parent:r});const p=i("tbody",{parent:n});t.forEach(({text:a,percent:d,amount:h})=>{const g=i("tr",{parent:p});i("td",{text:a,parent:g});const l=d==="Not eligible for refund"?"Not eligible for a refund":`$${h} refund`;i("td",{text:l,parent:g})})}function Q(c,t,e){const n=i("div",{className:"spot-selection__options",parent:c}),o=i("label",{className:`spot-selection__option ${t?"selected":""}`,parent:n}),r=i("input",{parent:o});r.type="radio",r.name="selection",r.value="yes",t&&(r.checked=!0),i("strong",{text:e.yesOptionText,parent:o}),i("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:o});const p=i("label",{className:"spot-selection__option",parent:n}),a=i("input",{parent:p});return a.type="radio",a.name="selection",a.value="no",i("span",{text:e.noOptionText,parent:p}),n}function H(c,t){var o;const e=(o=t.communication)==null?void 0:o.paymentTerms,n=i("div",{className:"spot-payment-terms",parent:c});return i("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:n}),i("div",{className:"spot-payment-terms__body",text:e,parent:n}),n}function M(c,t){const e=i("div",{className:"spot-footer__container",parent:c}),n=i("div",{className:"spot-footer__terms",parent:e});i("span",{innerHTML:t.communication.legalDisclaimer,parent:n}),i("br",{parent:n}),i("a",{href:t.communication.termsAndConditionsUrl,className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:n});const o=i("p",{className:"spot-footer__powered-by",parent:e});return o.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,4 +17,4 @@
17
17
  <rect width="45.405" height="14.8867" fill="white" transform="translate(87 8)"/>
18
18
  </clipPath>
19
19
  </defs>
20
- </svg>`,o}const M=":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-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-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}.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}@media (min-width: 48rem){.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr 20.3125rem;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list{grid-row:1}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1}.desktop-layout .spot-selection__options{grid-row:3}.desktop-layout .spot-table__container{grid-row:1 / span 3}}@media (max-width: 52.438rem){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 47.938rem){.spot-selection__recommended-tag{margin-top:0rem}}@media (max-width: 32.125rem){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 47.9375rem){.spot-table__container{display:flex;justify-content:center}.spot-selection__recommended-tag{display:inline-block;margin-left:0}.spot-footer__container{flex-direction:column;margin-top:.5rem}.spot-refund__table{width:100%;table-layout:auto}.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:.5rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.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:1.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;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}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:block;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;gap:.5rem;flex:1 0 0;align-self:stretch}.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:1.5rem;white-space:nowrap}.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)}.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;justify-content:space-between;align-items:center}.spot-footer__powered-by{margin-top:1.5rem}";function R(p){const e=document.createElement("style");e.textContent=p,document.head.appendChild(e)}R(M);const D={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 L{constructor(e={}){this.options={location:"body",showTable:!0,optInSelected:!1,apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},...e},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 e,o,n,t,r;try{k(this.options);const{environment:c,partnerId:a}=this.options.apiConfig,h=this.options.apiConfig.customEndpoint||D[c],d=this.options.quoteRequestData.cartInfo&&this.options.quoteRequestData.items?await I(h,a,this.options.quoteRequestData):await w(h,a,this.options.quoteRequestData);if(d.status!=="QUOTE_AVAILABLE"){d.status==="NO_MATCHING_QUOTE"&&((e=this.options.callbacks)!=null&&e.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=d.data,this._renderWidget(),this.options.optInSelected&&((o=this.options.callbacks)!=null&&o.onOptIn)){const q={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(q.batchQuoteDetails=this.quote.originalQuotes.map(s=>({quoteId:s.id,productPrice:s.spotPrice,cartItemId:s.cartItemId}))),this.options.callbacks.onOptIn(q)}(n=this.options.callbacks)!=null&&n.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote)}catch(c){(t=this.options.callbacks)!=null&&t.onError&&((r=this.options.callbacks)==null||r.onError({message:c.message,status:c.status,responseBody:c.responseBody}))}}_renderWidget(){this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([n,t])=>{const r=`--${n}`;this.container.style.setProperty(r,t)}),O(this.container,this.quote.communication);const e=document.createElement("div");e.className="spot-content__wrapper",this.container.appendChild(e),P(e,this.quote.communication.bulletPoints),this.quote.coveredItems&&$(e,this.quote.coveredItems),this.options.showTable&&Q(e,this.quote.payoutSchedule);const o=S(e,this.options.optInSelected,this.quote.communication);e.appendChild(o),this.paymentTermsEl=i("div",{className:"spot-payment-terms__wrapper",parent:e}),z(this.container,this.quote),window.addEventListener("resize",this._onResize),this._updateLayout(),this._setupOptionListeners(o)}_updateLayout(){const e=window.matchMedia("(min-width: 768px)").matches;this.container.querySelector(".spot-content__wrapper").classList.toggle("desktop-layout",e&&this.options.showTable)}_setupOptionListeners(e){const o=e.querySelectorAll('input[type="radio"]'),n=e.querySelectorAll(".spot-selection__option");o.forEach(t=>{t.addEventListener("change",r=>{var a,u,h;const c=r.target.value;if(this.hideSelectionError(),this.currentSelection=c,n.forEach(m=>m.classList.remove("selected")),(a=r.target.closest(".spot-selection__option"))==null||a.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),c==="yes"&&(this.options.quoteRequestData.isPartialPayment&&H(this.paymentTermsEl,this.quote),(u=this.options.callbacks)!=null&&u.onOptIn)){const m={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(m.batchQuoteDetails=this.quote.originalQuotes.map(d=>({quoteId:d.id,productPrice:d.spotPrice,cartItemId:d.cartItemId}))),this.options.callbacks.onOptIn(m)}if(c==="no"&&((h=this.options.callbacks)!=null&&h.onOptOut)){const m={status:"QUOTE_DECLINED",quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(m.batchQuoteDetails=this.quote.originalQuotes.map(d=>({quoteId:d.id,productPrice:d.spotPrice,cartItemId:d.cartItemId}))),this.options.callbacks.onOptOut(m)}})})}showSelectionError(){var e;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const o=(e=this.container)==null?void 0:e.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 e=!!this.container.querySelector('input[name="selection"]:checked');return e?this.hideSelectionError():this.showSelectionError(),e}async updateQuote(e){var o,n,t;try{const r={...this.options,quoteRequestData:e};k(r);const{environment:c,partnerId:a,endpoint:u}=this.options.apiConfig,h=u||D[c],d=r.quoteRequestData.cartInfo&&r.quoteRequestData.items?await I(h,a,r.quoteRequestData):await w(h,a,r.quoteRequestData);return d.status!=="QUOTE_AVAILABLE"?(d.status==="NO_MATCHING_QUOTE"&&((o=this.options.callbacks)!=null&&o.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:r.quoteRequestData}),!1):(this.options.quoteRequestData=r.quoteRequestData,this.quote=d.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(n=this.options.callbacks)!=null&&n.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote),!0)}catch(r){return(t=this.options.callbacks)==null||t.onError({message:r.message,status:r.status,responseBody:r.responseBody}),!1}}getSelection(){var o,n,t;if(this.currentSelection==null)return null;const e={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"};return(t=this.quote)!=null&&t.originalQuotes&&this.quote.originalQuotes.length>0&&(e.batchQuoteDetails=this.quote.originalQuotes.map(r=>({quoteId:r.id,productPrice:r.spotPrice,cartItemId:r.cartItemId}))),e}destroy(){window.removeEventListener("resize",this._onResize),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return L});
20
+ </svg>`,e}const L=":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-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}.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}@media (min-width: 48rem){.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr 20.3125rem;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list{grid-row:1}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1}.desktop-layout .spot-selection__options{grid-row:3}.desktop-layout .spot-table__container{grid-row:1 / span 3}}@media (max-width: 52.438rem){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 47.938rem){.spot-selection__recommended-tag{margin-top:0rem}}@media (max-width: 32.125rem){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 47.9375rem){.spot-table__container{display:flex;justify-content:center}.spot-selection__recommended-tag{display:inline-block;margin-left:0}.spot-footer__container{flex-direction:column;margin-top:.5rem}.spot-refund__table{width:100%;table-layout:auto}.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:.5rem;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:1.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;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}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:block;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;gap:.5rem;flex:1 0 0;align-self:stretch}.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:1.5rem;white-space:nowrap}.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)}.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;justify-content:space-between;align-items:center}.spot-footer__powered-by{margin-top:1.5rem}";function A(c){const t=document.createElement("style");t.textContent=c,document.head.appendChild(t)}A(L);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 V{constructor(t={}){this.options={location:"body",showTable:!0,optInSelected:!1,apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},...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,e,n,o,r;try{D(this.options);const{environment:p,partnerId:a}=this.options.apiConfig,h=this.options.apiConfig.customEndpoint||k[p],l=this.options.quoteRequestData.cartInfo&&this.options.quoteRequestData.items?await I(h,a,this.options.quoteRequestData):await q(h,a,this.options.quoteRequestData);if(l.status!=="QUOTE_AVAILABLE"){l.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=l.data,this._renderWidget(),this.options.optInSelected&&((e=this.options.callbacks)!=null&&e.onOptIn)){const y={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(y.batchQuoteDetails=this.quote.originalQuotes.map(s=>{var m;const u=(m=this.options.quoteRequestData.items)==null?void 0:m.find(v=>(v.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(v)+1}`)===s.cartItemId);return{quoteId:s.id,productPrice:(u==null?void 0:u.productPrice)||s.spotPrice,cartItemId:s.cartItemId}})),this.options.callbacks.onOptIn(y)}(n=this.options.callbacks)!=null&&n.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote)}catch(p){(o=this.options.callbacks)!=null&&o.onError&&((r=this.options.callbacks)==null||r.onError({message:p.message,status:p.status,responseBody:p.responseBody}))}}_renderWidget(){this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([n,o])=>{const r=`--${n}`;this.container.style.setProperty(r,o)}),O(this.container,this.quote.communication);const t=document.createElement("div");t.className="spot-content__wrapper",this.container.appendChild(t),this.quote.qualifyingReasons?$(t,this.quote.qualifyingReasons):P(t,this.quote.communication.bulletPoints),this.quote.coveredItems&&z(t,this.quote.coveredItems),this.options.showTable&&!this.quote.qualifyingReasons&&S(t,this.quote.payoutSchedule);const e=Q(t,this.options.optInSelected,this.quote.communication);t.appendChild(e),this.paymentTermsEl=i("div",{className:"spot-payment-terms__wrapper",parent:t}),M(this.container,this.quote),window.addEventListener("resize",this._onResize),this._updateLayout(),this._setupOptionListeners(e)}_updateLayout(){const t=window.matchMedia("(min-width: 768px)").matches,e=this.options.showTable&&!this.quote.qualifyingReasons;this.container.querySelector(".spot-content__wrapper").classList.toggle("desktop-layout",t&&e)}_setupOptionListeners(t){const e=t.querySelectorAll('input[type="radio"]'),n=t.querySelectorAll(".spot-selection__option");e.forEach(o=>{o.addEventListener("change",r=>{var a,d,h;const p=r.target.value;if(this.hideSelectionError(),this.currentSelection=p,n.forEach(g=>g.classList.remove("selected")),(a=r.target.closest(".spot-selection__option"))==null||a.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),p==="yes"&&(this.options.quoteRequestData.isPartialPayment&&H(this.paymentTermsEl,this.quote),(d=this.options.callbacks)!=null&&d.onOptIn)){const g={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(g.batchQuoteDetails=this.quote.originalQuotes.map(l=>{var s;const y=(s=this.options.quoteRequestData.items)==null?void 0:s.find(u=>(u.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(u)+1}`)===l.cartItemId);return{quoteId:l.id,productPrice:(y==null?void 0:y.productPrice)||l.spotPrice,cartItemId:l.cartItemId}})),this.options.callbacks.onOptIn(g)}if(p==="no"&&((h=this.options.callbacks)!=null&&h.onOptOut)){const g={status:"QUOTE_DECLINED",quoteId:this.quote.id};this.quote.originalQuotes&&this.quote.originalQuotes.length>0&&(g.batchQuoteDetails=this.quote.originalQuotes.map(l=>{var s;const y=(s=this.options.quoteRequestData.items)==null?void 0:s.find(u=>(u.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(u)+1}`)===l.cartItemId);return{quoteId:l.id,productPrice:(y==null?void 0:y.productPrice)||l.spotPrice,cartItemId:l.cartItemId}})),this.options.callbacks.onOptOut(g)}})})}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 e=(t=this.container)==null?void 0:t.querySelector(".spot-selection__options");e&&e.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 e,n,o;try{const r={...this.options,quoteRequestData:t};D(r);const{environment:p,partnerId:a,endpoint:d}=this.options.apiConfig,h=d||k[p],l=r.quoteRequestData.cartInfo&&r.quoteRequestData.items?await I(h,a,r.quoteRequestData):await q(h,a,r.quoteRequestData);return l.status!=="QUOTE_AVAILABLE"?(l.status==="NO_MATCHING_QUOTE"&&((e=this.options.callbacks)!=null&&e.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:r.quoteRequestData}),!1):(this.options.quoteRequestData=r.quoteRequestData,this.quote=l.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(n=this.options.callbacks)!=null&&n.onQuoteRetrieved&&this.options.callbacks.onQuoteRetrieved(this.quote),!0)}catch(r){return(o=this.options.callbacks)==null||o.onError({message:r.message,status:r.status,responseBody:r.responseBody}),!1}}getSelection(){var e,n,o;if(this.currentSelection==null)return null;const t={selection:this.currentSelection,quoteId:(e=this.quote)==null?void 0:e.id,spotPrice:(n=this.quote)==null?void 0:n.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};return(o=this.quote)!=null&&o.originalQuotes&&this.quote.originalQuotes.length>0&&(t.batchQuoteDetails=this.quote.originalQuotes.map(r=>{var a;const p=(a=this.options.quoteRequestData.items)==null?void 0:a.find(d=>(d.cartItemId||`item-${this.options.quoteRequestData.items.indexOf(d)+1}`)===r.cartItemId);return{quoteId:r.id,productPrice:(p==null?void 0:p.productPrice)||r.spotPrice,cartItemId:r.cartItemId}})),t}destroy(){window.removeEventListener("resize",this._onResize),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return V});
package/dist/medal.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-medal-2"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 3h6l3 7l-6 2l-6 -2z" /><path d="M12 12l-3 -9" /><path d="M15 11l-3 -8" /><path d="M12 19.5l-3 1.5l.5 -3.5l-2 -2l3 -.5l1.5 -3l1.5 3l3 .5l-2 2l.5 3.5z" /></svg>
package/dist/plane.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plane-icon lucide-plane"><path d="M17.8 19.2 16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.5-.1 1 .3 1.3L9 12l-2 3H4l-1 1 3 2 2 3 1-1v-3l3-2 3.5 5.3c.3.4.8.5 1.3.3l.5-.2c.4-.3.6-.7.5-1.2z"/></svg>
package/dist/scale.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-scale-icon lucide-scale"><path d="m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z"/><path d="m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z"/><path d="M7 21h10"/><path d="M12 3v18"/><path d="M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-umbrella-icon lucide-umbrella"><path d="M22 12a10.06 10.06 1 0 0-20 0Z"/><path d="M12 12v8a2 2 0 0 0 4 0"/><path d="M12 2v1"/></svg>
package/dist/users.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-users-icon lucide-users"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><path d="M16 3.128a4 4 0 0 1 0 7.744"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><circle cx="9" cy="7" r="4"/></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/index.js CHANGED
@@ -3,6 +3,7 @@ import { validateOptions } from "./validateOptions.js";
3
3
  import {
4
4
  renderHeader,
5
5
  renderBenefits,
6
+ renderQualifyingReasons,
6
7
  renderCoveredItems,
7
8
  renderTable,
8
9
  renderOptions,
@@ -24,7 +25,7 @@ injectStyles(styles);
24
25
  const apiEndpoint = {
25
26
  sandbox: "https://api.sandbox.getspot.com/api/v1/quote",
26
27
  production: "https://api.getspot.com/api/v1/quote",
27
- local: "http://localhost:3999/api/v1/quote"
28
+ local: "http://localhost:3999/api/v1/quote",
28
29
  };
29
30
 
30
31
  class SpotWidget {
@@ -58,9 +59,15 @@ class SpotWidget {
58
59
 
59
60
  const endpoint = customEndpoint || apiEndpoint[environment];
60
61
 
61
- const isBatchQuote = this.options.quoteRequestData.cartInfo && this.options.quoteRequestData.items;
62
+ const isBatchQuote =
63
+ this.options.quoteRequestData.cartInfo &&
64
+ this.options.quoteRequestData.items;
62
65
  const response = isBatchQuote
63
- ? await fetchMultipleQuotes(endpoint, partnerId, this.options.quoteRequestData)
66
+ ? await fetchMultipleQuotes(
67
+ endpoint,
68
+ partnerId,
69
+ this.options.quoteRequestData
70
+ )
64
71
  : await fetchQuote(endpoint, partnerId, this.options.quoteRequestData);
65
72
 
66
73
  if (response.status !== "QUOTE_AVAILABLE") {
@@ -83,18 +90,27 @@ class SpotWidget {
83
90
  const optInData = {
84
91
  status: "QUOTE_ACCEPTED",
85
92
  spotPrice: this.quote.spotPrice,
86
- quoteId: this.quote.id
93
+ quoteId: this.quote.id,
87
94
  };
88
-
95
+
89
96
  // For batch quotes, include detailed quote information
90
97
  if (this.quote.originalQuotes && this.quote.originalQuotes.length > 0) {
91
- optInData.batchQuoteDetails = this.quote.originalQuotes.map(q => ({
92
- quoteId: q.id,
93
- productPrice: q.spotPrice,
94
- cartItemId: q.cartItemId
95
- }));
98
+ optInData.batchQuoteDetails = this.quote.originalQuotes.map((q) => {
99
+ const originalItem = this.options.quoteRequestData.items?.find(
100
+ (item) =>
101
+ (item.cartItemId ||
102
+ `item-${
103
+ this.options.quoteRequestData.items.indexOf(item) + 1
104
+ }`) === q.cartItemId
105
+ );
106
+ return {
107
+ quoteId: q.id,
108
+ productPrice: originalItem?.productPrice || q.spotPrice,
109
+ cartItemId: q.cartItemId,
110
+ };
111
+ });
96
112
  }
97
-
113
+
98
114
  this.options.callbacks.onOptIn(optInData);
99
115
  }
100
116
 
@@ -127,11 +143,21 @@ class SpotWidget {
127
143
  cw.className = "spot-content__wrapper";
128
144
  this.container.appendChild(cw);
129
145
 
130
- renderBenefits(cw, this.quote.communication.bulletPoints);
146
+ // Render qualifying reasons if they exist, otherwise render bullet points
147
+ if (this.quote.qualifyingReasons) {
148
+ renderQualifyingReasons(cw, this.quote.qualifyingReasons);
149
+ } else {
150
+ renderBenefits(cw, this.quote.communication.bulletPoints);
151
+ }
152
+
131
153
  if (this.quote.coveredItems) {
132
154
  renderCoveredItems(cw, this.quote.coveredItems);
133
155
  }
134
- if (this.options.showTable) renderTable(cw, this.quote.payoutSchedule);
156
+
157
+ // Only show table if showTable is true and qualifyingReasons don't exist (pass/trip offers don't have payout schedules)
158
+ if (this.options.showTable && !this.quote.qualifyingReasons) {
159
+ renderTable(cw, this.quote.payoutSchedule);
160
+ }
135
161
  const optsEl = renderOptions(
136
162
  cw,
137
163
  this.options.optInSelected,
@@ -151,9 +177,10 @@ class SpotWidget {
151
177
 
152
178
  _updateLayout() {
153
179
  const isDesktop = window.matchMedia("(min-width: 768px)").matches;
180
+ const hasTable = this.options.showTable && !this.quote.qualifyingReasons;
154
181
  this.container
155
182
  .querySelector(".spot-content__wrapper")
156
- .classList.toggle("desktop-layout", isDesktop && this.options.showTable);
183
+ .classList.toggle("desktop-layout", isDesktop && hasTable);
157
184
  }
158
185
 
159
186
  _setupOptionListeners(el) {
@@ -180,36 +207,66 @@ class SpotWidget {
180
207
  const optInData = {
181
208
  status: "QUOTE_ACCEPTED",
182
209
  spotPrice: this.quote.spotPrice,
183
- quoteId: this.quote.id
210
+ quoteId: this.quote.id,
184
211
  };
185
-
212
+
186
213
  // For batch quotes, include detailed quote information
187
- if (this.quote.originalQuotes && this.quote.originalQuotes.length > 0) {
188
- optInData.batchQuoteDetails = this.quote.originalQuotes.map(q => ({
189
- quoteId: q.id,
190
- productPrice: q.spotPrice,
191
- cartItemId: q.cartItemId
192
- }));
214
+ if (
215
+ this.quote.originalQuotes &&
216
+ this.quote.originalQuotes.length > 0
217
+ ) {
218
+ optInData.batchQuoteDetails = this.quote.originalQuotes.map(
219
+ (q) => {
220
+ const originalItem =
221
+ this.options.quoteRequestData.items?.find(
222
+ (item) =>
223
+ (item.cartItemId ||
224
+ `item-${
225
+ this.options.quoteRequestData.items.indexOf(item) +
226
+ 1
227
+ }`) === q.cartItemId
228
+ );
229
+ return {
230
+ quoteId: q.id,
231
+ productPrice: originalItem?.productPrice || q.spotPrice,
232
+ cartItemId: q.cartItemId,
233
+ };
234
+ }
235
+ );
193
236
  }
194
-
237
+
195
238
  this.options.callbacks.onOptIn(optInData);
196
239
  }
197
240
  }
198
241
  if (val === "no" && this.options.callbacks?.onOptOut) {
199
242
  const optOutData = {
200
243
  status: "QUOTE_DECLINED",
201
- quoteId: this.quote.id
244
+ quoteId: this.quote.id,
202
245
  };
203
-
246
+
204
247
  // For batch quotes, include detailed quote information
205
- if (this.quote.originalQuotes && this.quote.originalQuotes.length > 0) {
206
- optOutData.batchQuoteDetails = this.quote.originalQuotes.map(q => ({
207
- quoteId: q.id,
208
- productPrice: q.spotPrice,
209
- cartItemId: q.cartItemId
210
- }));
248
+ if (
249
+ this.quote.originalQuotes &&
250
+ this.quote.originalQuotes.length > 0
251
+ ) {
252
+ optOutData.batchQuoteDetails = this.quote.originalQuotes.map(
253
+ (q) => {
254
+ const originalItem = this.options.quoteRequestData.items?.find(
255
+ (item) =>
256
+ (item.cartItemId ||
257
+ `item-${
258
+ this.options.quoteRequestData.items.indexOf(item) + 1
259
+ }`) === q.cartItemId
260
+ );
261
+ return {
262
+ quoteId: q.id,
263
+ productPrice: originalItem?.productPrice || q.spotPrice,
264
+ cartItemId: q.cartItemId,
265
+ };
266
+ }
267
+ );
211
268
  }
212
-
269
+
213
270
  this.options.callbacks.onOptOut(optOutData);
214
271
  }
215
272
  });
@@ -258,7 +315,7 @@ class SpotWidget {
258
315
  try {
259
316
  const updatedOptions = {
260
317
  ...this.options,
261
- quoteRequestData: newQuoteRequestData
318
+ quoteRequestData: newQuoteRequestData,
262
319
  };
263
320
 
264
321
  validateOptions(updatedOptions);
@@ -271,10 +328,20 @@ class SpotWidget {
271
328
 
272
329
  const endpoint = customEndpoint || apiEndpoint[environment];
273
330
 
274
- const isBatchQuote = updatedOptions.quoteRequestData.cartInfo && updatedOptions.quoteRequestData.items;
331
+ const isBatchQuote =
332
+ updatedOptions.quoteRequestData.cartInfo &&
333
+ updatedOptions.quoteRequestData.items;
275
334
  const response = isBatchQuote
276
- ? await fetchMultipleQuotes(endpoint, partnerId, updatedOptions.quoteRequestData)
277
- : await fetchQuote(endpoint, partnerId, updatedOptions.quoteRequestData);
335
+ ? await fetchMultipleQuotes(
336
+ endpoint,
337
+ partnerId,
338
+ updatedOptions.quoteRequestData
339
+ )
340
+ : await fetchQuote(
341
+ endpoint,
342
+ partnerId,
343
+ updatedOptions.quoteRequestData
344
+ );
278
345
 
279
346
  if (response.status !== "QUOTE_AVAILABLE") {
280
347
  if (
@@ -320,18 +387,27 @@ class SpotWidget {
320
387
  quoteId: this.quote?.id,
321
388
  spotPrice: this.quote?.spotPrice,
322
389
  status:
323
- this.currentSelection === "yes" ? "QUOTE_ACCEPTED" : "QUOTE_DECLINED"
390
+ this.currentSelection === "yes" ? "QUOTE_ACCEPTED" : "QUOTE_DECLINED",
324
391
  };
325
-
392
+
326
393
  // For batch quotes, include detailed quote information
327
394
  if (this.quote?.originalQuotes && this.quote.originalQuotes.length > 0) {
328
- selectionData.batchQuoteDetails = this.quote.originalQuotes.map(q => ({
329
- quoteId: q.id,
330
- productPrice: q.spotPrice,
331
- cartItemId: q.cartItemId
332
- }));
395
+ selectionData.batchQuoteDetails = this.quote.originalQuotes.map((q) => {
396
+ const originalItem = this.options.quoteRequestData.items?.find(
397
+ (item) =>
398
+ (item.cartItemId ||
399
+ `item-${
400
+ this.options.quoteRequestData.items.indexOf(item) + 1
401
+ }`) === q.cartItemId
402
+ );
403
+ return {
404
+ quoteId: q.id,
405
+ productPrice: originalItem?.productPrice || q.spotPrice,
406
+ cartItemId: q.cartItemId,
407
+ };
408
+ });
333
409
  }
334
-
410
+
335
411
  return selectionData;
336
412
  }
337
413
 
package/src/styles.css CHANGED
@@ -48,6 +48,24 @@
48
48
 
49
49
  --spot-selection-error-font-color: #ff0000;
50
50
  --spot-selection-error-font-size: 0.875rem;
51
+
52
+ --spot-qualifying-reasons-margin: 0.75rem 0;
53
+ --spot-qualifying-reasons-padding: 0 0.3125rem;
54
+ --spot-qualifying-reasons-column-gap: 3rem;
55
+ --spot-qualifying-reasons-row-gap: 0.25rem;
56
+ --spot-qualifying-reasons-grid-padding-left: 1rem;
57
+
58
+ --spot-qualifying-reasons-icon-wrapper-size: 1.125rem;
59
+ --spot-qualifying-reasons-icon-size: 0.75rem;
60
+ --spot-qualifying-reasons-icon-border-color: #2E2E2E;
61
+ --spot-qualifying-reasons-icon-border-width: 1px;
62
+ --spot-qualifying-reasons-icon-background: #ffffff;
63
+ --spot-qualifying-reasons-item-gap: 0.625rem;
64
+
65
+ --spot-qualifying-reasons-label-font-size: 0.8rem;
66
+ --spot-qualifying-reasons-label-font-weight: 400;
67
+ --spot-qualifying-reasons-label-font-color: #000000;
68
+ --spot-qualifying-reasons-label-font-family: Arial;
51
69
  --spot-selection-error-padding: 0.5rem;
52
70
 
53
71
  --spot-payment-terms-background: #f4f4f4;
@@ -212,6 +230,58 @@
212
230
  top: 0.125rem;
213
231
  }
214
232
 
233
+ /* Qualifying Reasons */
234
+ .spot-qualifying-reasons__container {
235
+ margin: var(--spot-qualifying-reasons-margin);
236
+ padding: var(--spot-qualifying-reasons-padding);
237
+ }
238
+
239
+ .spot-qualifying-reasons__grid {
240
+ display: grid;
241
+ grid-template-columns: repeat(2, minmax(0, max-content));
242
+ column-gap: var(--spot-qualifying-reasons-column-gap);
243
+ row-gap: var(--spot-qualifying-reasons-row-gap);
244
+ max-width: 100%;
245
+ padding-left: var(--spot-qualifying-reasons-grid-padding-left);
246
+ }
247
+
248
+ .spot-qualifying-reasons__item {
249
+ display: flex;
250
+ align-items: center;
251
+ gap: var(--spot-qualifying-reasons-item-gap);
252
+ }
253
+
254
+ .spot-qualifying-reasons__icon-wrapper {
255
+ width: var(--spot-qualifying-reasons-icon-wrapper-size);
256
+ height: var(--spot-qualifying-reasons-icon-wrapper-size);
257
+ border-radius: 50%;
258
+ border: var(--spot-qualifying-reasons-icon-border-width) solid var(--spot-qualifying-reasons-icon-border-color);
259
+ background-color: var(--spot-qualifying-reasons-icon-background);
260
+ display: flex;
261
+ align-items: center;
262
+ justify-content: center;
263
+ flex-shrink: 0;
264
+ }
265
+
266
+ .spot-qualifying-reasons__icon {
267
+ width: var(--spot-qualifying-reasons-icon-size);
268
+ height: var(--spot-qualifying-reasons-icon-size);
269
+ }
270
+
271
+ .spot-qualifying-reasons__label {
272
+ font-size: var(--spot-qualifying-reasons-label-font-size);
273
+ font-weight: var(--spot-qualifying-reasons-label-font-weight);
274
+ color: var(--spot-qualifying-reasons-label-font-color);
275
+ font-family: var(--spot-qualifying-reasons-label-font-family);
276
+ line-height: 1.2;
277
+ }
278
+
279
+ @media (max-width: 480px) {
280
+ .spot-qualifying-reasons__grid {
281
+ grid-template-columns: 1fr;
282
+ }
283
+ }
284
+
215
285
  /* Covered Items List */
216
286
  .spot-covered-items__container {
217
287
  margin-top: 0;
package/src/ui.js CHANGED
@@ -38,26 +38,84 @@ export function renderBenefits(container, bullets = []) {
38
38
  });
39
39
  }
40
40
 
41
+ // qualifying reasons
42
+ export function renderQualifyingReasons(container, qualifyingReasons = []) {
43
+ if (!qualifyingReasons || qualifyingReasons.length === 0) return;
44
+
45
+ const wrapper = makeEl("div", {
46
+ className: "spot-qualifying-reasons__container",
47
+ parent: container,
48
+ });
49
+
50
+ const sortedReasons = [...qualifyingReasons].sort((a, b) => a.rank - b.rank);
51
+
52
+ const grid = makeEl("div", {
53
+ className: "spot-qualifying-reasons__grid",
54
+ parent: wrapper,
55
+ });
56
+
57
+ const ICON_MAPPING = {
58
+ "Accident & Illness": "cross.svg",
59
+ "Family Emergencies": "users.svg",
60
+ Layoffs: "building.svg",
61
+ "Jury Duty": "scale.svg",
62
+ "Work Travel Conflict": "briefcase.svg",
63
+ "Severe Weather": "umbrella.svg",
64
+ "Travel Interruption": "plane.svg",
65
+ "Military Duty": "medal.svg",
66
+ };
67
+
68
+ // Get the base URL for assets
69
+ const scriptUrl = new URL(import.meta.url);
70
+ const baseUrl = scriptUrl.origin + scriptUrl.pathname.replace(/\/src\/[^/]*$/, "/assets/");
71
+
72
+ sortedReasons.forEach((reason) => {
73
+ const reasonEl = makeEl("div", {
74
+ className: "spot-qualifying-reasons__item",
75
+ parent: grid,
76
+ });
77
+
78
+ const iconWrapper = makeEl("div", {
79
+ className: "spot-qualifying-reasons__icon-wrapper",
80
+ parent: reasonEl,
81
+ });
82
+
83
+ const iconFileName =
84
+ ICON_MAPPING[reason.benefitType?.name] || ICON_MAPPING[reason.name];
85
+ if (iconFileName) {
86
+ const img = makeEl("img", {
87
+ parent: iconWrapper,
88
+ });
89
+ img.src = baseUrl + iconFileName;
90
+ img.alt = reason.benefitType?.name || reason.name || "";
91
+ img.className = "spot-qualifying-reasons__icon";
92
+ }
93
+
94
+ makeEl("span", {
95
+ className: "spot-qualifying-reasons__label",
96
+ text: reason.benefitType?.name || reason.name || "",
97
+ parent: reasonEl,
98
+ });
99
+ });
100
+ }
101
+
41
102
  // covered items for multi-quote
42
103
  export function renderCoveredItems(container, coveredItems = []) {
43
104
  if (coveredItems.length === 0) return;
44
-
105
+
45
106
  const wrapper = makeEl("div", {
46
107
  className: "spot-covered-items__container",
47
108
  parent: container,
48
109
  });
49
-
50
110
  makeEl("div", {
51
111
  className: "spot-covered-items__title",
52
112
  text: "Items covered in your cart:",
53
113
  parent: wrapper,
54
114
  });
55
-
56
115
  const ul = makeEl("ul", {
57
116
  className: "spot-covered-items__list",
58
117
  parent: wrapper,
59
118
  });
60
-
61
119
  coveredItems.forEach((item) => {
62
120
  const li = makeEl("li", { parent: ul });
63
121
  makeEl("span", { text: item, parent: li });
package/vite.config.js CHANGED
@@ -14,4 +14,5 @@ export default defineConfig({
14
14
  external: [], // no dependencies
15
15
  },
16
16
  },
17
+ publicDir: "assets",
17
18
  });