"use strict";
exports.id = 8371;
exports.ids = [8371];
exports.modules = {

/***/ 510220:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "G": () => (/* binding */ LinkToStore)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(807772);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var next_router__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(371853);
/* harmony import */ var next_router__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(next_router__WEBPACK_IMPORTED_MODULE_3__);
/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 



const STYLE = {
    fontSize: "150%",
    fontWeight: "bold",
    textAlign: "center",
    marginTop: "30px"
};
function LinkToStore(props) {
    const { conf  } = props;
    const router = (0,next_router__WEBPACK_IMPORTED_MODULE_3__.useRouter)();
    const params = Object.entries(conf).map(([key, value])=>`${key}=${value}`).join("&");
    const url = `/store/site-license?${params}`;
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
        style: STYLE,
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_2__.Button, {
            size: "large",
            type: "default",
            onClick: ()=>router.push(url),
            icon: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__.Icon, {
                name: "shopping-cart"
            }),
            children: "Select"
        })
    });
}


/***/ }),

/***/ 856343:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.displaySiteLicense = exports.untangleUptime = exports.requiresMemberhosting = exports.LicenseIdleTimeoutsKeysOrdered = exports.LicenseIdleTimeouts = void 0;
const lodash_1 = __webpack_require__(988593);
// Site Licenses related constants
// the license timeouts combined with the default quota (either hardcoded or the one from the site_settings)
// hence 30 minutes + 30 minutes default result in 30 minutes, and the same for "medium" and "day"
// @see DEFAULT_QUOTAS.mintime in src/packages/util/upgrade-spec.js
// medium and day imply member hosting
exports.LicenseIdleTimeouts = {
    short: {
        mins: 30,
        label: "30 minutes",
        labelShort: "30min",
        priceFactor: 1,
    },
    medium: { mins: 2 * 60, label: "2 hours", labelShort: "2h", priceFactor: 2 },
    day: {
        mins: 24 * 60,
        label: "1 day",
        labelShort: "1d",
        priceFactor: 4,
        requireMemberhosting: true,
    },
};
exports.LicenseIdleTimeoutsKeysOrdered = (0, lodash_1.sortBy)(Object.keys(exports.LicenseIdleTimeouts), (v) => exports.LicenseIdleTimeouts[v].mins);
function requiresMemberhosting(key) {
    if (key == null)
        return false;
    if (key == "always_running")
        return true;
    return exports.LicenseIdleTimeouts[key]?.requireMemberhosting ?? false;
}
exports.requiresMemberhosting = requiresMemberhosting;
function untangleUptime(uptime) {
    if (uptime == null) {
        // Let's just support this and have it default to short, since obviously
        // by explicitly allowing uptime? via typescript, we can't even tell there
        // is a problem from typescript errors.  See
        //    https://github.com/sagemathinc/cocalc/issues/6257
        // for how this bug causes a lot of trouble.
        return { always_running: false, idle_timeout: "short" };
    }
    if (uptime == "always_running") {
        return { always_running: true, idle_timeout: "day" };
    }
    return { always_running: false, idle_timeout: uptime };
}
exports.untangleUptime = untangleUptime;
function displaySiteLicense(uptime) {
    if (uptime == "always_running") {
        return "Always Running";
    }
    else {
        return exports.LicenseIdleTimeouts[uptime].label;
    }
}
exports.displaySiteLicense = displaySiteLicense;
//# sourceMappingURL=site-license.js.map

/***/ }),

