import { PlatformAdapter } from './base.js';
export class TikTokAdapter extends PlatformAdapter {
    getName() {
        return 'TikTok/Pangle';
    }
    getSizeLimit() {
        // TikTok/Pangle: 5MB
        return 5 * 1024 * 1024;
    }
    getDefaultFormat() {
        return 'zip';
    }
    async modifyHTML(html, assets) {
        // TikTok/Pangle 需要 Pangle JS-SDK
        const pangleScriptCode = `
      window.Pangle = window.Pangle || {
        open: function(url) {
          console.log('Pangle CTA: opening store');
        },
        ready: function() {
          console.log('Pangle SDK ready');
        }
      };
      window.openAppStore = window.openAppStore || function() {
        console.log('TikTok CTA: openAppStore');
        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 url = getOS() === 'ios' ? (_s.ios || '') : (_s.android || '');
        if (url) window.open(url, '_blank');
      };
    `;
        const pangleScript = await this.minifyPlatformScript(pangleScriptCode, 'pangle-sdk');
        const comment = `<!-- TikTok/Pangle: ZIP格式, config.json含playable_orientation, 禁止mraid.js -->`;
        // 在 </head> 之前插入
        html = html.replace('</head>', `${pangleScript}${comment}</head>`);
        // 注入统一的 CTA 适配器
        html = await this.injectCTAAdapterAsync(html);
        html = await this.injectTrackingAdapterAsync(html);
        return html;
    }
    getPlatformScript() {
        return `
      // TikTok/Pangle Playable Ad
      // 使用 Pangle SDK 进行跳转
      
      if (typeof Pangle !== 'undefined') {
        Pangle.ready();
      }
    `;
    }
    /**
     * 生成 config.json（TikTok/Pangle 要求）
     * @param orientation 0=横竖均可, 1=仅竖屏, 2=仅横屏
     */
    generateConfigJson(orientation = 0) {
        return {
            playable_orientation: orientation,
        };
    }
    validateOptions() {
        if (this.options.format && this.options.format !== 'zip') {
            console.warn('警告: TikTok/Pangle 要求 ZIP 格式');
        }
    }
}
