import { PlatformAdapter } from './base.js';
export class FacebookAdapter extends PlatformAdapter {
    getName() {
        return 'Facebook';
    }
    getSizeLimit() {
        // Facebook: HTML 5MB, ZIP 5MB（HTML 文件需 < 2MB 由校验处理）
        return 5 * 1024 * 1024;
    }
    getDefaultFormat() {
        return 'html';
    }
    async modifyHTML(html, assets) {
        // Facebook 需要 FbPlayableAd API
        const fbScriptCode = `
      window.FbPlayableAd = window.FbPlayableAd || {
        onCTAClick: function() {
          console.log('Facebook CTA clicked');
          function getOS(){
            var ua = navigator.userAgent || '';
            if (/iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) {
              return 'ios';
            } else if (/Android/i.test(ua)) {
              return 'android';
            }
            return 'unknown';
          }
          var _s = window.__PLAYCRAFT_STORE_URLS__ || {};
          var url = getOS() === 'ios' ? (_s.ios || '') : (_s.android || '');
          window.open(url, '_blank');
        }
      };
    `;
        // 压缩平台脚本
        const fbScript = await this.minifyPlatformScript(fbScriptCode, 'facebook-api');
        // 在 </head> 之前插入平台特定的 API
        html = html.replace('</head>', `${fbScript}</head>`);
        // 注入统一的 CTA 适配器
        html = await this.injectCTAAdapterAsync(html);
        html = await this.injectTrackingAdapterAsync(html);
        return html;
    }
    getPlatformScript() {
        return `
      // Facebook Playable Ad API
      if (typeof FbPlayableAd !== 'undefined') {
        // 在 CTA 按钮点击时调用
        // FbPlayableAd.onCTAClick();
      }
    `;
    }
}
