import * as _angular_core from '@angular/core';
import { OnDestroy } from '@angular/core';

/**
 * Runtime state attributes the component renders on the same anchor as `data-autoid`.
 * Every field is OPTIONAL — only present when the component actually renders that attribute.
 * All values are the raw DOM string (already "true"/"false" or stringified number/value).
 */
interface SdAutoidElementState {
    disabled?: string;
    loading?: string;
    empty?: string;
    invalid?: string;
    opened?: string;
    count?: string;
    /** Serialized DOM `data-value` (NOT `input.value`). Distinct from `SdAutoidElement.text` field. */
    dataValue?: string;
    required?: string;
    maxlength?: string;
    minlength?: string;
    pattern?: string;
    errorMessage?: string;
    type?: string;
    title?: string;
    message?: string;
}
interface SdAutoidElement {
    stt: number;
    name: string;
    autoid: string;
    tag: string;
    /**
     * Display text resolved from the DOM: `input.value` for form controls, otherwise
     * `textContent.trim().slice(0, 80)`. Use `state.dataValue` for the serialized
     * runtime value rendered by `@sdcorejs/angular` components.
     */
    text: string;
    xpath: string;
    duplicate: boolean;
    /** Runtime state attributes read from the DOM. Always an object — may be empty `{}`. */
    state: SdAutoidElementState;
    /**
     * `data-autoid` of the closest ancestor `<sd-table>` that contains this element,
     * or `undefined` if this element is top-level (not inside any `sd-table`).
     * Used by the UI to group table-scoped elements into a separate section.
     */
    tableScope?: string;
    /**
     * `true` when the element matched a required selector (sd-button, sd-input, …) but
     * had NO `data-autoid` — the scanner still emits it with `autoid: ''` and a positional
     * `xpath` fallback so the export stays usable. The dev should backfill an autoid.
     */
    missingAutoid?: boolean;
    /** Human-readable warning attached to a fallback element (only set when `missingAutoid`). */
    warning?: string;
}
interface SdAutoidMissing {
    tag: string;
    selector: string;
    outerHtmlPreview: string;
    nameHint: string;
}
interface SdAutoidAuditResult {
    total: number;
    duplicates: Record<string, number>;
    duplicateCount: number;
    missing: SdAutoidMissing[];
    missingCount: number;
}

interface SdAutoidInspectorConfig {
    /** Selector phụ thêm cần audit (mặc định component đã cover sd-* form + sd-button). */
    extraRequireSelectors?: string[];
    /** Root scan, mặc định document.body. */
    root?: HTMLElement;
}
/** Selector mặc định coi là phải có data-autoid. */
declare const SD_AUTOID_DEFAULT_REQUIRE_SELECTORS: ReadonlyArray<string>;

