import EventEmitter from '@erayt/titanOne-observer/lib/event';

const callbacks = {
  div() {},

  iframe(options) {
    const opts = options || {};
    const { scopeId, zoom } = opts;
    const $this = Eui(this);

    Eui.Processor.observer.setScopeRef(
      scopeId,
      new EventEmitter({
        scope: $this,
        isIframe: true,
      }),
    );

    Eui.postMessage($this, {
      env: Eui.env,
      command: 'ipc:env',
    });

    Eui.postMessage(
      $this,
      Eui.extend(true, {}, opts, {
        command: 'load',
      }),
    );

    if (zoom) {
      Eui.postMessage($this, {
        rata: zoom,
        command: 'zoom',
      });
    }
  },

  /**
   * 业务组件加载完成事件.
   * @param options
   */
  component(options) {
    const $this = Eui(this);
    const { scopeId } = options;
    if (scopeId) {
      const emitter = new EventEmitter({
        scope: $this,
      });
      Eui.Processor.observer.setScopeRef(scopeId, emitter);
    }
  },
};

export default callbacks;
