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

@ccclass('mailbox_read_item')
export class mailbox_read_item extends base_ui {
    @property(Node) lab_title:Node = null
    @property(Node) lab_time:Node = null
    @property(Node) lab_read_status:Node = null
    @property(Node) img_read_dot:Node = null
    @property(SpriteFrame) sf_read:SpriteFrame = null
    @property(SpriteFrame) sf_unread:SpriteFrame = null


    private read_color:Color = new Color().fromHEX("#7a8594")
    private unread_color:Color = new Color().fromHEX("#000000")
    private m_data:mail_item_data = null
    private m_click_cb = null
    start() {
        this.onButtonListen(this.node, ()=>{
            if(this.m_click_cb) {
                this.m_click_cb(this)
            }
        })
    }

    initView(data:mail_item_data, click_cb) {
        this.setData(data)
        this.m_click_cb = click_cb
    }

    public setData(data:mail_item_data) {
        this.m_data = data
        this.lab_title.getComponent(Label).string = this.m_data.title
        this.lab_time.getComponent(Label).string = this.m_data.create_at
        if(this.m_data.state==1) {
            this.node.getComponent(Sprite).spriteFrame = this.sf_read
            this.lab_title.getComponent(Label).color = this.read_color
            this.lab_time.getComponent(Label).color = this.read_color
            this.lab_read_status.getComponent(Label).color = this.read_color
            this.lab_read_status.getComponent(Label).string = '已读'
            this.img_read_dot.active = false
        } else {
            this.node.getComponent(Sprite).spriteFrame = this.sf_unread
            this.lab_title.getComponent(Label).color = this.unread_color
            this.lab_time.getComponent(Label).color = this.unread_color
            this.lab_read_status.getComponent(Label).color = new Color().fromHEX("#008614")
            this.lab_read_status.getComponent(Label).string = '未读'
            this.img_read_dot.active = true
        }
    }

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

