"use strict";var e=require("../../components/product-subscription/types.js");const t=({policies:e})=>{let t=e.filter(e=>null!=e);if(0===t.length)return null;let r=t.find(e=>{let t=e?.AfterCycle??e.afterCycle;return!t});return r??t[0]??null},r=({value:e})=>{if(!e)return 0;let t=parseFloat(e);return isNaN(t)||t<=0?0:t},n=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?0:e*t/100,u=({amount:e})=>r({value:e}),l=({variantPrice:e,fixedPrice:t})=>{let n=r({value:t});return n<=0?0:e-n},a=({variantPrice:e,amount:t})=>{let n=r({value:t});return n<=0?e:e-n},i=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?e:e-e*t/100,s=({fixedPrice:e})=>r({value:e}),o=({interval:e,intervalCount:t})=>{let r={DAY:{singular:"day",plural:"days"},WEEK:{singular:"week",plural:"weeks"},MONTH:{singular:"month",plural:"months"},YEAR:{singular:"year",plural:"years"}}[e];if(!r){let r=e.toLowerCase();return 1===t?`every ${r}`:`every ${t} ${r}`}let n=1===t?r.singular:r.plural;return 1===t?`every ${n}`:`every ${t} ${n}`};exports.calculateRecurringPrice=({variantPrice:r,pricingPolicies:n})=>{if(!n||0===n.length)return r;let u=n.filter(e=>null!=e);if(0===u.length)return r;let l=t({policies:u});if(!l)return r;let o=l.AdjustmentType??l.adjustmentType,p=l.AdjustmentValue??l.adjustmentValue;return o&&p?o===e.AdjustmentType.FIXED_AMOUNT&&p.amount?a({variantPrice:r,amount:p.amount}):o===e.AdjustmentType.PERCENTAGE&&void 0!==p.percentage?i({variantPrice:r,percentage:p.percentage}):o===e.AdjustmentType.PRICE&&p.amount?s({fixedPrice:p.amount}):r:r},exports.calculateSellingPlanDiscount=({variantPrice:r,pricingPolicies:a})=>{if(!a||0===a.length)return 0;let i=a.filter(e=>null!=e);if(0===i.length)return 0;let s=t({policies:i});if(!s)return 0;let o=s.AdjustmentType??s.adjustmentType,p=s.AdjustmentValue??s.adjustmentValue;return o&&p?o===e.AdjustmentType.FIXED_AMOUNT&&p.amount?u({amount:p.amount}):o===e.AdjustmentType.PERCENTAGE&&void 0!==p.percentage?n({variantPrice:r,percentage:p.percentage}):o===e.AdjustmentType.PRICE&&p.amount?l({variantPrice:r,fixedPrice:p.amount}):0:0},exports.findPolicyWithoutAfterCycle=t,exports.formatInterval=({deliveryPolicy:e})=>{if(!e)return"";let t=e.interval?.toUpperCase();if(!t)return"";let r=e.intervalCount??1;return o({interval:t,intervalCount:r})};
