import { _decorator, Component, EditBox, Node } from 'cc';
import { interact_page_data, ui_att_item } from '../../../data/data';
import { receive_widget_item } from './receive_widget_item';
import { ClientEvent } from '../../clientEvent';
import { config } from '../../config';
const { ccclass, property } = _decorator;

@ccclass('widget_interact_page')
export class widget_interact_page extends Component {
    @property(Node) img_bg:Node = null;
    @property(Node) btn_interact_left:Node = null;
    @property(Node) btn_interact_right:Node = null;
    @property(Node) img_item_interact_bg:Node = null;
    @property(Node) btn_sure:Node = null;
    @property(Node) img_item_interact:Node = null;
    @property(EditBox) editBoxAnswer:EditBox = null;
    private m_data:interact_page_data = null;
    public initView(data:interact_page_data){
        this.m_data = data;
        this.img_bg.getComponent(receive_widget_item).updateView(this.m_data.bg)
        this.btn_interact_left.getComponent(receive_widget_item).updateView(this.m_data.btn_interact_left)
        this.btn_interact_right.getComponent(receive_widget_item).updateView(this.m_data.btn_interact_right)
        this.img_item_interact_bg.getComponent(receive_widget_item).updateView(this.m_data.img_item_interact_bg)
       
        // this.btn_sure.getComponent(receive_widget_item).initView((d:ui_att_item)=>{
        //     this.m_data.btn_sure = d;
        //     ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,this.m_data,config.attributes_list_type.top)
        // })
        this.btn_sure.getComponent(receive_widget_item).updateView(this.m_data.btn_sure)

        this.img_item_interact.getComponent(receive_widget_item).updateView(this.m_data.img_item_interact_list[0])
        this.editBoxAnswer.string = this.editBoxAnswer.string;
        this.editBoxAnswer.node.on('editing-did-ended',()=>{
            this.m_data.answer =  parseInt(this.editBoxAnswer.string);
            ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,this.m_data,config.attributes_list_type.top)
        })
    }
}


