#!/bin/sh

if [ -n "$AUTOPKGTEST_TMP" ]; then
    rm -f  'node_modules/tabbable'
    pkgjs-ln 'tabbable'
    pkgjs-ln 'jsdom'
else
    rm -f  'node_modules/tabbable'
    ln -s .. 'node_modules/tabbable'
fi


node<<'EOF'
import { tabbable } from "tabbable";
import { JSDOM } from "jsdom";

// Create DOM and patch browser globals
const dom = new JSDOM(`
  <body>
    <button id="btn1">Click</button>
    <a id="link1" href="#">Link</a>
    <div id="not-tabbable"></div>
    <input id="input1" />
    <button id="hidden" style="display:none">Hidden</button>
  </body>
`, { pretendToBeVisual: true });

const { window } = dom;

// Patch required browser globals
global.window = window;
global.document = window.document;
global.getComputedStyle = window.getComputedStyle;
global.HTMLElement = window.HTMLElement;
global.Node = window.Node;

// Run tabbable
const result = tabbable(document.body);
const ids = result.map(el => el.id);

console.log("Tabbable elements:", ids);
EOF