import { SingleSubject } from "../types/signal";
import { BalFocusListener } from "./focus.listener";
export class BalFocusSubject extends SingleSubject {
  constructor() {
    super((observer, data) => {
      if (data) {
        if (data.isFocusIn) {
          if (observer.hasFocus === false) {
            observer.focusInListener(data.ev);
          }
          observer.hasFocus = true;
        }
        if (data.isFocusOut) {
          observer.focusOutListener(data.ev);
          observer.hasFocus = false;
        }
      }
    });
    this.listener = new BalFocusListener();
  }
  attach(observer) {
    super.attach(observer);
    this.listener.connect(observer.el);
    this.listener.add(info => super.notify(info));
  }
  detach() {
    super.detach();
    this.listener.disconnect();
  }
}
