// Injected script to call display API in page context and set CloudFront cookies
(function() {
  window.addEventListener('mym-call-display-api', async function(e) {
    const { displayUrl, requestId } = e.detail;
    
    try {
      console.log('[Page] Calling display API:', displayUrl);
      const res = await fetch(displayUrl, { 
        method: 'GET',
        credentials: 'include'
      });
      console.log('[Page] Display API response:', res.status);
      
      window.dispatchEvent(new CustomEvent('mym-display-done', { 
        detail: { requestId, ok: res.ok, status: res.status } 
      }));
    } catch (err) {
      console.error('[Page] Display API error:', err);
      window.dispatchEvent(new CustomEvent('mym-display-done', { 
        detail: { requestId, ok: false, error: err.message } 
      }));
    }
  });
  
  console.log('[Page] Display API caller ready');
})();
