import { _decorator, Component, Node, SpriteFrame } from 'cc';
import { not_have_interact_data } from '../../../data/data';
import { receive_widget_item } from './receive_widget_item';
import { Attributes } from '../Attributes';
import { tools } from '../../tools';
import { ClientEvent } from '../../clientEvent';
import { config } from '../../config';
const { ccclass, property } = _decorator;

@ccclass('widget_not_have_interact')
export class widget_not_have_interact extends Component {
    @property(Node) bg_widget_info:Node = null;
    @property(Node) btn_original_size:Node = null;
    private m_data:not_have_interact_data = null;
    protected start(): void {
        this.btn_original_size.on(Node.EventType.TOUCH_END, ()=>{
            if(this.m_data.bg.res.length==0) {
                return tools.showToast('还没有图片')
            }
            tools.loadUrl(this.m_data.bg.res,null,(sf:SpriteFrame)=>{
                this.m_data.bg.width = sf.originalSize.width
                this.m_data.bg.height = sf.originalSize.height
                this.updateStatus()
                ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,Attributes.Singleton.get_cur_att_data(),config.attributes_list_type.top)
            })
        })
    }
    public initView(data:not_have_interact_data){
        this.m_data = data;
        this.updateStatus()
    }

    private updateStatus() {
        this.bg_widget_info.getComponent(receive_widget_item).updateView(this.m_data.bg)
    }
}


