import { GameProp, RewardState } from "../../../data/GameData";

/**
 * 签到界面
 * - 每天第一次上线默认弹出一次【除首日】
 * - 全部签完后，不可再签到。此处需要判断上次签到天数。
 * - 签到数据几点刷新？什么方式刷新？ 与后端沟通
 * @author 薛鸿潇
 */
const { ccclass, property } = cc._decorator;

@ccclass
export default class Sign extends cc.Component {

    @property({ type: cc.ScrollView, displayName: '滚动视图' })
    private scroll_view: cc.ScrollView = null!;
    @property({ type: cc.Animation, displayName: '按钮_动画' })
    private anim_btn: cc.Animation = null!;

    onLoad() {

    }

    start() {
        gData.sign.sign_can = gData.gameData.getProp(GameProp.sign_can)
        gData.sign.initListData();
        gData.sign.init_data = true;
    }

    /**
     * 初始化滚动视图
     */
    private initScollView() {
        let list_data = gData.sign.list_data;
        this.scroll_view.node.emit('srollview-init', list_data)
    }

    /**
     * 点击领取按钮
     */
    private clickReceiveReward() {
        gData.sign.sign_can = 0;
        gData.sign.sign_last_bar++;
        gData.gameData.setProp(GameProp.sign_can, gData.sign.sign_can)
        gData.gameData.setProp(GameProp.sign_last_bar, gData.sign.sign_last_bar)
    }

    update(dt) {
        if (gData.sign.init_data) {
            gData.sign.init_data = false;
            this.initScollView();
            this.initBtnStyle();
        }
    }

    /**
     * 初始化按钮样式
     */
    private initBtnStyle() {
        if (gData.sign.sign_can) {
            this.anim_btn.play();
            this.anim_btn.getComponent('SetGray').setGray(false);
        } else {
            this.anim_btn.stop();
            this.anim_btn.node.scale = 1;
            this.anim_btn.getComponent('SetGray').setGray(true);
        }
    }
}