/***/ 182961:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {

var __webpack_unused_export__;

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
__webpack_unused_export__ = ({ value: true });
exports.pl = exports.f5 = void 0;
const billing_1 = __webpack_require__(612134);
const site_license_1 = __webpack_require__(856343);
const consts_1 = __webpack_require__(847533);
const dedicated_price_1 = __webpack_require__(461649);
function compute_cost(info) {
    if (info.type === "disk" || info.type === "vm") {
        return compute_cost_dedicated(info);
    }
    if (info.type !== "quota")
        throw new Error(`can only compute cost for type=quota`);
    let { quantity, user, upgrade, subscription, custom_ram, custom_cpu, custom_dedicated_ram, custom_dedicated_cpu, custom_disk, custom_member, custom_uptime, boost = false, } = info;
    // at this point, we assume the start/end dates are already
    // set to the start/end time of a day in the user's timezone.
    const start = info.start ? new Date(info.start) : undefined;
    const end = info.end ? new Date(info.end) : undefined;
    // dedicated cases above should eliminate an unknown user.
    if (user !== "academic" && user !== "business") {
        throw new Error(`unknown user ${user}`);
    }
    // this is set in the next if/else block
    let custom_always_running = false;
    if (upgrade == "standard") {
        // set custom_* to what they would be:
        custom_ram = consts_1.STANDARD.ram;
        custom_cpu = consts_1.STANDARD.cpu;
        custom_disk = consts_1.STANDARD.disk;
        custom_always_running = !!consts_1.STANDARD.always_running;
        custom_member = !!consts_1.STANDARD.member;
    }
    else if (upgrade == "basic") {
        custom_ram = consts_1.BASIC.ram;
        custom_cpu = consts_1.BASIC.cpu;
        custom_disk = consts_1.BASIC.disk;
        custom_always_running = !!consts_1.BASIC.always_running;
        custom_member = !!consts_1.BASIC.member;
    }
    else if (upgrade == "max") {
        custom_ram = consts_1.MAX.ram;
        custom_cpu = consts_1.MAX.cpu;
        custom_dedicated_ram = consts_1.MAX.dedicated_ram;
        custom_dedicated_cpu = consts_1.MAX.dedicated_cpu;
        custom_disk = consts_1.MAX.disk;
        custom_always_running = !!consts_1.MAX.always_running;
        custom_member = !!consts_1.MAX.member;
    }
    else {
        custom_always_running = custom_uptime === "always_running";
    }
    // member hosting is controlled by uptime
    if (custom_always_running !== true && (0, site_license_1.requiresMemberhosting)(custom_uptime)) {
        custom_member = true;
    }
    // We compute the cost for one project for one month.
    // First we add the cost for RAM and CPU.
    let cost_per_project_per_month = custom_ram * consts_1.COSTS.custom_cost.ram +
        custom_cpu * consts_1.COSTS.custom_cost.cpu +
        custom_dedicated_ram * consts_1.COSTS.custom_cost.dedicated_ram +
        custom_dedicated_cpu * consts_1.COSTS.custom_cost.dedicated_cpu;
    // If the project is always one, multiply the RAM/CPU cost by a factor.
    if (custom_always_running) {
        cost_per_project_per_month *= consts_1.COSTS.custom_cost.always_running;
        if (custom_member) {
            // if it is member hosted and always on, we absolutely can't ever use
            // pre-emptible for this project.  On the other hand,
            // always on non-member means it gets restarted whenever the
            // pre-empt gets killed, which is still potentially very useful
            // for long-running computations that can be checkpointed and started.
            cost_per_project_per_month *= consts_1.GCE_COSTS.non_pre_factor;
        }
    }
    else {
        // multiply by the idle_timeout factor
        // the smallest idle_timeout has a factor of 1
        const idle_timeout_spec = site_license_1.LicenseIdleTimeouts[custom_uptime];
        if (idle_timeout_spec != null) {
            cost_per_project_per_month *= idle_timeout_spec.priceFactor;
        }
    }
    // If the project is member hosted, multiply the RAM/CPU cost by a factor.
    if (custom_member) {
        cost_per_project_per_month *= consts_1.COSTS.custom_cost.member;
    }
    // Add the disk cost, which doesn't depend on how frequently the project
    // is used or the quality of hosting.
    cost_per_project_per_month += custom_disk * consts_1.COSTS.custom_cost.disk;
    // It's convenient in all cases to have the actual amount we will be
    // for both monthly and yearly available (used by backend for setting up
    // stripe products).
    const cost_sub_month = cost_per_project_per_month *
        consts_1.COSTS.user_discount[user] *
        consts_1.COSTS.sub_discount["monthly"];
    const cost_sub_year = cost_per_project_per_month *
        12 *
        consts_1.COSTS.user_discount[user] *
        consts_1.COSTS.sub_discount["yearly"];
    // Now give the academic and subscription discounts:
    cost_per_project_per_month *=
        consts_1.COSTS.user_discount[user] * consts_1.COSTS.sub_discount[subscription];
    let base_cost = cost_per_project_per_month;
    // Make cost properly account for period of purchase or subscription.
    if (subscription == "no") {
        if (start == null) {
            throw new Error("start must be set if subscription=no");
        }
        if (end == null) {
            throw Error("end must be set if subscription=no");
        }
        // scale by factor of a month
        const months = (end.valueOf() - start.valueOf()) / billing_1.ONE_MONTH_MS;
        base_cost *= months;
    }
    else if (subscription == "yearly") {
        base_cost *= 12;
    }
    // Just for visual clarity, if no quota boots are selected, user sees $0.00
    const boostZeroed = boost && custom_cpu === 0 && custom_ram === 0 && custom_disk === 0;
    const min_sale = boostZeroed ? 0 : consts_1.COSTS.min_sale;
    // cost_per_unit is important for purchasing upgrades for specific intervals.
    // i.e. above the "cost" is calculated for the total number of projects,
    // then here in "cost" the price is limited by the min_sale amount,
    // and later in charge/stripeCreatePrice, we did divide by the number of projects again.
    // instead: we use the limited cost_per_unit price to create a price in stripe.
    // and hence there is no implicit discount if you purchase several projects at once.
    // note: later on you have to use round2, since this is the price with full precision.
    const cost_per_unit = Math.max(min_sale / consts_1.COSTS.online_discount, base_cost);
    const cost_total = quantity * cost_per_unit;
    return {
        cost_per_unit,
        cost: cost_total,
        discounted_cost: Math.max(min_sale, cost_total * consts_1.COSTS.online_discount),
        cost_per_project_per_month,
        // attn: cost_sub* will be multiplied by the online discount in server/licenses/purchase/charge.ts
        // regarding min_sale, see above regarding cost_per_unit
        cost_sub_month: Math.max(min_sale / consts_1.COSTS.online_discount, cost_sub_month),
        cost_sub_year: Math.max(min_sale / consts_1.COSTS.online_discount, cost_sub_year),
    };
}
exports.f5 = compute_cost;
// cost-object for dedicated resource – there are no discounts whatsoever
function compute_cost_dedicated(info) {
    const { price, monthly } = (0, dedicated_price_1.dedicatedPrice)(info);
    return {
        cost: price,
        cost_per_unit: price,
        discounted_cost: price,
        cost_per_project_per_month: monthly,
        cost_sub_month: monthly,
        cost_sub_year: 12 * monthly,
        period: info.subscription,
    };
}
exports.pl = compute_cost_dedicated;
//# sourceMappingURL=compute-cost.js.map

/***/ }),

