import { _decorator, Component, Node } from 'cc';
import JNLayerBase from '../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase';
import { Prefab } from 'cc';
import { TD } from '../../App';
import { instantiate } from 'cc';
import { Button } from 'cc';
import { EventHandler } from 'cc';
import { Input } from 'cc';
import { TB, TbGResource } from '../../config/data/schema';
import { API } from '../../consts/API';
import { Label } from 'cc';
import { EditBox } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Debugger')
export class Debugger extends JNLayerBase {

    @property(EditBox)
    text:EditBox;

    @property(Node)
    resources:Node;

    @property(Prefab)
    debuger:Prefab;

    onJNLoad(data?: any): void {
        super.onJNLoad();
        this.onUpdateView();
    }

    onUpdateView(){
        TD.TbGResource.getDataList().forEach(config => {
            let debuger:Node;
            this.resources.addChild(debuger = instantiate(this.debuger));
            debuger.on(Input.EventType.TOUCH_END,async () => await this.onClickResources(config),this);
            debuger.getComponentInChildren(Label).string = config.name;
        })
    }

    async onClickResources(config:TB.TbGResource){
        await API.DebuggerAddResource(config.id,parseInt(this.text.string) || 1);
    }

}


