"use strict";var e=require("./calculateBestSellingPlan.js"),r=require("@gem-sdk/core");const i="__unknown__",t=e=>{let r=[];for(let i of e)if(i?.sellingPlans){let e=i.sellingPlans.filter(e=>null!=e);r.push(...e)}return r},p=e=>{if(!e)return 0;let i="number"==typeof e.price?String(e.price):e.price??void 0;return r.convertDecimalToNumber(i)??0},n=(e,r)=>e.find(e=>e?.sellingPlans?.some(e=>e?.baseID===r||e?.id===r)),u=(r,i)=>{let p=t(r);if(0===p.length)return;let u=e.findBestPlanFromList({plans:p,variantPrice:i});if(u)return n(r,u.baseID||u.id||"")},l=({sellingPlanGroups:e,extractedSettings:r,hasGroup:i,hasSourceApp:t,isUnknownSourceApp:p})=>i?p?e.find(e=>e?.id===r.group):t?e.find(e=>e?.appID===r.sourceApp&&e?.id===r.group):void 0:void 0;exports.findMatchedGroup=e=>{let{sellingPlanGroups:r,extractedSettings:o,currentVariant:s}=e,f=t(r),d=p(s),c=!!o.group,a=o.sourceApp===i,g=!!o.sourceApp,A=l({sellingPlanGroups:r,extractedSettings:o,hasGroup:c,hasSourceApp:g,isUnknownSourceApp:a}),v=o.defaultOptions?n(r,o.defaultOptions):void 0,m=o.sourceApp&&o.sourceApp!==i?r.find(e=>e?.appID===o.sourceApp):void 0,D=!c||void 0===o.sourceApp||!!A,I=!o.defaultOptions||!!v,O=!o.sourceApp||o.sourceApp===i||!!m;if(!(D&&I&&O)){let e=u(r,d);return e||(f.length?r[0]:void 0)}if(o.defaultOptions){let e=n(r,o.defaultOptions);if(e)return e}if(o.sourceApp){let e=r.find(e=>e?.appID===o.sourceApp);if(e)return e}if(d>0){let e=u(r,d);if(e)return e}return r[0]};
