import { PlatformAdapter } from './base.js';
export class InMobiAdapter extends PlatformAdapter {
    getName() {
        return 'InMobi';
    }
    getSizeLimit() {
        // InMobi: 5MB
        return 5 * 1024 * 1024;
    }
    getDefaultFormat() {
        return 'zip';
    }
    async modifyHTML(html, assets) {
        // InMobi 需要 MRAID 支持
        const inmobiScriptCode = `
      window.mraid = window.mraid || {
        getVersion: function() { return '2.0'; },
        isReady: function() { return true; },
        open: function(url) { 
          console.log('InMobi CTA: opening store');
          if (url) { window.open(url, '_blank'); return; }
          var ua = navigator.userAgent || '';
          var isIOS = /iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
          window.open(isIOS ? 'https://apps.apple.com/us/app/8-ball-pool/id543186831' : 'https://play.google.com/store/apps/details?id=com.miniclip.eightballpool', '_blank');
        },
        close: function() { window.close(); },
        addEventListener: function(event, listener) {
          if (event === 'ready') setTimeout(listener, 0);
        },
        removeEventListener: function(event, listener) {},
        getState: function() { return 'default'; },
        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 }; }
      };
    `;
        const inmobiScript = await this.minifyPlatformScript(inmobiScriptCode, 'inmobi-mraid');
        const comment = `<!-- InMobi: ZIP格式, 使用mraid.open() -->`;
        // 在 </head> 之前插入平台特定的 API
        html = html.replace('</head>', `${inmobiScript}${comment}</head>`);
        // 注入统一的 CTA 适配器
        html = await this.injectCTAAdapterAsync(html);
        html = await this.injectTrackingAdapterAsync(html);
        return html;
    }
    getPlatformScript() {
        return `
      // InMobi Playable Ad
      // 使用 mraid.open() 跳转应用商店
      
      if (typeof mraid !== 'undefined') {
        mraid.addEventListener('ready', function() {
          console.log('InMobi: mraid ready');
        });
      }
    `;
    }
    validateOptions() {
        if (this.options.format && this.options.format !== 'zip') {
            console.warn('警告: InMobi 要求 ZIP 格式');
        }
    }
}