/***/ 847533:
/***/ ((__unused_webpack_module, exports) => {


/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.discount_yearly_pct = exports.discount_monthly_pct = exports.discount_pct = exports.COSTS = exports.MIN_QUOTE = exports.MAX = exports.STANDARD = exports.BASIC = exports.CUSTOM_COST = exports.GCE_COSTS = void 0;
// discount is the number we multiply the price by:
// TODO: move the actual **data** that defines this cost map to the database
// and admin site settings.  It must be something that we can change at any time,
// and that somebody else selling cocalc would set differently.
// See https://cloud.google.com/compute/vm-instance-pricing#e2_custommachinetypepricing
// for the monthly GCE prices
exports.GCE_COSTS = {
    ram: 0.67,
    cpu: 5,
    disk: 0.04,
    non_pre_factor: 3.5, // Roughly Google's factor for non-preemptible's
};
// Our price = GCE price times this.  We charge LESS than Google VM's, due to our gamble
// on having multiple users on a node at once.
// 2022-06: price increase "version 2", from 0.75 → 0.8 to compensate for 15% higher GCE prices
//          and there is also a minimum of 3gb storage (the free base quota) now.
const COST_MULTIPLIER = 0.8;
// We gamble that projects are packed at least twice as densely on non-member
// nodes (it's often worse).
const NONMEMBER_DENSITY = 2;
// Changing this doesn't change the actual academic prices --
// it just changes the *business* prices.
const ACADEMIC_DISCOUNT = 0.6;
// Disk factor is based on how many copies of user data we have, plus guesses about
// bandwidth to transfer data around (to/from cloud storage, backblaze, etc.).
// 10 since we have about that many copies of user data, plus snapshots, and
// we store their data long after they stop paying...
const DISK_FACTOR = 10;
// These are based on what we observe in practice, what works well,
// and what is configured in our backend autoscalers.  This only
// impacts the cost of dedicated cpu and RAM.
const RAM_OVERCOMMIT = 5;
const CPU_OVERCOMMIT = 10;
// Extra charge if project will always be on. Really we are gambling that
// projects that are not always on, are off much of the time (at least 50%).
// We use this factor since a 50-simultaneous active projects license could
// easily be used about half of the time during a week in a large class.
const ALWAYS_RUNNING_FACTOR = 2;
exports.CUSTOM_COST = {
    ram: (COST_MULTIPLIER * exports.GCE_COSTS.ram) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,
    dedicated_ram: (RAM_OVERCOMMIT * (COST_MULTIPLIER * exports.GCE_COSTS.ram)) /
        ACADEMIC_DISCOUNT /
        NONMEMBER_DENSITY,
    cpu: (COST_MULTIPLIER * exports.GCE_COSTS.cpu) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,
    dedicated_cpu: (CPU_OVERCOMMIT * (COST_MULTIPLIER * exports.GCE_COSTS.cpu)) /
        ACADEMIC_DISCOUNT /
        NONMEMBER_DENSITY,
    disk: (DISK_FACTOR * COST_MULTIPLIER * exports.GCE_COSTS.disk) / ACADEMIC_DISCOUNT,
    always_running: ALWAYS_RUNNING_FACTOR,
    member: NONMEMBER_DENSITY,
};
exports.BASIC = {
    ram: 1,
    cpu: 1,
    disk: 3,
    dedicated_ram: 0,
    dedicated_cpu: 0,
    always_running: 0,
    member: 1,
};
exports.STANDARD = {
    ram: 2,
    cpu: 2,
    dedicated_ram: 0,
    dedicated_cpu: 0,
    disk: 3,
    always_running: 0,
    member: 1,
};
exports.MAX = {
    ram: 16,
    cpu: 3,
    dedicated_ram: 8,
    dedicated_cpu: 2,
    disk: 20,
    always_running: 1,
    member: 1,
};
exports.MIN_QUOTE = 100;
exports.COSTS = {
    user_discount: { academic: ACADEMIC_DISCOUNT, business: 1 },
    sub_discount: { no: 1, monthly: 0.9, yearly: 0.85 },
    online_discount: 0.75,
    min_quote: exports.MIN_QUOTE,
    min_sale: 1,
    custom_cost: exports.CUSTOM_COST,
    custom_max: exports.MAX,
    basic: exports.BASIC,
    standard: exports.STANDARD,
    max: exports.MAX,
};
exports.discount_pct = Math.round((1 - exports.COSTS.user_discount["academic"]) * 100);
exports.discount_monthly_pct = Math.round((1 - exports.COSTS.sub_discount["monthly"]) * 100);
exports.discount_yearly_pct = Math.round((1 - exports.COSTS.sub_discount["yearly"]) * 100);
//# sourceMappingURL=consts.js.map

/***/ }),

