import { test, expect } from './fixtures/auth';
import { CommonActions } from './utils/common-actions';

test.describe('Manage Event Page', () => {
  test('Shortcode is rendered on manage-event page', async ({ authenticatedPage: page }) => {
    test.setTimeout(30000);
    const actions = new CommonActions(page);
    
    // Navigate directly to manage-event page
    await actions.navigateAndWait('/manage-event/');
    
    // Take a screenshot to see what's rendered
    await actions.screenshot('manage-event-page');
    
    // Check that the shortcode is not visible as raw text
    const pageContent = await page.locator('body').textContent();
    console.log('Page content:', pageContent?.substring(0, 500));
    
    // The raw shortcode should NOT be visible
    expect(pageContent).not.toContain('[tribe_community_events');
    
    // Check for either the form or error message
    const hasForm = await page.locator('#tribe-community-events').count() > 0;
    const hasErrorMessage = await page.locator('.hvac-notice.hvac-error').count() > 0;
    
    if (hasForm) {
      console.log('✓ Event submission form is rendered');
      expect(hasForm).toBeTruthy();
    } else if (hasErrorMessage) {
      console.log('✓ Error message is displayed (TEC plugin may be inactive)');
      const errorText = await page.locator('.hvac-notice.hvac-error').textContent();
      console.log('Error message:', errorText);
      expect(hasErrorMessage).toBeTruthy();
    } else {
      console.log('✗ Neither form nor error message found');
      // Log what we actually see
      const mainContent = await page.locator('.entry-content, .site-main, main').first().innerHTML();
      console.log('Main content HTML:', mainContent);
    }
  });
});