import { CSSEngineResult } from "@vitus-labs/core";
import { ComponentType, FC, ReactNode } from "react";
//#region src/ThemeProvider.d.ts
/**
 * Extensible theme interface. Consumers can augment this via module
 * declaration merging for full strict types:
 *
 *   declare module '@vitus-labs/styler' {
 *     interface DefaultTheme {
 *       colors: { primary: string; secondary: string }
 *       spacing: (n: number) => string
 *     }
 *   }
 */
interface DefaultTheme {}
type Theme = DefaultTheme & Record<string, unknown>;
/** Hook to read the current theme from the nearest ThemeProvider. */
export declare const useTheme: <T extends Theme = Theme>() => T;
/** Provides a theme object to all nested styled components via React context. */
export declare const ThemeProvider: FC<{
  /** A theme object, or a function receiving the outer theme and returning the new one. */
  theme: Theme | ((outer: Theme) => Theme);
  children: ReactNode;
}>;
//#endregion
//#region src/resolve.d.ts
type Interpolation = string | number | boolean | null | undefined | CSSResult | CSSEngineResult | Interpolation[] | ((props: {
  theme?: DefaultTheme & Record<string, any>;
  [key: string]: any;
}) => Interpolation);
/**
 * Lazy representation of a `css` tagged template. Stores the raw template
 * strings and interpolation values without resolving them. Resolution is
 * deferred until a styled component renders (or until explicitly resolved).
 */
declare class CSSResult {
  readonly strings: TemplateStringsArray;
  readonly values: Interpolation[];
  /**
   * Memoized result of `isDynamic(this)`. Populated on first access from
   * `shared.ts#isDynamic` (or from `resolveValue` below on lazy populate).
   * Declared without an initializer — V8 sees `undefined` for unassigned
   * properties anyway, and skipping the `= undefined` write keeps the
   * constructor's hidden-class transition shorter (one fewer store).
   */
  _isDynamic: boolean | null | undefined;
  /**
   * Memoized resolved CSS string for static CSSResults — populated by
   * `resolveValue` the first time a known-static nested CSSResult is
   * resolved. Safe because props don't affect the output when there are
   * no function interpolations. Skipped for dynamic CSSResults (the
   * resolved string depends on props each call).
   */
  _staticResolved: string | undefined;
  constructor(strings: TemplateStringsArray, values: Interpolation[]);
  /** Resolve with empty props — useful for static templates, testing, and debugging. */
  toString(): string;
}
//#endregion
//#region src/css.d.ts
/**
 * Tagged template function for CSS. Captures the template strings and
 * interpolation values as a lazy CSSResult — resolution is deferred
 * until a styled component renders.
 *
 * Works as both a tagged template (`css\`...\``) and a regular function
 * call (`css(...args)`) since tagged templates are syntactic sugar for
 * function calls with (TemplateStringsArray, ...values).
 */
