import{AdjustmentType as e}from"../../components/product-subscription/types.js";let 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},l=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?0:e*t/100,n=({amount:e})=>r({value:e}),u=({variantPrice:e,fixedPrice:t})=>{let l=r({value:t});return l<=0?0:e-l},a=({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 o=t({policies:i});if(!o)return 0;let s=o.AdjustmentType??o.adjustmentType,p=o.AdjustmentValue??o.adjustmentValue;return s&&p?s===e.FIXED_AMOUNT&&p.amount?n({amount:p.amount}):s===e.PERCENTAGE&&void 0!==p.percentage?l({variantPrice:r,percentage:p.percentage}):s===e.PRICE&&p.amount?u({variantPrice:r,fixedPrice:p.amount}):0:0},i=({variantPrice:e,amount:t})=>{let l=r({value:t});return l<=0?e:e-l},o=({variantPrice:e,percentage:t})=>isNaN(t)||t<=0?e:e-e*t/100,s=({fixedPrice:e})=>r({value:e}),p=({variantPrice:r,pricingPolicies:l})=>{if(!l||0===l.length)return r;let n=l.filter(e=>null!=e);if(0===n.length)return r;let u=t({policies:n});if(!u)return r;let a=u.AdjustmentType??u.adjustmentType,p=u.AdjustmentValue??u.adjustmentValue;return a&&p?a===e.FIXED_AMOUNT&&p.amount?i({variantPrice:r,amount:p.amount}):a===e.PERCENTAGE&&void 0!==p.percentage?o({variantPrice:r,percentage:p.percentage}):a===e.PRICE&&p.amount?s({fixedPrice:p.amount}):r:r},c=({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 l=1===t?r.singular:r.plural;return 1===t?`every ${l}`:`every ${t} ${l}`},m=({deliveryPolicy:e})=>{if(!e)return"";let t=e.interval?.toUpperCase();if(!t)return"";let r=e.intervalCount??1;return c({interval:t,intervalCount:r})};export{p as calculateRecurringPrice,a as calculateSellingPlanDiscount,t as findPolicyWithoutAfterCycle,m as formatInterval};
