/**
 * Ambient declarations for the project's `window` globals.
 *
 * Several legacy modules attach helpers onto `window` so they can be
 * called from HTML ``onclick`` attributes / global tab-registry lookups.
 * Without these declarations every callsite used ``(window as any).foo``,
 * which silently erases type errors at the call boundary. Declaring the
 * known fields here lets `tsc --noEmit` flag real typos while keeping
 * the call sites readable.
 *
 * The list is the minimal subset that covers the ``(window as any).<name>``
 * sites flagged by the cross-file audit. Anything indexed by dynamic
 * string ($name = `${kind}Foo`) still legitimately needs an indexed
 * access — those cases keep their narrow casts.
 */

export {};

declare global {
    interface Window {
        // Auth / setup gates (set from core/api.ts during boot)
        _authRequired?: boolean;
        _setupRequired?: boolean;
        _setupModalOpen?: boolean;

        // i18n shim — present once core/i18n.ts initialises.
        __t?: (key: string) => string;

        // UI helpers exposed for inline onclick handlers in templates.
        applyAccentColor?: (accent?: string, persist?: boolean) => void;
        hideSetupRequiredModal?: () => void;
        configureKCRegions?: (sourceId: string) => void;
        removeZ2MLightMapping?: (btn: HTMLElement) => void;

        // Feature reloaders. They are called from cross-feature code that
        // doesn't want a hard module import (to avoid cycles).
        loadAutomations?: () => Promise<void> | void;
        loadPictureSources?: () => Promise<void> | void;
        loadIntegrations?: () => Promise<void> | void;
        loadUpdateSettings?: () => Promise<void> | void;
        loadUpdateStatus?: () => Promise<void> | void;
        showPatternTemplateEditor?: (...args: unknown[]) => unknown;

        // Settings + about panel — bound by app boot and called from
        // template handlers / nav buttons.
        initUpdateSettingsPanel?: () => void;
        onTestDisplaySelected?: (value: string) => void;
        openSettingsModal?: (...args: unknown[]) => unknown;
        renderAboutPanel?: () => void;
        switchSettingsTab?: (tabId: string) => void;

        // Internal helpers attached by features for inline-call reuse.
        _autoGenerateAutomationName?: () => void;
        _openKCRegionEditor?: (sourceId: string) => void;

        // HTTP endpoint editor — used by the integrations tab and
        // automation rule editor.
        showHTTPEndpointModal?: (editData?: unknown) => Promise<void>;
        closeHTTPEndpointModal?: () => Promise<void>;
        saveHTTPEndpoint?: () => Promise<void>;
        editHTTPEndpoint?: (id: string) => Promise<void>;
        cloneHTTPEndpoint?: (id: string) => Promise<void>;
        deleteHTTPEndpoint?: (id: string) => Promise<void>;
        testHTTPEndpoint?: () => Promise<void>;
        addHTTPEndpointHeader?: () => void;
        toggleHTTPEndpointTokenVisibility?: () => void;

        // HA / MQTT source editors — declared so app.ts assignments
        // satisfy strict mode. (Not exhaustive; only what http-endpoints
        // wires up.)
        showHASourceModal?: (...args: unknown[]) => unknown;
        closeHASourceModal?: () => Promise<void>;
        saveHASource?: () => Promise<void>;
        editHASource?: (id: string) => Promise<void>;
        cloneHASource?: (id: string) => Promise<void>;
        deleteHASource?: (id: string) => Promise<void>;
        testHASource?: () => Promise<void>;
    }
}