export declare const css: (strings: TemplateStringsArray, ...values: Interpolation[]) => CSSResult;
//#endregion
//#region src/globalStyle.d.ts
export declare const createGlobalStyle: (strings: TemplateStringsArray, ...values: Interpolation[]) => FC | {
  (props: Record<string, any>): import("react").ReactElement<{
    href: string;
    precedence: string;
  }, string | import("react").JSXElementConstructor<any>> | null;
  displayName: string;
};
//#endregion
//#region src/keyframes.d.ts
declare class KeyframesResult {
  readonly name: string;
  constructor(strings: TemplateStringsArray, values: Interpolation[]);
  /** Returns the animation name when used in string context. */
  toString(): string;
}
export declare const keyframes: (strings: TemplateStringsArray, ...values: Interpolation[]) => KeyframesResult;
//#endregion
//#region src/sheet.d.ts
interface StyleSheetOptions {
  /** Maximum number of cached rules before eviction (default: 10000). */
  maxCacheSize?: number;
  /** CSS @layer name to wrap scoped rules in. */
  layer?: string;
}
declare class StyleSheet {
  private cache;
  private insertCache;
  private prepareCache;
  private prepareHotA;
  private prepareHotB;
  private missKey;
  private missClass;
  private insertHotA;
  private insertHotB;
  private sheet;
  private ssrBuffer;
  private kf;
  private isSSR;
  private maxCacheSize;
  private layer;
  private globals;
  constructor(options?: StyleSheetOptions);
  private mount;
  /**
   * Populate the dedup cache from React 19's `<style data-precedence data-href>`
   * tags. The `data-href` is the same shape we'd compute client-side
   * (`vl-<hash>` for component styles, `g-<hash>` for globals), so a Map
   * pre-population is sufficient — no need to re-parse the cssText.
   */
  private hydrateFromPrecedenceTags;
  /** Extract className from a selector like ".vl-abc" or ".vl-abc.vl-abc" → "vl-abc" */
  private extractClassName;
  /** Parse existing rules from SSR-rendered <style> tag into cache. */
  private hydrateFromTag;
  /**
   * Evict oldest entries from the cssText-keyed lookup caches
   * (`insertCache`, `prepareCache`) when they exceed maxCacheSize.
   *
   * `cache` is deliberately NOT evicted: it is the set of rules that are
   * already in the DOM (className → marker). Evicting it made a later
   * insert of the same CSS re-append the rule — duplicating it, moving it
   * to the end of the cascade, and growing the DOM sheet without bound.
   * Its entries are tiny (short className key + marker value), and the
   * DOM sheet it mirrors is never pruned either.
   */
  private evictIfNeeded;
  /**
   * Extract nested at-rules (@media, @supports, @container) from CSS text
   * and wrap their content in the given selector as separate top-level rules.
   *
   * This converts:
   *   "color:red; @media (min-width:600px){font-size:2rem;}"
   * Into:
   *   { base: "color:red;", atRules: ["@media (min-width:600px){.vl-abc{font-size:2rem;}}"] }
   *
   * Non-at-rule brace blocks (like &:hover{...}) are preserved in the base CSS.
   */
  private splitAtRules;
  /**
   * Compute a className from CSS text without injecting (pure function for render phase).
   * Used with useInsertionEffect pattern: compute class during render, inject in effect.
   */
  getClassName(cssText: string, boost?: boolean): string;
  /**
   * Insert CSS rules for a component. Returns the class name (deterministic, hash-based).
   * Deduplicates: same CSS text always produces the same class name and
   * the rules are only injected once.
   *
   * Nested @media/@supports/@container blocks are automatically extracted
   * into separate top-level rules (matching styled-components/Emotion behavior).
   *
   * When `boost` is true, the selector is doubled (`.vl-abc.vl-abc`)
   * to raise specificity from (0,1,0) to (0,2,0). This ensures the
   * rule wins over single-class selectors regardless of source order.
   */
  insert(cssText: string, boost?: boolean): string;
  /** Insert a @keyframes rule. Deduplicates by animation name. */
  insertKeyframes(name: string, body: string): void;
  /**
   * Split CSS text into individual top-level rules.
   * CSSStyleSheet.insertRule() only accepts one rule at a time,
   * so multi-rule CSS must be split before injection.
   */
  private splitRules;
  /**
   * Server: the `@keyframes` rules referenced by `cssText` (empty when none).
   * Keyframes are registered at module load, outside any render, so without
   * this they never reach the SSR HTML.
   */
  keyframesFor(cssText: string): string;
  /** Insert pre-split global rules, keeping @import/@charset ahead of everything else. */
  private insertGlobalRules;
  /** Insert global CSS rules (no wrapper selector). Deduplicates by hash. */
  insertGlobal(cssText: string): void;
  /**
   * Mount-scoped global CSS (used by createGlobalStyle on the client).
   * Ref-counted per cssText: the first acquire inserts the rules, the last
   * `releaseGlobal` removes them again — so unmounting a global style, or a
   * dynamic one changing value (A → B → A), never leaves stale rules in
   * effect. Rules already present from SSR hydration are left alone.
   * Returns the key to pass to `releaseGlobal`.
   */
  acquireGlobal(cssText: string, key?: string): string;
  /** Release a global acquired via `acquireGlobal`; removes its rules at zero. */
  releaseGlobal(key: string): void;
  /**
   * Returns collected CSS for SSR as a complete `<style>` tag string.
   *
   * NOTE: With the default React 19 `<style precedence>` SSR path, this
   * buffer is **empty** — components emit their own precedence tags inline,
   * which React collects and dedupes automatically. This API is retained as
   * an opt-in "manual mode" for callers that explicitly push rules into the
   * buffer (e.g. legacy SSR pipelines via direct `sheet.insert(cssText)`
   * calls outside of render).
   */
  getStyleTag(): string;
  /**
   * Returns collected CSS rules as a raw string (useful for streaming SSR).
   * See `getStyleTag` for caveats — empty unless rules were pushed manually.
   */
  getStyles(): string;
  /** Invalidate the 2-slot LRU hot caches in front of insert/prepare. */
  private clearHotSlots;
  /** Reset SSR buffer and cache (call between server requests). */
  reset(): void;
  /** Clear the dedup cache. Useful for HMR / dev-time reloads. */
  clearCache(): void;
  /**
   * Full cleanup: clear cache and remove all CSS rules from the DOM.
   * Intended for HMR / dev-time reloads where stale styles must be purged.
   * Also fires every callback registered via `onClear` so other modules
   * (e.g. styled.ts's static-component cache) can purge their own state.
   *
   *   if (import.meta.hot) {
   *     import.meta.hot.accept(() => sheet.clearAll())
   *   }
   */
  clearAll(): void;
  /**
   * Compute className and full CSS rule text without injecting.
   * Used with React 19's `<style precedence>` for component-level injection.
   * Result is cached so repeated calls (per render until cssText changes) skip
   * the hash + splitAtRules + join work.
   */
  prepare(cssText: string, boost?: boolean): {
    className: string;
    rules: string;
  };
  /** Check if a className is already in the cache. O(1) Map lookup. */
  has(className: string): boolean;
  /** Current number of cached rules. */
  get cacheSize(): number;
}
/** Default singleton sheet for client-side use. */
export declare const sheet: StyleSheet;
/**
 * Factory for standalone StyleSheet instances, driven manually via
 * `insert()` / `getStyleTag()`. styled(), createGlobalStyle, keyframes and
 * useCSS always write to the shared `sheet` above, never to an instance
 * created here (SSR needs none: components emit `<style precedence>`).
 *
 *   const manual = createSheet({ layer: 'components' })
 *   manual.insert('color: red;')
 *   const html = manual.getStyleTag()
 *   manual.reset()
 */
export declare const createSheet: (options?: StyleSheetOptions) => StyleSheet;
//#endregion
//#region src/styled.d.ts
type Tag = string | ComponentType<any>;
interface StyledOptions {
  /** Custom prop filter. Return true to forward the prop to the DOM element. */
  shouldForwardProp?: (prop: string) => boolean;
  /**
   * Double the class selector (`.vl-abc.vl-abc`) to raise specificity
   * from (0,1,0) to (0,2,0). Ensures this component's styles override
   * inner library components regardless of CSS source order.
   */
  boost?: boolean;
}
/** Factory function: styled(tag) returns a tagged template function. */
declare const styledFactory: (tag: Tag, options?: StyledOptions) => (strings: TemplateStringsArray, ...values: Interpolation[]) => ComponentType<any>;
export declare const styled: typeof styledFactory & Record<string, (strings: TemplateStringsArray, ...values: Interpolation[]) => any>;
//#endregion
//#region src/useCSS.d.ts
export declare function useCSS(template: CSSResult, props?: Record<string, any>, boost?: boolean): string;
//#endregion
export type { CSSResult, DefaultTheme, Interpolation, StyleSheetOptions, StyledOptions };