const browser = require('../browser');

module.exports = async ({ selector, timeout = 15000 }) => {
  if (!selector) {
    throw new Error('Selector é obrigatório');
  }

  await browser.start();
  const p = await browser.ensurePage();

  const el = await p.waitForSelector(selector, {
    timeout,
    state: 'attached'
  });

  return {
    success: true,
    action: "wait_for_selector",
    selector,
    found: !!el
  };
};
