import { _decorator, Color, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { bag_type_item_data } from '../../data';
import { base_ui } from '../../fw/base_ui';
const { ccclass, property } = _decorator;

@ccclass('bag_type_item')
export class bag_type_item extends base_ui {
    @property(Node) lab_name:Node = null
    @property(SpriteFrame) sf_selected:SpriteFrame = null
    @property(SpriteFrame) sf_unSelected:SpriteFrame = null
    
    private color_selected:Color = new Color().fromHEX("#ffffff")
    private color_unselected:Color = new Color().fromHEX("#8995BA")
    private m_data:bag_type_item_data = null
    private m_click_cb = null

    protected start(): void {
        this.onButtonListen(this.node, ()=>{
            if(this.m_click_cb) {
                this.m_click_cb(this)
            }
        })
    }

    initView(data:bag_type_item_data, click_cb) {
        this.m_data = data
        this.m_click_cb = click_cb
        this.lab_name.getComponent(Label).string = this.m_data.name
    }

    public setSelected() {
        this.node.getComponent(Sprite).spriteFrame = this.sf_selected
        this.lab_name.getComponent(Label).color = this.color_selected
    }

    public setUnselected() {
        this.node.getComponent(Sprite).spriteFrame = this.sf_unSelected
        this.lab_name.getComponent(Label).color = this.color_unselected
    }

    public getData():bag_type_item_data {
        return this.m_data
    }

    
}

