import { Plugin } from 'rollup';

/** @format */

/**
 * @description
 * Object to configure the Plugin. All properties are optional
 */

type RldInit = {
    /**
     * @description
     * The URL the plugin will use to construct and listen to for the reload route. Default to `rld`
     * @type { string }
     */
    url?: string;
    /**
     * @description
     * Port to use with the server. Defaults to `31415`
     * @type { number }
     */
    port?: number;
    /**
     * @description
     * Hostname to use with the server. Defaults to `localhost`
     * @type { string }
     */
    host?: string;
    /**
     * @description
     * Object of attributes used as key value pair to add to the created script tag.
     * This can be useful to add a nonce or similar attributes to the script tag if necessary.
     *
     * eg:
     * ```js
     * {
     *   attributes: {
     *     'class': 'Test'
     *   }
     * }
     *
     * // this will add the class 'test' to the script tag
     * ```
     *
     * @type { Record<string, string> }
     */
    attributes?: Record<string, string>;
    /**
     * @description
     * Boolean flag indicating if information should be logged to the browser console.
     * @type { boolean }
     */
    log?: boolean;
};

/** @format */

/**
 * @description
 * Factory function to create the Plugin object from the passed init / defaults.
 * `Rollup-Plugin-Rld` will inject a function into your bundle when Rollup is used in watch mode.
 * The function itself will inject a script tag if executed in a HTML instance, that will listen to
 * the server created by the plugin. If changes to the bundle are detected, a reload will be triggered.
 *
 * @param { Partial<RldInit> } init - The optional init Object for the Plugin.
 * @returns { Plugin } the Plugin object.
 */
declare const rld: (init?: Partial<RldInit>) => Plugin;

export { rld };
