import { EntryStrategy } from '@qwik.dev/optimizer';
import { Optimizer } from '@qwik.dev/optimizer';
import { OptimizerOptions } from '@qwik.dev/optimizer';
import type { Plugin as Plugin_2 } from 'vite';
import { TransformModule } from '@qwik.dev/optimizer';
import { TransformModuleInput } from '@qwik.dev/optimizer';

/**
 * A function that returns a map of bundle names to their dependencies.
 *
 * @public
 */
export declare type BundleGraphAdder = (manifest: QwikManifest) => Record<string, {
    imports?: string[];
    dynamicImports?: string[];
}>;

/**
 * Use `__EXPERIMENTAL__.x` to check if feature `x` is enabled. It will be replaced with `true` or
 * `false` via an exact string replacement.
 *
 * Add experimental features to this enum definition.
 *
 * @public
 */
export declare enum ExperimentalFeatures {
    /** Enable the Each keyed-list primitive */
    each = "each",
    /** Enable the Suspense fallback primitive */
    suspense = "suspense",
    /** Enable the Valibot form validation */
    valibot = "valibot",
    /** Disable SPA navigation handler in Qwik Router */
    noSPA = "noSPA",
    /** Enable the ability to use the Qwik Insights vite plugin and `<Insights/>` component */
    insights = "insights"
}

/** @public */
export declare interface GlobalInjections {
    tag: string;
    attributes?: {
        [key: string]: string;
    };
    location: 'head' | 'body';
}

declare interface NormalizedQwikPluginOptions extends Omit<Required<QwikPluginOptions>, 'input' | 'vendorRoots' | 'srcInputs' | 'experimental'> {
    input: string[] | {
        [entry: string]: string;
    } | undefined;
    experimental: Record<keyof typeof ExperimentalFeatures, boolean> | undefined;
}

/**
 * Workaround to make the api be defined in the type.
 *
 * @internal
 */
declare type P<T> = Plugin_2<T> & {
    api: T;
    config: Extract<Plugin_2<T>['config'], Function>;
};

/** @public */
export declare interface QwikAsset {
    /** Name of the asset */
    name: string | undefined;
    /** Size of the asset */
    size: number;
}

/** @public */
export declare type QwikBuildMode = 'production' | 'development';

/** @public */
export declare type QwikBuildTarget = 'client' | 'ssr' | 'lib' | 'test';

/** @public */
export declare interface QwikBundle {
    /** Size of the bundle */
    size: number;
    /** Total size of this bundle's static import graph */
    total: number;
    /** Interactivity score of the bundle */
    interactivity?: number;
    /** Symbols in the bundle */
    symbols?: string[];
    /** Direct imports */
    imports?: string[];
    /** Dynamic imports */
    dynamicImports?: string[];
    /** Source files of the bundle */
    origins?: string[];
}

/**
 * Bundle graph.
 *
 * Format: [ 'bundle-a.js', 3, 5 // Depends on 'bundle-b.js' and 'bundle-c.js' 'bundle-b.js', 5, //
 * Depends on 'bundle-c.js' 'bundle-c.js', ]
 *
 * @public
 */
export declare type QwikBundleGraph = Array<string | number>;

/**
 * The metadata of the build. One of its uses is storing where QRL symbols are located.
 *
 * @public
 */
export declare interface QwikManifest {
    /** Content hash of the manifest, if this changes, the code changed */
    manifestHash: string;
    /** QRL symbols */
    symbols: {
        [symbolName: string]: QwikSymbol;
    };
    /** Where QRLs are located. The key is the symbol name, the value is the bundle fileName */
    mapping: {
        [symbolName: string]: string;
    };
    /**
     * All code bundles, used to know the import graph. The key is the bundle fileName relative to
     * "build/"
     */
    bundles: {
        [fileName: string]: QwikBundle;
    };
    /** All assets. The key is the fileName relative to the rootDir */
    assets?: {
        [fileName: string]: QwikAsset;
    };
    /** All bundles in a compact graph format with probabilities */
    bundleGraph?: QwikBundleGraph;
    /** The bundle graph fileName */
    bundleGraphAsset?: string;
    /** The preloader bundle fileName */
    preloader?: string;
    /** The Qwik core bundle fileName */
    core?: string;
    /** The Qwik loader bundle fileName */
    qwikLoader?: string;
    /** CSS etc to inject in the document head */
    injections?: GlobalInjections[];
    /** The version of the manifest */
    version: string;
    /** The options used to build the manifest */
    options?: {
        target?: string;
        buildMode?: string;
        entryStrategy?: {
            type: EntryStrategy['type'];
        };
    };
    /** The platform used to build the manifest */
    platform?: {
        [name: string]: string;
    };
}

