import { PlatformAdapter } from './base.js';
export class RemergeAdapter extends PlatformAdapter {
    getName() {
        return 'Remerge';
    }
    getSizeLimit() {
        // Remerge: 5MB
        return 5 * 1024 * 1024;
    }
    getDefaultFormat() {
        return 'html';
    }
    async modifyHTML(html, assets) {
        // Remerge 使用 FbPlayableAd API（与 Facebook/Moloco 相同）
        const remergeScriptCode = `
      window.FbPlayableAd = window.FbPlayableAd || {
        onCTAClick: function() {
          console.log('Remerge CTA clicked');
          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 url = getOS() === 'ios' ? 'https://apps.apple.com/us/app/8-ball-pool/id543186831' : 'https://play.google.com/store/apps/details?id=com.miniclip.eightballpool';
          window.open(url, '_blank');
        }
      };
    `;
        const remergeScript = await this.minifyPlatformScript(remergeScriptCode, 'remerge-api');
        const meta = `<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">`;
        const comment = `<!-- Remerge: 单文件 HTML <5MB, CTA 无参数调用 -->`;
        // 在 </head> 之前插入平台特定的 API
        html = html.replace('</head>', `${remergeScript}${comment}${meta}</head>`);
        // 注入统一的 CTA 适配器
        html = await this.injectCTAAdapterAsync(html);
        html = await this.injectTrackingAdapterAsync(html);
        return html;
    }
    getPlatformScript() {
        return `
      // Remerge Playable Ad
      // 使用 FbPlayableAd.onCTAClick() 跳转（无参数）
      
      if (typeof FbPlayableAd !== 'undefined') {
        // 在 CTA 按钮点击时调用
        // FbPlayableAd.onCTAClick();
      }
    `;
    }
    validateOptions() {
        if (this.options.format && this.options.format !== 'html') {
            console.warn('警告: Remerge 使用单文件 HTML 格式');
        }
    }
}
