{
  "version": 3,
  "sources": ["landing-pricing.js"],
  "sourcesContent": ["import $ from \"../../core/jquery.js\";\nimport { api } from \"../../core/api.js\";\nimport { register } from \"../../core/components.js\";\nimport { formatMoney } from \"../../core/format.js\";\nimport { gettext, interpolate, ngettext } from \"../../core/i18n.js\";\nimport { play } from \"../../core/motion.js\";\n\nconst MONTHLY = 1;\nconst YEARLY = 12;\n\n/** The gross price of an offer in a currency, in its minor unit - or null. */\nfunction grossOf(offer, currency) {\n    return (\n        offer?.prices.find((price) => price.currency === currency)?.gross_amount ?? null\n    );\n}\n\n/**\n * The plans on sale as subscriptions, smallest first, each with its offer for\n * a month and for a year where it has one with a price in the currency.\n */\nfunction plansOf(offers, currency) {\n    const plans = new Map();\n    offers\n        .filter((offer) => offer.kind === \"subscription\" && offer.plan)\n        .filter((offer) => grossOf(offer, currency) !== null)\n        .forEach((offer) => {\n            const entry = plans.get(offer.plan.uuid) ?? {\n                plan: offer.plan,\n                periods: {},\n            };\n            entry.periods[offer.period_months] = offer;\n            plans.set(offer.plan.uuid, entry);\n        });\n    return [...plans.values()]\n        .filter((entry) => entry.periods[MONTHLY] || entry.periods[YEARLY])\n        .sort((a, b) => a.plan.storage_gb - b.plan.storage_gb);\n}\n\n/** True when a year of every plan costs no more than ten of its months. */\nfunction yearIsTenMonths(plans, currency) {\n    const both = plans.filter(\n        (entry) => entry.periods[MONTHLY] && entry.periods[YEARLY],\n    );\n    return (\n        both.length > 0 &&\n        both.every(\n            (entry) =>\n                grossOf(entry.periods[YEARLY], currency) <=\n                10 * grossOf(entry.periods[MONTHLY], currency),\n        )\n    );\n}\n\nfunction statsText(months) {\n    if (!months) {\n        return gettext(\"Website statistics with no time limit\");\n    }\n    return interpolate(\n        ngettext(\n            \"Website statistics: %(months)s month back\",\n            \"Website statistics: %(months)s months back\",\n            months,\n        ),\n        { months },\n    );\n}\n\n/**\n * The home page's prices, drawn from the public offers: a card for every plan\n * sold as a subscription, by its storage, with what its website may do, and\n * the price for a month or a year as the visitor switches - the cards swept\n * off to one side and back in from the other, the way the switch moved. Nothing is drawn\n * when the offers cannot be had - the notes and the larger plans stay.\n */\nregister(\"landing-pricing\", (root, options) => {\n    const currency = options.currency;\n    const list = root.find(\"[data-ref=plans]\");\n    const template = root.find(\"[data-ref=plan-template]\")[0];\n    const periodButtons = root.find(\"[data-action=period]\");\n    let plans = [];\n    let months = MONTHLY;\n\n    function card(entry) {\n        const item = $(template.content.firstElementChild.cloneNode(true));\n        const offer =\n            entry.periods[months] ?? entry.periods[MONTHLY] ?? entry.periods[YEARLY];\n        const shownMonths = offer.period_months;\n        const { plan } = entry;\n        item.find(\"[data-ref=name]\").text(plan.name);\n        item.find(\"[data-ref=storage]\").text(\n            interpolate(gettext(\"%(gb)s GB of storage\"), { gb: plan.storage_gb }),\n        );\n        item.find(\"[data-ref=amount]\").text(\n            formatMoney(grossOf(offer, currency), currency),\n        );\n        item.find(\"[data-ref=per]\").text(\n            shownMonths === YEARLY ? gettext(\"a year\") : gettext(\"a month\"),\n        );\n        item.find(\"[data-ref=has-sites]\").prop(\"hidden\", !plan.has_sites);\n        item.find(\"[data-ref=has-custom-domain]\").prop(\n            \"hidden\",\n            !plan.has_custom_domain,\n        );\n        item.find(\"[data-ref=has-multiple-sites]\").prop(\n            \"hidden\",\n            !plan.has_multiple_sites,\n        );\n        item.find(\"[data-ref=site-stats]\")\n            .text(statsText(plan.site_stats_months))\n            .prop(\"hidden\", !plan.has_sites);\n        return item;\n    }\n\n    function draw() {\n        list.empty().append(plans.map(card));\n    }\n\n    periodButtons.on(\"click\", async function () {\n        const chosen = Number($(this).attr(\"data-months\"));\n        if (chosen === months) {\n            return;\n        }\n        const forward = chosen > months;\n        months = chosen;\n        periodButtons.each(function () {\n            const current = Number($(this).attr(\"data-months\")) === months;\n            $(this)\n                .toggleClass(\"home-pricing__period-option--current\", current)\n                .attr(\"aria-pressed\", String(current));\n        });\n        await play(list, forward ? \"dropOutLeft\" : \"dropOutRight\");\n        draw();\n        await play(list, forward ? \"dropInRight\" : \"dropInLeft\");\n    });\n\n    api.get(\"billing.offers\").then((offers) => {\n        plans = plansOf(offers, currency);\n        root.find(\"[data-ref=yearly-note]\").prop(\n            \"hidden\",\n            !yearIsTenMonths(plans, currency),\n        );\n        draw();\n    });\n});\n"],
  "mappings": "AAAA,OAAOA,MAAO,uBACd,OAAS,OAAAC,MAAW,oBACpB,OAAS,YAAAC,MAAgB,2BACzB,OAAS,eAAAC,MAAmB,uBAC5B,OAAS,WAAAC,EAAS,eAAAC,EAAa,YAAAC,MAAgB,qBAC/C,OAAS,QAAAC,MAAY,uBAErB,MAAMC,EAAU,EACVC,EAAS,GAGf,SAASC,EAAQC,EAAOC,EAAU,CAC9B,OACID,GAAO,OAAO,KAAME,GAAUA,EAAM,WAAaD,CAAQ,GAAG,cAAgB,IAEpF,CAMA,SAASE,EAAQC,EAAQH,EAAU,CAC/B,MAAMI,EAAQ,IAAI,IAClB,OAAAD,EACK,OAAQJ,GAAUA,EAAM,OAAS,gBAAkBA,EAAM,IAAI,EAC7D,OAAQA,GAAUD,EAAQC,EAAOC,CAAQ,IAAM,IAAI,EACnD,QAASD,GAAU,CAChB,MAAMM,EAAQD,EAAM,IAAIL,EAAM,KAAK,IAAI,GAAK,CACxC,KAAMA,EAAM,KACZ,QAAS,CAAC,CACd,EACAM,EAAM,QAAQN,EAAM,aAAa,EAAIA,EACrCK,EAAM,IAAIL,EAAM,KAAK,KAAMM,CAAK,CACpC,CAAC,EACE,CAAC,GAAGD,EAAM,OAAO,CAAC,EACpB,OAAQC,GAAUA,EAAM,QAAQT,CAAO,GAAKS,EAAM,QAAQR,CAAM,CAAC,EACjE,KAAK,CAACS,EAAGC,IAAMD,EAAE,KAAK,WAAaC,EAAE,KAAK,UAAU,CAC7D,CAGA,SAASC,EAAgBJ,EAAOJ,EAAU,CACtC,MAAMS,EAAOL,EAAM,OACdC,GAAUA,EAAM,QAAQT,CAAO,GAAKS,EAAM,QAAQR,CAAM,CAC7D,EACA,OACI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iBACV,EACAF,EAAK,KAAK,+BAA+B,EAAE,KACvC,SACA,CAACE,EAAK,kBACV,EACAF,EAAK,KAAK,uBAAuB,EAC5B,KAAKR,EAAUU,EAAK,iBAAiB,CAAC,EACtC,KAAK,SAAU,CAACA,EAAK,SAAS,EAC5BF,CACX,CAEA,SAASG,GAAO,CACZP,EAAK,MAAM,EAAE,OAAOV,EAAM,IAAIa,CAAI,CAAC,CACvC,CAEAD,EAAc,GAAG,QAAS,gBAAkB,CACxC,MAAMM,EAAS,OAAOlC,EAAE,IAAI,EAAE,KAAK,aAAa,CAAC,EACjD,GAAIkC,IAAWX,EACX,OAEJ,MAAMY,EAAUD,EAASX,EACzBA,EAASW,EACTN,EAAc,KAAK,UAAY,CAC3B,MAAMQ,EAAU,OAAOpC,EAAE,IAAI,EAAE,KAAK,aAAa,CAAC,IAAMuB,EACxDvB,EAAE,IAAI,EACD,YAAY,uCAAwCoC,CAAO,EAC3D,KAAK,eAAgB,OAAOA,CAAO,CAAC,CAC7C,CAAC,EACD,MAAM7B,EAAKmB,EAAMS,EAAU,cAAgB,cAAc,EACzDF,EAAK,EACL,MAAM1B,EAAKmB,EAAMS,EAAU,cAAgB,YAAY,CAC3D,CAAC,EAEDlC,EAAI,IAAI,gBAAgB,EAAE,KAAMc,GAAW,CACvCC,EAAQF,EAAQC,EAAQH,CAAQ,EAChCY,EAAK,KAAK,wBAAwB,EAAE,KAChC,SACA,CAACJ,EAAgBJ,EAAOJ,CAAQ,CACpC,EACAqB,EAAK,CACT,CAAC,CACL,CAAC",
  "names": ["$", "api", "register", "formatMoney", "gettext", "interpolate", "ngettext", "play", "MONTHLY", "YEARLY", "grossOf", "offer", "currency", "price", "plansOf", "offers", "plans", "entry", "a", "b", "yearIsTenMonths", "both", "statsText", "months", "root", "options", "list", "template", "periodButtons", "card", "item", "shownMonths", "plan", "draw", "chosen", "forward", "current"]
}
