import { PlatformAdapter } from './base.js';
export class SnapchatAdapter extends PlatformAdapter {
    getName() {
        return 'Snapchat';
    }
    getSizeLimit() {
        // Snapchat: 5MB (uncompressed)
        return 5 * 1024 * 1024;
    }
    getDefaultFormat() {
        return 'zip';
    }
    async modifyHTML(html, assets) {
        // Snapchat 需要 MRAID 2.0 和 snapchatCta 函数
        const mraidScriptCode = `
      window.mraid = window.mraid || {
        getVersion: function() { return '2.0'; },
        isReady: function() { return true; },
        open: function(url) {
          if (url) { window.open(url, '_blank'); return; }
          var ua = navigator.userAgent || '';
          var isIOS = /iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
          var _s = window.__PLAYCRAFT_STORE_URLS__ || {};
          window.open(isIOS ? (_s.ios || '') : (_s.android || ''), '_blank');
        },
        close: function() { window.close(); },
        addEventListener: function(event, listener) {},
        removeEventListener: function(event, listener) {},
        getState: function() { return 'ready'; },
        getPlacementType: function() { return 'interstitial'; },
        getMaxSize: function() { return { width: window.innerWidth, height: window.innerHeight }; },
        getCurrentPosition: function() { return { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight }; },
        getScreenSize: function() { return { width: screen.width, height: screen.height }; }
      };
      window.snapchatCta = function() {
        if (window.mraid && window.mraid.open) {
          var _s = window.__PLAYCRAFT_STORE_URLS__ || {};
          var ua = navigator.userAgent || '';
          var isIOS = /iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
          var url = isIOS ? (_s.ios || '') : (_s.android || '');
          window.mraid.open(url);
        }
      };
    `;
        const mraidScript = await this.minifyPlatformScript(mraidScriptCode, 'snapchat-mraid');
        html = html.replace('</head>', `${mraidScript}</head>`);
        // 注入统一的 CTA 适配器
        html = await this.injectCTAAdapterAsync(html);
        html = await this.injectTrackingAdapterAsync(html);
        return html;
    }
    getPlatformScript() {
        return `
      // Snapchat Playable Ad
      if (typeof mraid !== 'undefined') {
        mraid.addEventListener('ready', function() {
          console.log('MRAID ready');
        });
      }

      // 在 CTA 按钮点击时调用
      // snapchatCta();
    `;
    }
    validateOptions() {
        // Snapchat 默认使用 ZIP 格式，但不强制要求
        // MRAID 支持会在 modifyHTML 中自动添加
        if (this.options.format && this.options.format !== 'zip') {
            console.warn('Warning: Snapchat typically uses ZIP format');
        }
    }
}
