import sys, time
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

opts = Options(); opts.headless = False
svc = Service(executable_path=r"geckodriver.exe")
d = webdriver.Firefox(options=opts, service=svc)

url = "http://localhost:8000/field-capture.html?debug&_=" + str(time.time())
d.get(url)
time.sleep(4)

# Use the exposed __test API to create a job, then navigate to a sketch screen
d.execute_script("""
  window.__test.state.jobs.push({
    id: 'j1', name: 'Test Job', address: '', date: '', notes: '',
    sketches: [{ id: 's1', name: 'Plan View', photo: null, pins: [], lines: [] }]
  });
  window.__test.ui.screen = 'sketch';
  window.__test.ui.jobId = 'j1';
  window.__test.ui.sketchId = 's1';
  window.__test.render();
""")
time.sleep(1)

html = d.execute_script("return document.querySelector('.sketch-empty') ? document.querySelector('.sketch-empty').innerText : null")
print("sketch-empty text:", repr(html))

btns = d.execute_script("""
  return Array.from(document.querySelectorAll('.sketch-empty .btn')).map(b => b.innerText);
""")
print("buttons:", btns)

# Confirm the browse-files input uses the same photo handler
inputs = d.execute_script("""
  return Array.from(document.querySelectorAll('.sketch-empty input[type=file]')).map(i => ({
    accept: i.getAttribute('accept'),
    action: i.getAttribute('data-action-input')
  }));
""")
print("file inputs:", inputs)

d.quit()