type Segment = 'audit' | 'elements' | 'export';
declare class SdAutoidInspector implements OnDestroy {
    #private;
    enabled: _angular_core.InputSignalWithTransform<boolean, unknown>;
    config: _angular_core.InputSignal<SdAutoidInspectorConfig | undefined>;
    open: _angular_core.WritableSignal<boolean>;
    segment: _angular_core.WritableSignal<Segment>;
    filter: _angular_core.WritableSignal<string>;
    elements: _angular_core.WritableSignal<SdAutoidElement[]>;
    audit: _angular_core.WritableSignal<SdAutoidAuditResult | null>;
    copyOk: _angular_core.WritableSignal<boolean>;
    highlightOn: _angular_core.WritableSignal<boolean>;
    dismissed: _angular_core.WritableSignal<boolean>;
    filteredElements: _angular_core.Signal<SdAutoidElement[]>;
    /**
     * Elements not inside any sd-table — rendered in the main "Top-level" section.
     */
    readonly topLevelElements: _angular_core.Signal<SdAutoidElement[]>;
    /**
     * Map of `sd-table` autoid → its inner autoid elements. Tables themselves
     * stay in `topLevelElements` (the table's own autoid is top-level).
     */
    readonly tableGroups: _angular_core.Signal<{
        scope: string;
        items: SdAutoidElement[];
    }[]>;
    readonly dataOpened: _angular_core.Signal<"true" | "false">;
    readonly dataHighlightOn: _angular_core.Signal<"true" | "false">;
    readonly dataSegment: _angular_core.Signal<Segment>;
    readonly dataElementCount: _angular_core.Signal<string>;
    readonly dataMissingCount: _angular_core.Signal<string>;
    readonly dataDuplicateCount: _angular_core.Signal<string>;
    ngOnDestroy(): void;
    togglePanel: () => void;
    openPanel: () => void;
    closePanel: () => void;
    refresh: () => void;
    dismissFab: (event: Event) => void;
    toggleHighlight: () => void;
    setSegment: (seg: Segment) => void;
    copyJson: () => Promise<void>;
    copyXpath: (autoid: string) => Promise<void>;
    exportCsv: () => void;
    exportJson: () => void;
    exportMdPom: () => void;
    exportMdTable: () => void;
    onEscape(): void;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<SdAutoidInspector, never>;
    static ɵcmp: _angular_core.ɵɵComponentDeclaration<SdAutoidInspector, "sd-autoid-inspector", never, { "enabled": { "alias": "enabled"; "required": false; "isSignal": true; }; "config": { "alias": "config"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
}

type SdAutoidExportFormat = 'csv' | 'json' | 'md-pom' | 'md-table';
interface SdAutoidExportMeta {
    /** `location.pathname + location.search` — kept for back-compat with MD exports. */
    pageUrl: string;
    pageTitle: string;
    timestamp: string;
    /** Full `location.href`. */
    url: string;
    /** `location.pathname` only. */
    pathname: string;
    /** Raw `location.search` (incl. leading `?`), or `''`. */
    search: string;
    /** Parsed query string → key/value map (last value wins on repeats). */
    queryParams: Record<string, string>;
    /**
     * Angular route path params (`:id`, …) merged across the activated-route tree.
     * Only present when an Angular `Router` is available at scan time; omitted otherwise.
     */
    params?: Record<string, string>;
}
/** JSON export envelope: page meta + the scanned elements. */
interface SdAutoidExportJson {
    meta: SdAutoidExportMeta;
    elements: SdAutoidElement[];
}

declare class SdAutoidScannerService {
    /**
     * Quét element có [data-autoid] trong root, gắn name/tag/value/xpath.
     * Khi truyền `requireSelectors` (vd các sd-* form/button), những node khớp selector
     * mà KHÔNG có data-autoid (self lẫn con) sẽ được thêm vào dưới dạng phần tử fallback
     * (`autoid: ''`, xpath theo vị trí thẻ + cờ `missingAutoid` + warning) — để JSON xuất ra
     * vẫn dùng được và dev biết chỗ cần bổ sung autoid.
     */
    scan(root?: HTMLElement, requireSelectors?: ReadonlyArray<string>): SdAutoidElement[];
    /**
     * Tìm các node khớp `requireSelectors` nhưng thiếu data-autoid (self + mọi descendant),
     * thêm vào `result` dưới dạng phần tử fallback. Trả về `stt` kế tiếp.
     */
    private appendMissing;
    /** XPath theo vị trí thẻ trong document, vd `(//sd-button)[2]`, khi không có autoid. */
    private fallbackXpath;
    /** Group element theo autoid để consumer lấy duplicate map. */
    groupByAutoid(elements: SdAutoidElement[]): Record<string, SdAutoidElement[]>;
    /**
     * Read the optional `data-*` E2E state attributes off the same node.
     * Only includes fields actually present on the DOM (skipped fields stay undefined).
     */
    private readState;
    /**
     * If the node is inside an `<sd-table>` element, return that table's `data-autoid`.
     * Walks up via closest('sd-table') — skips the node itself if it IS the table.
     */
    private resolveTableScope;
    private resolveName;
    private resolveSdTag;
    private resolveText;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<SdAutoidScannerService, never>;
    static ɵprov: _angular_core.ɵɵInjectableDeclaration<SdAutoidScannerService>;
}

declare class SdAutoidAuditService {
    /**
     * Audit kết quả scan + DOM:
     * - duplicates: map autoid → count khi count > 1
     * - missing: element khớp selector yêu cầu nhưng KHÔNG có [data-autoid]
     */
    audit(elements: SdAutoidElement[], options?: {
        requireSelectors?: ReadonlyArray<string>;
        root?: HTMLElement;
    }): SdAutoidAuditResult;
    private findMissing;
    private buildSelectorPath;
    private shortHtml;
    private resolveNameHint;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<SdAutoidAuditService, never>;
    static ɵprov: _angular_core.ɵɵInjectableDeclaration<SdAutoidAuditService>;
}

declare class SdAutoidHighlightService {
    #private;
    /** Apply outline cho mọi [data-autoid]: xanh nếu unique, đỏ nếu duplicate. Idempotent. */
    apply(root?: HTMLElement): void;
    /** Highlight tập element không có autoid (missing) bằng outline cam dashed. */
    applyMissing(nodes: HTMLElement[]): void;
    /** Restore inline style như trước khi apply. */
    clear(root?: HTMLElement): void;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<SdAutoidHighlightService, never>;
    static ɵprov: _angular_core.ɵɵInjectableDeclaration<SdAutoidHighlightService>;
}

declare class SdAutoidExportService {
    /**
     * Có `meta` → bọc `{ meta, elements }` (kèm url/queryParams) để consumer biết trang/route.
     * Không `meta` → giữ mảng thuần (back-compat cho caller cũ chỉ cần elements).
     */
    toJson(elements: SdAutoidElement[], meta?: SdAutoidExportMeta): string;
    /** Parse a `location.search` string into a flat key/value map (last value wins). */
    parseQueryParams(search: string): Record<string, string>;
    toCsv(elements: SdAutoidElement[]): string;
    /** POM TypeScript skeleton — copy ngay vào file Playwright/Cypress. */
    toMarkdownPom(elements: SdAutoidElement[], meta: SdAutoidExportMeta): string;
    /** Markdown reference table, group FIRST by tableScope (top-level first, then per table), then by tag. */
    toMarkdownTable(elements: SdAutoidElement[], meta: SdAutoidExportMeta): string;
    download(content: string, filename: string, mime: string): void;
    copyToClipboard(content: string): Promise<void>;
    /** Build a compact state summary string from defined state keys, e.g. "disabled=false; empty=true". */
    private buildStateSummary;
    private q;
    private mdCell;
    private toCamel;
    private toPascal;
    static ɵfac: _angular_core.ɵɵFactoryDeclaration<SdAutoidExportService, never>;
    static ɵprov: _angular_core.ɵɵInjectableDeclaration<SdAutoidExportService>;
}

export { SD_AUTOID_DEFAULT_REQUIRE_SELECTORS, SdAutoidAuditService, SdAutoidExportService, SdAutoidHighlightService, SdAutoidInspector, SdAutoidScannerService };
export type { SdAutoidAuditResult, SdAutoidElement, SdAutoidElementState, SdAutoidExportFormat, SdAutoidExportJson, SdAutoidExportMeta, SdAutoidInspectorConfig, SdAutoidMissing };
