import fs from "fs";
import path from "path"; // Add this import
const STORYBOOK_DIR = path.resolve(__dirname, "../../storybook-static/");
/** Load Storybook story for Playwright testing */
export async function getStory(page, storyID) {
    // Load stories.json
    const storiesManifestPath = path.resolve(STORYBOOK_DIR, "index.json");
    if (!fs.existsSync(storiesManifestPath)) {
        throw new Error("Could not find storybook-static/stories.json. Try rebuilding with `yarn build:storybook`");
    }
    const storiesManifest = JSON.parse(fs.readFileSync(storiesManifestPath, "utf8"));
    // Find the specified story
    const story = storiesManifest.entries[storyID];
    if (!story) {
        throw new Error(`Could not find story ID "${storyID}".`);
    }
    // Navigate to the specific story
    const search = new URLSearchParams({ viewMode: "story", id: storyID });
    await page.goto(`iframe?${search.toString()}`, {
        waitUntil: "networkidle",
    });
}
