import { test, expect, openNavigationCollection, openMedialibCollection, openNewMedialibEntry } from "./fixtures"

test.describe("Admin navigation and media config", () => {
    test("renders the navigation collection with declared trees and structure controls", async ({ page }) => {
        await openNavigationCollection(page)

        const main = page.locator("main")
        await expect(page).toHaveURL(/\/collections\/navigation\?view=navigation$/)
        await expect(page.getByRole("heading", { level: 2, name: "Deklarierte Bäume" })).toBeVisible()
        await expect(main).toContainText("Header DE")
        await expect(main).toContainText("Header EN")
        await expect(main).toContainText("Footer DE")
        await expect(main).toContainText("Footer EN")
        await expect(main).toContainText("Wurzelknoten")
        await expect(main).toContainText("Max. Ebene")
    })

    test("renders the media library list with subnavigation and previews", async ({ page }) => {
        await openMedialibCollection(page)

        const main = page.locator("main")
        await expect(page).toHaveURL(/\/collections\/medialib\?view=media$/)
        await expect(page.getByRole("region", { name: "Mediathek-Raster" })).toBeVisible()
        await expect(main).toContainText("Bilder")
        await expect(main).toContainText("Dokumente")
        await expect(main).toContainText("Dateien hinzufügen")
        await expect(
            page.getByRole("img", { name: /Technology Stack|Homepage Hero|About Team|Contact Hero|Workflow/ }).first()
        ).toBeVisible()
    })

    test("shows the configured media widgets in the new entry form", async ({ page }) => {
        await openNewMedialibEntry(page)

        await expect(page.getByText("Datei", { exact: true })).toBeVisible()
        await expect(page.getByRole("button", { name: /Datei hochladen/ })).toBeVisible()
        await expect(page.getByLabel("Titel")).toBeVisible()
        await expect(page.getByText("Alt-Text")).toBeVisible()
        await expect(page.getByRole("tab", { name: "de" })).toBeVisible()
        await expect(page.getByRole("tab", { name: "en" })).toBeVisible()
        await expect(page.getByLabel("Beschreibung")).toBeVisible()
        await expect(page.getByLabel("Tags")).toBeVisible()
    })
})