/** @public */
declare interface QwikPluginDevTools {
    /**
     * Validates image sizes for CLS issues during development. In case of issues, provides you with a
     * correct image size resolutions. If set to `false`, image dev tool will be disabled.
     *
     * Default `true`
     */
    imageDevTools?: boolean | true;
    /**
     * Press-hold the defined keys to enable qwik dev inspector. By default the behavior is activated
     * by pressing the left or right `Alt` key. If set to `false`, qwik dev inspector will be
     * disabled.
     *
     * Valid values are `KeyboardEvent.code` values. Please note that the 'Left' and 'Right' suffixes
     * are ignored.
     */
    clickToSource?: string[] | false;
    /**
     * Enable HMR for Qwik components. When enabled, editing a component file re-renders only that
     * component without a full page reload, preserving client state.
     *
     * Set this to `false` for full page reloads on component edits.
     *
     * Default `true`
     */
    hmr?: boolean;
}

declare interface QwikPluginOptions {
    csr?: boolean;
    buildMode?: QwikBuildMode;
    debug?: boolean;
    entryStrategy?: EntryStrategy;
    rootDir?: string;
    tsconfigFileNames?: string[];
    /** @deprecated No longer used */
    vendorRoots?: string[];
    manifestOutput?: ((manifest: QwikManifest) => Promise<void> | void) | null;
    manifestInput?: QwikManifest | null;
    manifestInputPath?: string | null;
    input?: string[] | string | {
        [entry: string]: string;
    };
    outDir?: string;
    ssrOutDir?: string;
    clientOutDir?: string;
    assetsDir?: string;
    srcDir?: string | null;
    scope?: string | null;
    /** @deprecated Not used */
    srcInputs?: TransformModuleInput[] | null;
    sourcemap?: boolean;
    resolveQwikBuild?: boolean;
    target?: QwikBuildTarget;
    transformedModuleOutput?: ((transformedModules: TransformModule[]) => Promise<void> | void) | null;
    devTools?: QwikPluginDevTools;
    /**
     * Inline styles up to a certain size (in bytes) instead of using a separate file.
     *
     * Default: 20kb (20,000bytes)
     */
    inlineStylesUpToBytes?: number;
    /**
     * Run eslint on the source files for the ssr build or dev server. This can slow down startup on
     * large projects. Defaults to `true`
     */
    lint?: boolean;
    /**
     * Experimental features. These can come and go in patch releases, and their API is not guaranteed
     * to be stable between releases.
     */
    experimental?: (keyof typeof ExperimentalFeatures)[];
}

/** @public */
export declare function qwikRollup(qwikRollupOpts?: QwikRollupPluginOptions): any;

