import { _decorator, Component, Node } from "cc";
import BaseUI from "../../scripts/base/BaseUI";
import { Hall } from "../hall/Hall";
import { EditBox } from "cc";
const { ccclass, property } = _decorator;

export interface BindGameInputLayerListener {
  OnInput(input: string): void;
 }

@ccclass("BindGameInputLayer")
export class BindGameInputLayer extends BaseUI {
  static async show(listener: BindGameInputLayerListener) {
    let layer = await Hall.ins.showLayer("prefab/layer/BindGameInputLayer");
    layer.getComponent(BindGameInputLayer).init(listener);
  }

  @property(EditBox)
  public edit_code: EditBox = null;

  protected onLoad(): void {
    super.onLoad();
  }

  private listener: BindGameInputLayerListener;

  private init(listener: BindGameInputLayerListener) {
    this.listener = listener;
  }
 
  protected simpleOnBtnClick(name: string): void {
    switch (name) {
      case "btn_bind":
        let inputString = this.edit_code.string;
        this.closePage();
        this.listener.OnInput(inputString);
        break;
    }  
  }
}
