"use client";
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useLicenseOptional } from "./LicenseContext";
import { LicenseFeatures } from "./types";
/**
 * Component that conditionally renders children based on license features.
 *
 * @example
 * // Single feature check
 * <FeatureGate feature="ai">
 *   <AIAssistantPanel />
 * </FeatureGate>
 *
 * @example
 * // Multiple features (any)
 * <FeatureGate feature={["ai", "translation"]}>
 *   <AdvancedTools />
 * </FeatureGate>
 *
 * @example
 * // Multiple features (all required)
 * <FeatureGate feature={["ai", "reviews"]} requireAll>
 *   <AIReviewsFeature />
 * </FeatureGate>
 *
 * @example
 * // With fallback
 * <FeatureGate feature="page-wizard" fallback={<UpgradePrompt />}>
 *   <PageWizard />
 * </FeatureGate>
 */
export function FeatureGate({ feature, requireAll = false, children, fallback = null, allowWhenNoContext = false, }) {
    const license = useLicenseOptional();
    // If no license context and we allow it, show children
    if (!license && allowWhenNoContext) {
        return _jsx(_Fragment, { children: children });
    }
    // If no license context, don't show gated content
    if (!license) {
        return _jsx(_Fragment, { children: fallback });
    }
    const features = Array.isArray(feature) ? feature : [feature];
    let hasAccess;
    if (requireAll) {
        hasAccess = features.every((f) => license.hasFeature(f));
    }
    else {
        hasAccess = features.some((f) => license.hasFeature(f));
    }
    return _jsx(_Fragment, { children: hasAccess ? children : fallback });
}
/**
 * Hook to check if a feature is available
 *
 * @example
 * const canUseAI = useFeature("ai");
 * const canUseAdvanced = useFeature(["ai", "translation"], { requireAll: true });
 */
export function useFeature(feature, options) {
    const license = useLicenseOptional();
    if (!license) {
        return false;
    }
    const features = Array.isArray(feature) ? feature : [feature];
    if (options?.requireAll) {
        return features.every((f) => license.hasFeature(f));
    }
    return features.some((f) => license.hasFeature(f));
}
/**
 * Hook to get the current license status for display purposes
 */
export function useLicenseStatus() {
    const license = useLicenseOptional();
    return {
        isLicensed: license?.isLicensed ?? false,
        licenseType: license?.licenseType ?? null,
        features: license?.features ?? [],
        daysRemaining: license?.daysRemaining,
        expiresAt: license?.expiresAt,
        isLoading: license?.isLoading ?? true,
    };
}
export function UpgradePrompt({ feature, className = "" }) {
    const featureNames = {
        [LicenseFeatures.AI]: "AI Assistant",
        [LicenseFeatures.TRANSLATION]: "Translation",
        [LicenseFeatures.PAGE_WIZARD]: "Page Wizard",
        [LicenseFeatures.REVIEWS]: "Reviews & Feedback",
        [LicenseFeatures.FULL]: "Full Access",
    };
    const displayName = featureNames[feature] || feature;
    return (_jsx("div", { className: `border-feedback-orange bg-feedback-orange-light rounded-lg border p-4 ${className}`, children: _jsxs("div", { className: "flex items-start gap-3", children: [_jsx("div", { className: "flex-shrink-0", children: _jsx("svg", { className: "text-feedback-orange h-5 w-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1, d: "M12 15v2m0 0v2m0-2h2m-2 0H10m5-6a3 3 0 11-6 0 3 3 0 016 0z" }) }) }), _jsxs("div", { className: "flex-1", children: [_jsxs("h4", { className: "text-feedback-orange text-sm font-medium", children: [displayName, " requires an upgrade"] }), _jsx("p", { className: "text-feedback-orange mt-1 text-sm", children: "This feature is not available with your current license. Contact sales to upgrade." })] })] }) }));
}
/**
 * Badge showing the current license status
 */
export function LicenseBadge() {
    const { isLicensed, licenseType, daysRemaining, isLoading } = useLicenseStatus();
    if (isLoading) {
        return null;
    }
    if (!isLicensed) {
        return (_jsx("span", { className: "rounded-badge bg-feedback-red-light badge-pad text-2xs text-feedback-red inline-flex items-center font-medium", children: "Unlicensed" }));
    }
    if (licenseType === "trial") {
        const isExpiringSoon = daysRemaining !== undefined && daysRemaining <= 7;
        return (_jsxs("span", { className: `rounded-badge badge-pad text-2xs inline-flex items-center font-medium ${isExpiringSoon
                ? "bg-feedback-orange-light text-feedback-orange"
                : "bg-feedback-blue-light text-feedback-blue"}`, children: ["Trial", daysRemaining !== undefined ? ` (${daysRemaining}d)` : ""] }));
    }
    return (_jsx("span", { className: "rounded-badge bg-feedback-green-light badge-pad text-2xs text-feedback-green inline-flex items-center font-medium", children: "Licensed" }));
}
//# sourceMappingURL=FeatureGate.js.map