/** @public */
export declare interface QwikRollupPluginOptions {
    csr?: boolean;
    /**
     * Build `production` or `development`.
     *
     * Default `development`
     */
    buildMode?: QwikBuildMode;
    /**
     * Target `client` or `ssr`.
     *
     * Default `client`
     */
    target?: QwikBuildTarget;
    /**
     * Prints verbose Qwik plugin debug logs.
     *
     * Default `false`
     */
    debug?: boolean;
    /**
     * The Qwik entry strategy to use while building for production. During development the type is
     * always `segment`.
     *
     * Default `{ type: "smart" }`)
     */
    entryStrategy?: EntryStrategy;
    /**
     * The source directory to find all the Qwik components. Since Qwik does not have a single input,
     * the `srcDir` is used to recursively find Qwik files.
     *
     * Default `src`
     */
    srcDir?: string;
    /**
     * Alternative to `srcDir`, where `srcInputs` is able to provide the files manually. This option
     * is useful for an environment without a file system, such as a webworker.
     *
     * Default: `null`
     */
    srcInputs?: TransformModuleInput[] | null;
    /**
     * The root of the application, which is commonly the same directory as `package.json` and
     * `rollup.config.js`.
     *
     * Default `process.cwd()`
     */
    rootDir?: string;
    /**
     * The client build will create a manifest and this hook is called with the generated build data.
     *
     * Default `undefined`
     */
    manifestOutput?: (manifest: QwikManifest) => Promise<void> | void;
    /**
     * The SSR build requires the manifest generated during the client build. The `manifestInput`
     * option can be used to manually provide a manifest.
     *
     * Default `undefined`
     */
    manifestInput?: QwikManifest;
    optimizerOptions?: OptimizerOptions;
    /**
     * Hook that's called after the build and provides all of the transformed modules that were used
     * before bundling.
     */
    transformedModuleOutput?: ((transformedModules: TransformModule[]) => Promise<void> | void) | null;
    /**
     * Run eslint on the source files for the ssr build or dev server. This can slow down startup on
     * large projects. Defaults to `true`
     */
    lint?: boolean;
    /**
     * Experimental features. These can come and go in patch releases, and their API is not guaranteed
     * to be stable between releases.
     */
    experimental?: (keyof typeof ExperimentalFeatures)[];
}

/** @public */
export declare interface QwikSymbol {
    origin: string;
    displayName: string;
    hash: string;
    canonicalFilename: string;
    ctxKind: 'function' | 'eventHandler';
    ctxName: string;
    /** Whether the symbol captures a variable */
    captures: boolean;
    parent: string | null;
    loc: [number, number];
    /** The parameter names if it's a function with parameters */
    paramNames?: string[];
    /** The transformed names of scoped variables, if any */
    captureNames?: string[];
}

/**
 * The types for Vite/Rollup don't allow us to be too specific about the return type. The correct
 * return type is `[QwikVitePlugin, VitePlugin<never>]`, and if you search the plugin by name you'll
 * get the `QwikVitePlugin`.
 *
 * @public
 */
export declare function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;

/**
 * This is the type of the "pre" Qwik Vite plugin. `qwikVite` actually returns a tuple of two
 * plugins, but after Vite flattens them, you can find the plugin by name.
 *
 * @public
 */
export declare type QwikVitePlugin = P<QwikVitePluginApi> & {
    name: 'vite-plugin-qwik';
};

/** @public */
export declare interface QwikVitePluginApi {
    getOptimizer: () => Optimizer | null;
    getOptions: () => NormalizedQwikPluginOptions;
    getManifest: () => QwikManifest | null;
    getRootDir: () => string | null;
    getClientOutDir: () => string | null;
    getClientPublicOutDir: () => string | null;
    getAssetsDir: () => string | undefined;
    registerBundleGraphAdder: (adder: BundleGraphAdder) => void;
    /** @internal */
    _oldDevSsrServer: () => boolean | undefined;
}

declare interface QwikVitePluginCommonOptions {
    /**
     * Prints verbose Qwik plugin debug logs.
     *
     * Default `false`
     */
    debug?: boolean;
    /**
     * The Qwik entry strategy to use while building for production. During development the type is
     * always `segment`.
     *
     * Default `{ type: "smart" }`)
     */
    entryStrategy?: EntryStrategy;
    /**
     * The source directory to find all the Qwik components. Since Qwik does not have a single input,
     * the `srcDir` is used to recursively find Qwik files.
     *
     * Default `src`
     */
    srcDir?: string;
    /**
     * List of tsconfig.json files to use for ESLint warnings during development.
     *
     * Default `['tsconfig.json']`
     */
    tsconfigFileNames?: string[];
    /**
     * List of directories to recursively search for Qwik components or Vendors.
     *
     * Default `[]`
     *
     * @deprecated No longer used. Instead, any imported file with `.qwik.` in the name is processed.
     */
    vendorRoots?: string[];
    /**
     * Disables the automatic vendor roots scan. This is useful when you want to manually specify the
     * vendor roots.
     */
    disableVendorScan?: boolean;
    /**
     * Options for the Qwik optimizer.
     *
     * Default `undefined`
     */
    optimizerOptions?: OptimizerOptions;
    /**
     * Hook that's called after the build and provides all of the transformed modules that were used
     * before bundling.
     */
    transformedModuleOutput?: ((transformedModules: TransformModule[]) => Promise<void> | void) | null;
    devTools?: QwikPluginDevTools;
    /**
     * Predicate function to filter out files from the optimizer. hook for resolveId, load, and
     * transform
     */
    fileFilter?: (id: string, hook: keyof Plugin_2) => boolean;
    /**
     * Run eslint on the source files for the ssr build or dev server. This can slow down startup on
     * large projects. Defaults to `true`
     */
    lint?: boolean;
    /**
     * Experimental features. These can come and go in patch releases, and their API is not guaranteed
     * to be stable between releases
     */
    experimental?: (keyof typeof ExperimentalFeatures)[];
    /**
     * Disables automatic preloading of font assets (WOFF/WOFF2/TTF) found in the build output. When
     * enabled, the plugin will not add `<link rel="preload">` tags for font files in the document
     * head.
     *
     * Disabling may impact Cumulative Layout Shift (CLS) metrics.
     */
    disableFontPreload?: boolean;
}

