/*
 * @Author: mojunshou 1637302775@qq.com
 * @Date: 2025-03-20 17:53:50
 * @LastEditors: mojunshou 1637302775@qq.com
 * @LastEditTime: 2025-04-11 10:28:16
 * @Description: 红包提现
 */
import { _decorator, Label, Node } from "cc";
import { oops } from "db://oops-framework/core/Oops";
import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
import { GameComponent } from "db://oops-framework/module/common/GameComponent";
import { GameEvent } from "../common/config/GameEvent";
import { UIID } from "../common/config/GameUIConfig";
import { CocosHandler } from "../common/manager/CocosHandler";
import List from "../ui/List";
import { RedPackeItemView } from "./RedPackeItemView";
import { ServerHandler } from "../common/manager/ServerHandler";

const { ccclass, property } = _decorator;

/** 视图层对象 */
@ccclass('RedPackeWithdrawalViewComp')
export class RedPackeWithdrawalViewComp extends GameComponent {

    @property(List)
    recordList: List = null!;

    @property(Label)
    lab_redNum: Label = null!;  //红包金额

    @property(Label)
    lab_tips: Label = null!;  //提示金额

    @property(Label)
    lab_wxNum: Label = null!;  //微信金额

    data: any[] = [];
    onLoad() {
        this.setButton();
        this.addEvent();
        const data = {
            title: `每日消除100次即可领取`,
            current: 1,
            total: 100,
            state: 0,
            goods: [
                {
                    type: 1001,
                    num: 100
                }
            ]
        }

        for (let i = 0; i < 10; i++) {
            this.data.push(data);
        }
        oops.log.logView(this.data, "this.data");
        this.recordList.numItems = this.data.length;
        oops.log.logView(this.recordList.numItems, "this.recordList.numItems");
    }



    addEvent() {
        oops.message.on(GameEvent.openRecordView, this.openRecordView, this);
    }


    private onListRender(item: Node, idx: number) {
        console.log("onListRender", idx);
        const itemView: RedPackeItemView | null = item.getComponent(RedPackeItemView);
        if (itemView) {
            console.log(">>>>>>>>>>>>>>>>>", itemView)
            itemView.setItem(this.data[idx], idx);
        }
    }

    private btn_back() {
        oops.gui.remove(UIID.RedPacketWithdraw);
    }


    private btn_record() {
        if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
            ServerHandler.inst.getRecordList();
        } else {
            oops.gui.open(UIID.WithdrawRecord);
        }
    }


    private openRecordView() {
        oops.gui.open(UIID.WithdrawRecord);
    }


    private btn_withdrawal() {
        //全部提现

    }

}