import{z as zeroDecimalCurrencies}from"./currency.js";const convertAmount=(r,e)=>zeroDecimalCurrencies.includes(e)?r:r/100,getHumanDiscount=r=>{if((null==r?void 0:r.amount_off)&&(null==r?void 0:r.currency))return getFormattedPrice({amount:r.amount_off,currency:r.currency});if(null==r?void 0:r.percent_off){const e=(0|r.percent_off)+"%";
// translators: %s is the discount percentage (e.g. "10%").
return wp.i18n.sprintf(wp.i18n.__("%s off","surecart"),e)}return""},getFormattedPrice=({amount:r,currency:e})=>{const n=convertAmount(r,e);return`${new Intl.NumberFormat(void 0,{style:"currency",currency:e}).format(parseFloat(n.toFixed(2)))}`},getCurrencySymbol=(r="usd")=>{var e;return null===(e=new Intl.NumberFormat(void 0,{style:"currency",currency:r}).formatToParts().find((r=>"currency"===r.type)))||void 0===e?void 0:e.value},translateInterval=(r,e,n=wp.i18n.__("every","surecart"),t=wp.i18n.__("once","surecart"),a=!1)=>{switch(e){case"day":return`${n} ${wp.i18n.sprintf(a?wp.i18n._n("%d day","%d days",r,"surecart"):wp.i18n._n("day","%d days",r,"surecart"),r)}`;case"week":return`${n} ${wp.i18n.sprintf(a?wp.i18n._n("%d week","%d weeks",r,"surecart"):wp.i18n._n("week","%d weeks",r,"surecart"),r)}`;case"month":return`${n} ${wp.i18n.sprintf(a?wp.i18n._n("%d month","%d months",r,"surecart"):wp.i18n._n("month","%d months",r,"surecart"),r)}`;case"year":return`${n} ${wp.i18n.sprintf(a?wp.i18n._n("%d year","%d years",r,"surecart"):wp.i18n._n("year","%d years",r,"surecart"),r)}`;default:return t}},translateAbbreviatedInterval=(r,e,n=wp.i18n.__("once","surecart"),t=!1)=>{switch(e){case"day":return` / ${wp.i18n.sprintf(t?wp.i18n._n("%d day","%d days",r,"surecart"):wp.i18n._n("day","%d days",r,"surecart"),r)}`;case"week":return` / ${wp.i18n.sprintf(t?wp.i18n._n("%d wk","%d wks",r,"surecart"):wp.i18n._n("wk","%d wks",r,"surecart"),r)}`;case"month":return` / ${wp.i18n.sprintf(t?wp.i18n._n("%d mo","%d months",r,"surecart"):wp.i18n._n("mo","%d mos",r,"surecart"),r)}`;case"year":return` / ${wp.i18n.sprintf(t?wp.i18n._n("%d yr","%d yrs",r,"surecart"):wp.i18n._n("yr","%d yrs",r,"surecart"),r)}`;default:return n}},intervalString=(r,e={})=>{if(!r)return"";const{showOnce:n,labels:t,abbreviate:a}=e,{interval:i=wp.i18n.__("every","surecart")}=t||{};return`${intervalCountString(r,i,n?wp.i18n.__("once","surecart"):"",a)} ${periodCountString(r,a)}`},intervalCountString=(r,e,n=wp.i18n.__("once","surecart"),t=!1)=>r.recurring_interval_count&&r.recurring_interval&&1!==(null==r?void 0:r.recurring_period_count)?t?translateAbbreviatedInterval(r.recurring_interval_count,r.recurring_interval,n):translateInterval(r.recurring_interval_count,r.recurring_interval,` ${e}`,n):"",periodCountString=(r,e=!1)=>(null==r?void 0:r.recurring_period_count)&&1!==(null==r?void 0:r.recurring_period_count)?e?`x ${r.recurring_period_count}`:` (${wp.i18n.sprintf(wp.i18n._n("%d payment","%d payments",r.recurring_period_count,"surecart"),r.recurring_period_count)})`:"",productNameWithPrice=r=>{var e;return r?`${null===(e=null==r?void 0:r.product)||void 0===e?void 0:e.name} ${(null==r?void 0:r.name)?`— ${r.name}`:""}`:""},getHumanDiscountRedeemableStatus=r=>{switch(r){case"invalid":return wp.i18n.__("Not valid","surecart");case"expired":return wp.i18n.__("Expired","surecart");case"gone":return wp.i18n.__("Not available","surecart");case"less_than_min_subtotal_amount":return wp.i18n.__("Minimum not met","surecart");case"greater_than_max_subtotal_amount":return wp.i18n.__("Order amount exceeds limit","surecart");case"not_applicable":return wp.i18n.__("Product(s) not eligible","surecart");case"not_applicable_to_customer":return wp.i18n.__("Not eligible","surecart");case"":return"";default:return wp.i18n.__("Not redeemable","surecart")}};export{getHumanDiscount as a,getHumanDiscountRedeemableStatus as b,getCurrencySymbol as c,getFormattedPrice as g,intervalString as i,productNameWithPrice as p,translateInterval as t};