/**
 * Basic test for background window functionality
 * Quick verification that 1280x720 background windows work correctly
 */

const MCP_HTTP_URL = 'http://localhost:3001/mcp';

async function testBasicBackgroundWindow() {
  console.log('🧪 Basic Background Window Test');
  console.log('===============================');

  try {
    console.log('1️⃣ Testing basic background window creation...');

    const response = await fetch(MCP_HTTP_URL, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Accept: 'application/json, text/event-stream',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'tools/call',
        params: {
          name: 'chrome_navigate',
          arguments: {
            url: 'https://example.com',
            backgroundPage: true,
          },
        },
      }),
    });

    const result = await response.json();

    if (result.error) {
      console.log(`❌ Error: ${result.error.message}`);
      return;
    }

    if (result.result && result.result.content) {
      const content = JSON.parse(result.result.content[0].text);

      console.log('✅ Background window created successfully!');
      console.log(`📊 Window Details:`);
      console.log(`   Window ID: ${content.windowId}`);
      console.log(`   Dimensions: ${content.width}x${content.height}`);
      console.log(`   URL: ${content.tabs?.[0]?.url || 'N/A'}`);
      console.log(`   Automation Ready: ${content.automationReady}`);
      console.log(`   Minimized: ${content.minimized}`);

      // Verify expected dimensions
      if (content.width === 1280 && content.height === 720) {
        console.log('✅ Dimensions are correct (1280x720)');
      } else {
        console.log(
          `❌ Dimensions are incorrect. Expected 1280x720, got ${content.width}x${content.height}`,
        );
      }

      console.log('\n⏳ Window should now be minimized in your taskbar.');
      console.log('   You can click on it to see the page loaded at example.com');
    } else {
      console.log('❌ Unexpected response format');
      console.log('Raw response:', JSON.stringify(result, null, 2));
    }
  } catch (error) {
    console.log(`❌ Test failed: ${error.message}`);
    console.log('Make sure the MCP server is running on localhost:3001');
  }
}

// Run the basic test
testBasicBackgroundWindow().catch(console.error);
