// @ts-check
const { test, expect } = require('@playwright/test');
const { login } = require('./helpers/auth');

async function loginAsAdmin(page) {
  await login(page, 'admin');
  await page.locator('input[name="lg_idx"]').first().check();
  await page.click('button[type="submit"]');
  await page.waitForURL(url => !url.pathname.includes('select-local-government'), { timeout: 30000 });
}

test.describe('P5: 판매 대장', () => {
  test('일자별 판매 대장 접근', async ({ page }) => {
    await loginAsAdmin(page);
    await page.goto('/admin/reports/sales-ledger');
    await expect(page).toHaveURL(/\/admin\/reports\/sales-ledger/);
  });
  test('기간별 판매 대장', async ({ page }) => {
    await loginAsAdmin(page);
    await page.goto('/admin/reports/sales-ledger?mode=period&start_date=2026-01-01&end_date=2026-12-31');
    await expect(page).toHaveURL(/mode=period/);
  });
});

test.describe('P5: 일계표', () => {
  test('일계표 접근', async ({ page }) => {
    await loginAsAdmin(page);
    await page.goto('/admin/reports/daily-summary');
    await expect(page).toHaveURL(/\/admin\/reports\/daily-summary/);
  });
});

test.describe('P5: 기간별 판매현황', () => {
  test('기간별 판매현황 접근', async ({ page }) => {
    await loginAsAdmin(page);
    await page.goto('/admin/reports/period-sales');
    await expect(page).toHaveURL(/\/admin\/reports\/period-sales/);
  });
});

test.describe('P5: 봉투 수불 현황', () => {
  test('수불 현황 접근', async ({ page }) => {
    await loginAsAdmin(page);
    await page.goto('/admin/reports/supply-demand');
    await expect(page).toHaveURL(/\/admin\/reports\/supply-demand/);
  });
});

test.describe('P5: 지자체관리자 접근', () => {
  test('리포트 접근 가능', async ({ page }) => {
    await login(page, 'local');
    await page.goto('/admin/reports/sales-ledger');
    await expect(page).toHaveURL(/\/admin\/reports\/sales-ledger/);
    await page.goto('/admin/reports/daily-summary');
    await expect(page).toHaveURL(/\/admin\/reports\/daily-summary/);
  });
});
