'use strict';

var tslib_es6 = require('../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js');
var jsxRuntime = require('react/jsx-runtime');
var utils = require('@windrun-huaiin/lib/utils');
var server = require('next-intl/server');
var pricePlanInteractive = require('./price-plan-interactive.js');

function PricePlan(_a) {
    return tslib_es6.__awaiter(this, arguments, void 0, function* ({ locale, currency = '$', pricePlanConfig, sectionClassName }) {
        var _b, _c;
        const t = yield server.getTranslations({ locale, namespace: 'pricePlan' });
        const data = {
            title: t('title'),
            subtitle: t('subtitle'),
            billingSwitch: t.raw('billingSwitch'),
            plans: t.raw('plans'),
            currency,
            pricePlanConfig
        };
        // Static data processing for server-side rendering
        const billingOptions = data.pricePlanConfig.billingOptions;
        const prices = data.pricePlanConfig.prices;
        const minPlanFeaturesCount = data.pricePlanConfig.minPlanFeaturesCount;
        // Use default billing for static rendering
        const defaultBilling = billingOptions.find((opt) => opt.key === data.billingSwitch.defaultKey) || billingOptions[0];
        const defaultBillingDisplay = data.billingSwitch.options.find((opt) => opt.key === data.billingSwitch.defaultKey) || data.billingSwitch.options[0];
        // Calculate features count
        const maxFeaturesCount = Math.max(...data.plans.map((plan) => { var _a; return ((_a = plan.features) === null || _a === void 0 ? void 0 : _a.length) || 0; }), minPlanFeaturesCount || 0);
        // Handle card height alignment
        const getFeatureRows = (plan) => {
            const features = plan.features || [];
            const filled = [...features];
            while (filled.length < maxFeaturesCount)
                filled.push(null);
            return filled;
        };
        // Static price render logic for default billing
        function renderPrice(plan, billingKey = data.billingSwitch.defaultKey) {
            const priceValue = prices[plan.key];
            const currentBilling = billingOptions.find((opt) => opt.key === billingKey) || defaultBilling;
            const currentBillingDisplay = data.billingSwitch.options.find((opt) => opt.key === billingKey) || defaultBillingDisplay;
            const billingSubTitle = (currentBillingDisplay === null || currentBillingDisplay === void 0 ? void 0 : currentBillingDisplay.subTitle) || '';
            // Non-numeric (like 'Custom') directly display
            if (typeof priceValue !== 'number' || isNaN(priceValue)) {
                return (jsxRuntime.jsxs("div", { className: "flex flex-col items-start w-full", "data-price-container": plan.key, children: [jsxRuntime.jsx("div", { className: "flex items-end gap-2", children: jsxRuntime.jsx("span", { className: "text-4xl font-extrabold text-gray-900 dark:text-gray-100", "data-price-value": plan.key, children: priceValue }) }), jsxRuntime.jsx("div", { className: "flex items-center gap-2 min-h-[24px] mt-1", children: jsxRuntime.jsx("span", { className: utils.cn('text-xs text-gray-700 dark:text-gray-300 font-medium', plan.showBillingSubTitle === false && 'opacity-0 select-none'), "data-price-subtitle": plan.key, children: plan.showBillingSubTitle === false ? '' : billingSubTitle }) })] }));
            }
            // Numeric price logic
            const originValue = Number(priceValue);
            const discount = currentBilling.discount;
            const hasDiscount = discount !== 0;
            const saleValue = originValue * (1 - discount);
            const formatPrice = (v) => Number(v.toFixed(2)).toString();
            const unit = currentBillingDisplay.unit || '';
            let discountText = '';
            if (hasDiscount && currentBillingDisplay.discountText) {
                discountText = currentBillingDisplay.discountText.replace('{percent}', String(Math.round(Math.abs(discount) * 100)));
            }
            const showNaN = saleValue < 0;
            return (jsxRuntime.jsxs("div", { className: "flex flex-col items-start w-full", "data-price-container": plan.key, children: [jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [jsxRuntime.jsxs("span", { className: "text-4xl font-extrabold text-gray-900 dark:text-gray-100", "data-price-value": plan.key, children: [data.currency, showNaN ? 'NaN' : (hasDiscount ? formatPrice(saleValue) : formatPrice(originValue))] }), jsxRuntime.jsx("span", { className: "text-lg text-gray-700 dark:text-gray-300 font-medium mb-1", "data-price-unit": plan.key, children: unit })] }), jsxRuntime.jsxs("div", { className: "flex items-center gap-2 min-h-[24px] mt-1", children: [hasDiscount && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("span", { className: "text-base text-gray-400 line-through", "data-price-original": plan.key, children: [data.currency, showNaN ? 'NaN' : formatPrice(originValue)] }), discountText && (jsxRuntime.jsx("span", { className: "px-2 py-0.5 text-xs rounded bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200 font-semibold align-middle", "data-price-discount": plan.key, children: discountText }))] })), jsxRuntime.jsx("span", { className: utils.cn('text-xs text-gray-700 dark:text-gray-300 font-medium', plan.showBillingSubTitle === false && 'opacity-0 select-none'), "data-price-subtitle": plan.key, children: plan.showBillingSubTitle === false ? '' : billingSubTitle })] })] }));
        }
        return (jsxRuntime.jsxs("section", { id: "pricing", className: utils.cn("px-4 py-10 md:px-16 md:py-16 mx-auto max-w-7xl scroll-mt-10", sectionClassName), children: [jsxRuntime.jsx("h2", { className: "text-3xl md:text-4xl font-bold text-center mb-3", children: data.title }), jsxRuntime.jsx("p", { className: "text-center text-gray-600 dark:text-gray-400 mb-8 text-base md:text-lg mx-auto", children: data.subtitle }), jsxRuntime.jsxs("div", { className: "flex flex-col items-center", children: [jsxRuntime.jsx("div", { className: "flex items-center relative mb-3", children: jsxRuntime.jsxs("div", { className: "flex bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-700 rounded-full p-1", "data-billing-switch": true, children: [jsxRuntime.jsx("button", { className: utils.cn('min-w-[120px] px-6 py-2 font-medium transition text-lg relative', data.billingSwitch.defaultKey === 'monthly'
                                            ? 'text-white bg-linear-to-r from-purple-400 to-pink-500 hover:from-purple-500 hover:to-pink-600 dark:from-purple-500 dark:to-pink-600 dark:hover:from-purple-600 rounded-full shadow-sm'
                                            : 'text-gray-800 dark:text-gray-200 hover:text-gray-900 dark:hover:text-gray-100 rounded-full'), "data-billing-button": "monthly", type: "button", children: ((_b = data.billingSwitch.options.find((opt) => opt.key === 'monthly')) === null || _b === void 0 ? void 0 : _b.name) || 'Monthly' }), jsxRuntime.jsx("button", { className: utils.cn('min-w-[120px] px-6 py-2 font-medium transition text-lg relative', data.billingSwitch.defaultKey === 'yearly'
                                            ? 'text-white bg-linear-to-r from-purple-400 to-pink-500 hover:from-purple-500 hover:to-pink-600 dark:from-purple-500 dark:to-pink-600 dark:hover:from-purple-600 rounded-full shadow-sm'
                                            : 'text-gray-800 dark:text-gray-200 hover:text-gray-900 dark:hover:text-gray-100 rounded-full'), "data-billing-button": "yearly", type: "button", children: ((_c = data.billingSwitch.options.find((opt) => opt.key === 'yearly')) === null || _c === void 0 ? void 0 : _c.name) || 'Yearly' })] }) }), jsxRuntime.jsx("div", { className: "h-8 flex items-center justify-center mb-3", "data-discount-info": true, children: (() => {
                                const opt = data.billingSwitch.options.find((opt) => opt.key === data.billingSwitch.defaultKey);
                                const bOpt = billingOptions.find((opt) => opt.key === data.billingSwitch.defaultKey);
                                if (!(opt && bOpt && opt.discountText && bOpt.discount !== 0))
                                    return null;
                                return (jsxRuntime.jsx("span", { className: "px-2 py-1 text-xs rounded bg-yellow-100 text-yellow-800 font-semibold align-middle text-center inline-flex items-center justify-center whitespace-nowrap", children: opt.discountText.replace('{percent}', String(Math.round(Math.abs(bOpt.discount) * 100))) }));
                            })() })] }), jsxRuntime.jsx("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-8", children: data.plans.map((plan, _idx) => {
                        var _a, _b, _c;
                        return (jsxRuntime.jsxs("div", { "data-price-plan": plan.key, className: utils.cn('flex flex-col bg-white dark:bg-gray-800/60 rounded-2xl border border-gray-300 dark:border-[#7c3aed40] transition p-8 h-full shadow-sm dark:shadow-none', 'hover:border-2 hover:border-purple-500', 'focus-within:border-2 focus-within:border-purple-500'), style: { minHeight: maxFeaturesCount * 100 }, children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-2 mb-2", children: [jsxRuntime.jsx("span", { className: "text-xl font-bold text-gray-900 dark:text-gray-100", children: plan.title }), plan.titleTags && plan.titleTags.map((tag, i) => (jsxRuntime.jsx("span", { className: "px-2 py-0.5 text-xs rounded bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200 font-semibold align-middle", children: tag }, i)))] }), renderPrice(plan), jsxRuntime.jsx("ul", { className: "flex-1 mb-6 mt-4", children: getFeatureRows(plan).map((feature, i) => (jsxRuntime.jsxs("li", { className: "flex items-center gap-2 mb-2 min-h-[28px]", "data-feature-item": `${plan.key}-${i}`, children: [feature ? (jsxRuntime.jsx("span", { className: "inline-flex items-center justify-center w-5 h-5 rounded-full bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200 mr-1", children: feature.icon ? jsxRuntime.jsx("span", { children: feature.icon }) : jsxRuntime.jsx("span", { className: "font-bold", children: "\u2713" }) })) : (jsxRuntime.jsx("span", { className: "inline-flex items-center justify-center w-5 h-5 rounded-full mr-1", children: "\u00A0" })), feature && feature.tag && (jsxRuntime.jsx("span", { className: "px-1 py-0.5 text-[6px] rounded bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200 font-semibold align-middle", children: feature.tag })), feature ? (jsxRuntime.jsxs("span", { className: "relative group cursor-pointer text-sm text-gray-800 dark:text-gray-200", children: [feature.description, feature.tooltip && (jsxRuntime.jsx("span", { className: "ml-1 align-middle inline-flex", "data-tooltip-trigger": `${plan.key}-${i}`, "data-tooltip-content": feature.tooltip, children: jsxRuntime.jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: jsxRuntime.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }) }))] })) : (jsxRuntime.jsx("span", { children: "\u00A0" }))] }, i))) }), jsxRuntime.jsx("div", { className: "flex-1" }), jsxRuntime.jsx("button", { className: utils.cn('w-full py-2 mt-auto text-white text-base font-bold shadow-lg hover:shadow-xl transition-all duration-300 rounded-full', ((_a = plan.button) === null || _a === void 0 ? void 0 : _a.disabled)
                                        ? 'bg-gray-400 cursor-not-allowed'
                                        : 'bg-linear-to-r from-purple-400 to-pink-500 hover:from-purple-500 hover:to-pink-600 dark:from-purple-500 dark:to-pink-600 dark:hover:from-purple-600 dark:hover:to-pink-700'), disabled: (_b = plan.button) === null || _b === void 0 ? void 0 : _b.disabled, type: "button", "data-plan-button": plan.key, children: ((_c = plan.button) === null || _c === void 0 ? void 0 : _c.text) || '--' })] }, plan.key));
                    }) }), jsxRuntime.jsx(pricePlanInteractive.PricePlanInteractive, { data: data })] }));
    });
}

exports.PricePlan = PricePlan;
