import { PlatformAdapter } from './base.js';
export class BigoAdapter extends PlatformAdapter {
    getName() {
        return 'BIGO Ads';
    }
    getSizeLimit() {
        // BIGO Ads: 5MB
        return 5 * 1024 * 1024;
    }
    getDefaultFormat() {
        return 'zip';
    }
    async modifyHTML(html, assets) {
        // BIGO Ads 需要 BIGO JS-SDK
        const bigoScriptCode = `
      window.BGY_MRAID = window.BGY_MRAID || {
        open: function(url) {
          console.log('BIGO CTA: opening store');
          function getOS(){
            var ua = navigator.userAgent || '';
            if (/iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) return 'ios';
            if (/Android/i.test(ua)) return 'android';
            return 'unknown';
          }
          var _s = (typeof window !== 'undefined' && window.__PLAYCRAFT_STORE_URLS__) || {};
          var storeUrl = url || (getOS() === 'ios' ? (_s.ios || '') : (_s.android || ''));
          window.open(storeUrl, '_blank');
        },
        gameReady: function() {
          console.log('BIGO: game ready');
        },
        gameEnd: function() {
          console.log('BIGO: game end');
        }
      };
    `;
        const sdkScript = `<script src="https://static-web.likeevideo.com/oss/material-ad/playable-ad-demo/bgy-mraid-sdk.js"></script>`;
        const fallbackScript = await this.minifyPlatformScript(bigoScriptCode, 'bigo-sdk');
        const comment = `<!-- BIGO: ZIP格式, config.json含orientation, 使用BGY_MRAID.open() -->`;
        // 在 </head> 之前插入
        html = html.replace('</head>', `${sdkScript}${fallbackScript}${comment}</head>`);
        // 注入统一的 CTA 适配器
        html = await this.injectCTAAdapterAsync(html);
        html = await this.injectTrackingAdapterAsync(html);
        return html;
    }
    getPlatformScript() {
        return `
      // BIGO Ads Playable
      // 使用 BGY_MRAID SDK
      
      if (typeof BGY_MRAID !== 'undefined') {
        // 游戏准备就绪
        BGY_MRAID.gameReady();
        
        // CTA 跳转
        // BGY_MRAID.open('https://play.google.com/store');
        
        // 游戏结束
        // BGY_MRAID.gameEnd();
      }
    `;
    }
    /**
     * 生成 config.json（BIGO 要求）
     * @param orientation 0=横或竖, 1=仅竖屏, 2=仅横屏
     */
    generateConfigJson(orientation = 0) {
        return {
            orientation: orientation,
        };
    }
    validateOptions() {
        if (this.options.format && this.options.format !== 'zip') {
            console.warn('警告: BIGO Ads 要求 ZIP 格式');
        }
    }
}
