import { test, expect } from '@playwright/test';
import { BASE_URL, USER, ADMIN, loginAs } from '../helpers';

test.describe('WFBO Chat Log — read-only', () => {

    test('admin can see a player conversation and its message, with no reply UI', async ({ page }) => {
        // Player sends a message first, creating the conversation.
        await loginAs(page, USER.mobile, USER.password);
        await page.goto(`${BASE_URL}/`);
        await page.click('[data-testid="chat-widget-toggle"]');
        await page.fill('[data-testid="chat-input"]', 'Chat log acceptance test message');
        await page.click('[data-testid="chat-send-button"]');
        await expect(page.locator('[data-testid="chat-message"][data-sender="player"]')).toBeVisible();

        // Admin reviews it in WFBO.
        await loginAs(page, ADMIN.mobile, ADMIN.password);
        await page.goto(`${BASE_URL}/wfbo/chats`);

        await expect(page.locator('[data-testid="wfbo-page-title"]')).toHaveText('Chats');
        const row = page.locator('[data-testid^="chat-conversation-row-"]').first();
        await expect(row).toBeVisible();

        await row.locator('[data-testid^="btn-view-chat-"]').click();

        await expect(page.locator('[data-testid="chat-message-list"]')).toContainText('Chat log acceptance test message');
        await expect(page.locator('[data-testid="chat-reply-input"]')).toHaveCount(0);
    });
});
