{"version":3,"sources":["../../src/modules/wallet/sdk.ts","../../src/modules/wallet/Balance.tsx","../../src/lib/cn.ts","../../src/primitives/Chip.tsx","../../src/modules/wallet/format-pollen.ts","../../src/modules/wallet/KeyBudget.tsx","../../src/modules/wallet/KeyExpiry.tsx","../../src/modules/wallet/KeyModels.tsx","../../src/modules/wallet/KeyPrefix.tsx"],"sourcesContent":["export { Balance, type BalanceProps } from \"./Balance.tsx\";\nexport { KeyBudget, type KeyBudgetProps } from \"./KeyBudget.tsx\";\nexport { KeyExpiry, type KeyExpiryProps } from \"./KeyExpiry.tsx\";\nexport { KeyModels, type KeyModelsProps } from \"./KeyModels.tsx\";\nexport { KeyPrefix, type KeyPrefixProps } from \"./KeyPrefix.tsx\";\n","import { useAccountBalance, useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\nimport { formatPollen } from \"./format-pollen.ts\";\n\nexport type BalanceProps = { className?: string };\n\n/** Renders the logged-in user's pollen balance. `null` until loaded. */\nexport function Balance({ className }: BalanceProps = {}) {\n    const { isLoggedIn } = useAuthState();\n    const { data: balance } = useAccountBalance({ enabled: isLoggedIn });\n    if (!isLoggedIn || balance == null) return null;\n    return (\n        <Chip\n            data-polli=\"balance\"\n            className={cn(\"polli:tabular-nums\", className)}\n        >\n            {formatPollen(balance.balance)} pollen\n        </Chip>\n    );\n}\n","import { clsx } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({ prefix: \"polli\" });\n\n/** Internal class merge for polli:-prefixed package primitive classes. */\nexport function cn(...inputs: (string | undefined | null | false)[]) {\n    return twMerge(clsx(...inputs));\n}\n","import type { ComponentPropsWithoutRef, FC } from \"react\";\nimport { cn } from \"../lib/cn.ts\";\nimport type { ThemeName } from \"../theme.ts\";\n\n/** Semantic chip labels for status and metadata badges. */\ntype ChipIntent =\n    | \"news\"\n    | \"alpha\"\n    | \"neutral\"\n    | \"success\"\n    | \"warning\"\n    | \"danger\";\n\nconst chipSizes = {\n    sm: \"polli:px-2 polli:py-0.5 polli:text-xs\",\n    md: \"polli:px-2.5 polli:py-0.5 polli:text-sm\",\n    lg: \"polli:px-3 polli:py-1 polli:text-sm\",\n} as const;\n\nconst intentClasses: Record<ChipIntent, string> = {\n    news: \"polli:bg-[oklch(0.935_0.06_158)] polli:text-[oklch(0.46_0.13_158)]\",\n    alpha: \"polli:bg-[oklch(0.93_0.06_300)] polli:text-[oklch(0.42_0.18_300)]\",\n    neutral:\n        \"polli:border polli:border-gray-400/70 polli:bg-gray-100/80 polli:text-gray-900\",\n    success:\n        \"polli:border polli:border-intent-success-border polli:bg-intent-success-bg-light polli:text-intent-success-text\",\n    warning:\n        \"polli:border polli:border-intent-warning-border polli:bg-intent-warning-bg-light polli:text-intent-warning-text\",\n    danger: \"polli:border polli:border-intent-danger-border polli:bg-intent-danger-bg-light polli:text-intent-danger-text\",\n};\n\nexport type ChipProps = ComponentPropsWithoutRef<\"span\"> & {\n    /** Override the cascade theme for this chip's subtree. */\n    theme?: ThemeName;\n    /** Semantic intent. Wins over `theme` when set. */\n    intent?: ChipIntent;\n    size?: keyof typeof chipSizes;\n};\n\n// Static, rectangular colored container. Round shapes are reserved for buttons.\n// Reads `bg-theme-bg-active` / `text-theme-text-strong` from the cascade unless\n// `intent` is set (semantic, theme-independent).\nexport const Chip: FC<ChipProps> = ({\n    theme,\n    intent,\n    size = \"md\",\n    className,\n    children,\n    ...rest\n}) => {\n    const intentClass = intent\n        ? intentClasses[intent]\n        : \"polli:bg-theme-bg-active polli:text-theme-text-strong\";\n    return (\n        <span\n            {...rest}\n            data-theme={theme}\n            className={cn(\n                \"polli:inline-flex polli:shrink-0 polli:items-center polli:gap-1 polli:rounded-lg polli:font-medium polli:leading-normal\",\n                chipSizes[size],\n                intentClass,\n                className,\n            )}\n        >\n            {children}\n        </span>\n    );\n};\n","// 5-digit budget for pollen display. Integer takes its space, decimals fill\n// the remainder (capped at 4), floor toward -infinity, trailing zeros stripped.\n// Integers needing >=6 digits switch to compact (K/M/B, 3 sig figs).\n// Decimal point and minus sign do not count toward the budget.\n\nconst BUDGET = 5;\nconst MAX_DECIMALS = 4;\nconst COMPACT_THRESHOLD = 100_000;\n\nfunction floorTo(value: number, decimals: number): number {\n    const factor = 10 ** decimals;\n    return Math.floor(value * factor) / factor;\n}\n\nfunction formatCompact(value: number): string {\n    const abs = Math.abs(value);\n    const sign = value < 0 ? \"-\" : \"\";\n    const [unit, scale] =\n        abs >= 1e9\n            ? ([\"B\", 1e9] as const)\n            : abs >= 1e6\n              ? ([\"M\", 1e6] as const)\n              : ([\"K\", 1e3] as const);\n    const ratio = abs / scale;\n    const intDigits = Math.max(1, Math.floor(Math.log10(ratio)) + 1);\n    const decimals = Math.max(0, 3 - intDigits);\n    const floored = floorTo(ratio, decimals);\n    return `${sign}${Number(floored.toFixed(decimals)).toString()}${unit}`;\n}\n\nexport function formatPollen(value: number): string {\n    if (!Number.isFinite(value) || value === 0) return \"0\";\n\n    const abs = Math.abs(value);\n\n    if (abs >= COMPACT_THRESHOLD) return formatCompact(value);\n\n    const intDigits = abs >= 1 ? Math.floor(Math.log10(abs)) + 1 : 1;\n    const decimals = Math.min(MAX_DECIMALS, Math.max(0, BUDGET - intDigits));\n    const floored = floorTo(value, decimals);\n    if (floored === 0) return \"0\";\n    return Number(floored.toFixed(decimals)).toString();\n}\n","import { useAccountKey, useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\nimport { formatPollen } from \"./format-pollen.ts\";\n\nexport type KeyBudgetProps = { className?: string };\n\n/** Renders the current delegated key's remaining budget. `null` until loaded. */\nexport function KeyBudget({ className }: KeyBudgetProps = {}) {\n    const { isLoggedIn } = useAuthState();\n    const { data: key } = useAccountKey({ enabled: isLoggedIn });\n    const budget = key?.pollenBudget;\n    if (!isLoggedIn || budget == null) return null;\n    return (\n        <Chip\n            data-polli=\"key-budget\"\n            className={cn(\"polli:tabular-nums\", className)}\n        >\n            {formatPollen(budget)} pollen\n        </Chip>\n    );\n}\n","import { useAccountKey, useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\n\nexport type KeyExpiryProps = { className?: string };\n\n/** Renders the current delegated key's expiry date (YYYY-MM-DD) or `null`. */\nexport function KeyExpiry({ className }: KeyExpiryProps = {}) {\n    const { isLoggedIn } = useAuthState();\n    const { data: key } = useAccountKey({ enabled: isLoggedIn });\n    if (!isLoggedIn || !key?.expiresAt) return null;\n    return (\n        <Chip\n            data-polli=\"key-expiry\"\n            className={cn(\"polli:tabular-nums\", className)}\n        >\n            {key.expiresAt.slice(0, 10)}\n        </Chip>\n    );\n}\n","import { useAccountKey, useAuthState } from \"@pollinations/sdk/react\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\n\nexport type KeyModelsProps = { className?: string };\n\n/** Renders \"All models\" or \"N models\" for the current key. `null` until loaded. */\nexport function KeyModels({ className }: KeyModelsProps = {}) {\n    const { isLoggedIn } = useAuthState();\n    const { data: key } = useAccountKey({ enabled: isLoggedIn });\n    if (!isLoggedIn || !key) return null;\n    const models = key.permissions?.models ?? null;\n    const text =\n        models === null\n            ? \"All models\"\n            : `${models.length} model${models.length === 1 ? \"\" : \"s\"}`;\n    return (\n        <Chip data-polli=\"key-models\" className={className}>\n            {text}\n        </Chip>\n    );\n}\n","import { useAuthState } from \"@pollinations/sdk/react\";\nimport { cn } from \"../../lib/cn.ts\";\nimport { Chip } from \"../../primitives/Chip.tsx\";\n\nexport type KeyPrefixProps = { className?: string };\n\n/** Renders the first 7 chars of the API key followed by bullets. `null` when logged out. */\nexport function KeyPrefix({ className }: KeyPrefixProps = {}) {\n    const { apiKey } = useAuthState();\n    if (!apiKey) return null;\n    return (\n        <Chip\n            data-polli=\"key-prefix\"\n            className={cn(\"polli:font-mono polli:select-none\", className)}\n        >\n            {apiKey.slice(0, 7)}\n            {\"••••••••\"}\n        </Chip>\n    );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAgD;;;ACAhD,kBAAqB;AACrB,4BAAoC;AAEpC,IAAM,cAAU,2CAAoB,EAAE,QAAQ,QAAQ,CAAC;AAGhD,SAAS,MAAM,QAA+C;AACjE,SAAO,YAAQ,kBAAK,GAAG,MAAM,CAAC;AAClC;;;AC8CQ;AAzCR,IAAM,YAAY;AAAA,EACd,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACR;AAEA,IAAM,gBAA4C;AAAA,EAC9C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SACI;AAAA,EACJ,SACI;AAAA,EACJ,SACI;AAAA,EACJ,QAAQ;AACZ;AAaO,IAAM,OAAsB,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,GAAG;AACP,MAAM;AACF,QAAM,cAAc,SACd,cAAc,MAAM,IACpB;AACN,SACI;AAAA,IAAC;AAAA;AAAA,MACI,GAAG;AAAA,MACJ,cAAY;AAAA,MACZ,WAAW;AAAA,QACP;AAAA,QACA,UAAU,IAAI;AAAA,QACd;AAAA,QACA;AAAA,MACJ;AAAA,MAEC;AAAA;AAAA,EACL;AAER;;;AC9DA,IAAM,SAAS;AACf,IAAM,eAAe;AACrB,IAAM,oBAAoB;AAE1B,SAAS,QAAQ,OAAe,UAA0B;AACtD,QAAM,SAAS,MAAM;AACrB,SAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACxC;AAEA,SAAS,cAAc,OAAuB;AAC1C,QAAM,MAAM,KAAK,IAAI,KAAK;AAC1B,QAAM,OAAO,QAAQ,IAAI,MAAM;AAC/B,QAAM,CAAC,MAAM,KAAK,IACd,OAAO,MACA,CAAC,KAAK,GAAG,IACV,OAAO,MACJ,C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,IAAAC,sBAAA;AAJD,SAAS,UAAU,EAAE,UAAU,IAAoB,CAAC,GAAG;AAC1D,QAAM,EAAE,OAAO,QAAI,4BAAa;AAChC,MAAI,CAAC,OAAQ,QAAO;AACpB,SACI;AAAA,IAAC;AAAA;AAAA,MACG,cAAW;AAAA,MACX,WAAW,GAAG,qCAAqC,SAAS;AAAA,MAE3D;AAAA,eAAO,MAAM,GAAG,CAAC;AAAA,QACjB;AAAA;AAAA;AAAA,EACL;AAER;","names":["import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime","import_react","import_jsx_runtime"]}