import { afterEach, describe, expect, it } from "vitest";
import type { BookingConfig } from "./config";
import { initialOnboarding, ready, type StarterStatus } from "./setup";

const base: BookingConfig = {
    restUrl: "/wp-json/fxtr/v1/",
    restNonce: "n",
    today: "2026-10-28",
    caps: { settings: true },
    dateFormat: "Y-m-d",
    timeFormat: "H:i",
    locale: "en-US",
};

afterEach(() => {
    delete window.fxtrAdmin;
});

describe("initialOnboarding", () => {
    it("takes the state the page was printed with", () => {
        window.fxtrAdmin = { ...base, onboarding: { status: "pending", started_at: null, completed_at: null, dismissed_at: null } };
        expect(initialOnboarding().status).toBe("pending");
    });

    it("does not show the welcome when the state is missing", () => {
        window.fxtrAdmin = base;
        expect(initialOnboarding().status).toBe("completed");
    });
});

describe("ready", () => {
    const status = (checklist: StarterStatus["checklist"]) => ({ checklist }) as StarterStatus;

    it("needs tables, shifts and a booking page", () => {
        expect(ready(status({ tables: true, shifts: true, booking_page: true }))).toBe(true);
        expect(ready(status({ tables: true, shifts: false, booking_page: true }))).toBe(false);
        expect(ready(status({ tables: true, shifts: true, booking_page: false }))).toBe(false);
    });
});
