"use strict";

import ATReactNativeBridge from "../specs/NativeATBridge.js";
import { ATAdEvents } from "../events/ATAdEvents.js";
import { dispatchRewardEvent } from "./ATRewardVideoAd.js";
import { ATLog } from "../utils/ATLog.js";
/**
 * 激励视频 AutoLoad（静态入口；复用同一事件通道，callbackName 与手动 `ATRewardVideoAd` 完全一致）。
 */
export class ATRewardVideoAutoAd {
  static setAdListener(placementID, listener) {
    ATAdEvents.setAdListener(placementID, p => dispatchRewardEvent(listener, p));
  }
  static removeAdListener(placementID) {
    ATAdEvents.removeAdListener(placementID);
  }
  static addPlacement(placementID, settings = {}) {
    ATReactNativeBridge.addAutoLoadRewardedVideo(placementID, settings);
  }
  static removePlacement(placementID) {
    ATReactNativeBridge.removeAutoLoadRewardedVideo(placementID);
  }
  static isAdReady(placementID) {
    return ATReactNativeBridge.autoLoadRewardedVideoReady(placementID);
  }

  /**
   * 展示 AutoLoad 激励。
   * - 无参 / string：走 scenario 参数（showAutoLoadRewardedVideo）
   * - ATShowConfig 对象：走 showConfig（showAutoLoadRewardedVideoWithConfig）
   */
  static show(placementID, scenarioOrConfig) {
    if (typeof scenarioOrConfig === 'string') {
      return ATReactNativeBridge.showAutoLoadRewardedVideo(placementID, scenarioOrConfig);
    }
    if (scenarioOrConfig) {
      const bridge = ATReactNativeBridge;
      const showWithConfig = bridge.showAutoLoadRewardedVideoWithConfig;
      if (typeof showWithConfig === 'function') {
        return showWithConfig.call(bridge, placementID, scenarioOrConfig);
      }
      // 旧版原生未编进 showAutoLoadRewardedVideoWithConfig 时，经 scenario JSON 透传 showConfig。
      ATLog.call('ATRewardVideoAutoAd', 'show(showConfig fallback)', 'showAutoLoadRewardedVideoWithConfig unavailable; using JSON scenario');
      return ATReactNativeBridge.showAutoLoadRewardedVideo(placementID, JSON.stringify(scenarioOrConfig));
    }
    return ATReactNativeBridge.showAutoLoadRewardedVideo(placementID, '');
  }
}
//# sourceMappingURL=ATRewardVideoAutoAd.js.map