const puppeteer = require('puppeteer-core');
const fs = require('fs');
const OUT = '/root/folxplay-test/prod';
fs.mkdirSync(OUT, { recursive: true });

(async () => {
  const browser = await puppeteer.launch({
    executablePath: '/usr/bin/google-chrome',
    headless: 'new',
    args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--autoplay-policy=no-user-gesture-required']
  });

  const page = await browser.newPage();
  await page.setViewport({ width: 1440, height: 900 });

  console.log('Loading https://folxplay.biba.live ...');
  const resp = await page.goto('https://folxplay.biba.live/', { waitUntil: 'networkidle2', timeout: 20000 });
  console.log('HTTP status:', resp.status());
  console.log('Final URL:', resp.url());
  
  await new Promise(r => setTimeout(r, 1500));
  await page.screenshot({ path: OUT + '/prod-home.png', fullPage: false });
  console.log('prod-home.png saved');

  // Click Folx Music
  await page.click('[data-channel="mt"]');
  await new Promise(r => setTimeout(r, 5000));
  await page.screenshot({ path: OUT + '/prod-playing.png', fullPage: false });
  
  const state = await page.evaluate(() => {
    const v = document.getElementById('video');
    return v ? { paused: v.paused, currentTime: v.currentTime, duration: v.duration, vw: v.videoWidth, vh: v.videoHeight } : null;
  });
  console.log('Video state:', JSON.stringify(state));
  
  await browser.close();
})();
