import { _decorator, Component, Node } from 'cc';
import { ui_att_item } from '../../../data/data';
import { receive_res_item } from '../uiWidget/receive_res_item';
import { tools } from '../../tools';
const { ccclass, property } = _decorator;

@ccclass('scene_tips_rule_item')
export class scene_tips_rule_item extends Component {
    @property(Node) res_node:Node = null;
    @property(Node) btn_delete:Node = null;
    @property(Node) btn_clear:Node = null;
    private m_data:ui_att_item = null;
    private m_index:number = 0;
    private m_call_back = null;
    public initView(data:ui_att_item,index:number,call,type){
        this.m_data =data;
        this.m_call_back = call;
        this.m_index = index;
        this.res_node.getComponent(receive_res_item).initView(this.m_data,type)
        this.btn_delete.off(Node.EventType.TOUCH_END)
        this.btn_delete.on(Node.EventType.TOUCH_END,()=>{
            if(this.m_call_back!=null){
                tools.show_dialog("确定删除此按钮？",()=>{
                    this.m_call_back(this.m_index)
                    this.node.destroy()
                    this.node.removeFromParent()
                })
            }
        })

        if(this.btn_clear!=null){
            this.btn_clear.off(Node.EventType.TOUCH_END)
            this.btn_clear.on(Node.EventType.TOUCH_END,()=>{
                this.m_data.res_name = ""
                this.m_data.res = ""
                this.res_node.getComponent(receive_res_item).initView(this.m_data,type)
            })
        }

    }

    protected onDestroy(): void {
        this.res_node.destroy()
    }
}