declare interface QwikVitePluginCSROptions extends QwikVitePluginCommonOptions {
    /** Client Side Rendering (CSR) mode. It will not support SSR, default to Vite's `index.html` file. */
    csr: true;
    client?: never;
    devSsrServer?: never;
    ssr?: never;
}

declare interface QwikVitePluginCSROptions extends QwikVitePluginCommonOptions {
    /** Client Side Rendering (CSR) mode. It will not support SSR, default to Vite's `index.html` file. */
    csr: true;
}

/** @public */
export declare type QwikVitePluginOptions = QwikVitePluginCSROptions | QwikVitePluginSSROptions;

declare interface QwikVitePluginSSROptions extends QwikVitePluginCommonOptions {
    /** Client Side Rendering (CSR) mode. It will not support SSR, default to Vite's `index.html` file. */
    csr?: false | undefined;
    client?: {
        /**
         * The entry point for the client builds. This would be the application's root component
         * typically.
         *
         * Default `src/components/app/app.tsx`
         */
        input?: string[] | string;
        /**
         * Output directory for the client build.
         *
         * Default `dist`
         */
        outDir?: string;
        /**
         * The client build will create a manifest and this hook is called with the generated build
         * data.
         *
         * Default `undefined`
         */
        manifestOutput?: (manifest: QwikManifest) => Promise<void> | void;
    };
    /** @deprecated Use the `devSsrServer` option of the qwikRouter() plugin instead. */
    devSsrServer?: boolean;
    /** Controls the SSR behavior. */
    ssr?: {
        /**
         * The entry point for the SSR renderer. This file should export a `render()` function. This
         * entry point and `render()` export function is also used for Vite's SSR development and
         * Node.js debug mode.
         *
         * Default `src/entry.ssr.tsx`
         */
        input?: string;
        /**
         * Output directory for the server build.
         *
         * Default `server`
         */
        outDir?: string;
        /**
         * The SSR build requires the manifest generated during the client build. By default, this
         * plugin will wire the client manifest to the ssr build. However, the `manifestInput` option
         * can be used to manually provide a manifest.
         *
         * Default `undefined`
         */
        manifestInput?: QwikManifest;
        /** Same as `manifestInput` but allows passing the path to the file. */
        manifestInputPath?: string;
    };
}

/** @public */
export declare interface ResolvedManifest {
    mapper: SymbolMapper;
    manifest: ServerQwikManifest;
    injections?: GlobalInjections[];
    bundleGraph?: QwikBundleGraph;
}

/**
 * The manifest values that are needed for SSR.
 *
 * @public
 */
export declare type ServerQwikManifest = Pick<QwikManifest, 'manifestHash' | 'injections' | 'bundleGraph' | 'bundleGraphAsset' | 'mapping' | 'preloader' | 'core' | 'qwikLoader'>;

/** @public */
export declare type SymbolMapper = Record<string, readonly [symbol: string, chunk: string]>;

/** @public */
export declare type SymbolMapperFn = (symbolName: string, mapper: SymbolMapper | undefined, parent?: string) => readonly [symbol: string, chunk: string] | undefined;


export * from "@qwik.dev/optimizer";

export { }