/***/ 461649:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.dedicatedPrice = void 0;
// define structure and prices of dedicated resources
// no sustained use discounts
// "quota" ends up in the license's quota field
const billing_1 = __webpack_require__(612134);
const dedicated_1 = __webpack_require__(473009);
function getDuration({ start, end, subscription }) {
    if (start != null && end != null) {
        return (end.getTime() - start.getTime()) / billing_1.ONE_DAY_MS;
    }
    else if (subscription === "yearly") {
        return billing_1.AVG_YEAR_DAYS;
    }
    else {
        return billing_1.AVG_MONTH_DAYS;
    }
}
function dedicatedPrice(info) {
    const { dedicated_vm, dedicated_disk, subscription } = info;
    // at this point, we assume the start/end dates are already
    // set to the start/end time of a day in the user's timezone.
    const start = info.start ? new Date(info.start) : undefined;
    const end = info.end ? new Date(info.end) : undefined;
    const duration = getDuration({ start, end, subscription });
    if (!!dedicated_vm) {
        const info = dedicated_1.PRICES.vms[dedicated_vm.machine];
        if (info == null) {
            throw new Error(`Dedicated VM "${dedicated_vm}" is not defined.`);
        }
        return {
            price: info.price_day * duration,
            monthly: info.price_day * billing_1.AVG_MONTH_DAYS,
        };
    }
    else if (!!dedicated_disk) {
        //console.log(dedicated_disk);
        const diskID = (0, dedicated_1.getDedicatedDiskKey)(dedicated_disk);
        const info = dedicated_1.PRICES.disks[diskID];
        if (info == null) {
            throw new Error(`Dedicated Disk "${dedicated_disk}" is not defined.`);
        }
        return {
            price: info.price_day * duration,
            monthly: info.price_day * billing_1.AVG_MONTH_DAYS,
        };
    }
    else {
        throw new Error("Neither VM nor Disk specified!");
    }
}
exports.dedicatedPrice = dedicatedPrice;
//# sourceMappingURL=dedicated-price.js.map

/***/ }),

/***/ 221460:
/***/ ((__unused_webpack_module, exports) => {

var __webpack_unused_export__;

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
__webpack_unused_export__ = ({ value: true });
exports.CZ = exports.lG = void 0;
function percent_discount({ cost, discounted_cost, }) {
    return Math.round(100 * (1 - discounted_cost / cost));
}
exports.lG = percent_discount;
function money(n, hideCurrency = false) {
    let s = new Intl.NumberFormat(undefined, {
        style: "currency",
        currency: "USD",
        minimumFractionDigits: 0,
    }).format(n);
    const i = s.indexOf(".");
    if (i == s.length - 2) {
        s += "0";
    }
    return (hideCurrency ? "" : "USD ") + s;
}
exports.CZ = money;
//# sourceMappingURL=utils.js.map

/***/ })

};
;