const FOCUSABLE_SELECTOR = [
    'a[href]:not([tabindex="-1"])',
    'button:not(:disabled):not([tabindex="-1"])',
    'input:not(:disabled):not([type="hidden"]):not([tabindex="-1"])',
    'select:not(:disabled):not([tabindex="-1"])',
    'textarea:not(:disabled):not([tabindex="-1"])',
    '[tabindex="0"]',
].join(', ');

export function focusFirstFocusableIn(container: HTMLElement | null | undefined): void {
    if (!container) {
        return;
    }

    const first = container.querySelector<HTMLElement>(FOCUSABLE_SELECTOR);
    first?.focus();
}

export function focusPanelById(panelId: string): void {
    focusFirstFocusableIn(document.getElementById(panelId));
}
