17 lines
871 B
JavaScript
17 lines
871 B
JavaScript
// Separate native plans retain their own quota; this only groups their cards.
|
|
export function catalogGroups(plans, periods, currentPlanId) {
|
|
const groups=[];
|
|
for(const plan of plans){
|
|
const keys=periods.filter(k=>plan[k]!=null&&(k!=='reset_price'||String(currentPlanId)===String(plan.id)));
|
|
if(!keys.length)continue;
|
|
const series=Array.isArray(plan.tags)?plan.tags.find(t=>/^fuc-series:[a-z0-9-]+$/.test(t)):null;
|
|
const key=series?'series-'+series.slice(11):'plan-'+plan.id;
|
|
let group=groups.find(g=>g.key===key);
|
|
// Conflicting products stay separate instead of hiding a purchase option.
|
|
if(group&&group.rows.some(row=>keys.includes(row.period)))group=null;
|
|
if(!group){group={key:groups.some(g=>g.key===key)?'plan-'+plan.id:key,name:plan.name,rows:[]};groups.push(group);}
|
|
group.rows.push(...keys.map(period=>({plan,period})));
|
|
}
|
|
return groups;
|
|
}
|