import List from "../../Script/module/RankList/List";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    //商店界面
    @property(cc.Node)
    shop: cc.Node = null;
    //商品列表
    @property(cc.Node)
    itemList: cc.Node = null;
    // onLoad () {}

    start() {
        this.openShop();
    }
    //打开商店界面
    openShop() {
        // 商品数据数组
        const products = [
            { product_id: "gold_pack_1", name: "金币包1", price: 600, title: "3x2六档金币" },
            { product_id: "gold_pack_2", name: "金币包2", price: 3600, title: "" },
            { product_id: "gold_pack_3", name: "金币包3", price: 6800, title: "" },
            { product_id: "gold_pack_4", name: "金币包4", price: 12800, title: "" },
            { product_id: "gold_pack_5", name: "金币包5", price: 32800, title: "" },
            { product_id: "gold_pack_6", name: "金币包6", price: 64800, title: "" },
            { product_id: "unlimited_health_bundle_1", name: "无限体力组合包1", price: 1800, title: "3个横版礼包" },
            { product_id: "unlimited_health_bundle_2", name: "无限体力组合包2", price: 6600, title: "" }
        ];
        for (let i = 1; i <= 8 && i < this.itemList.children.length; i++) {
            const spriteComp = this.itemList.children[i].children[0].getComponent(cc.Sprite);
            const price = this.itemList.children[i].children[1].getComponent(cc.Label);
            const title = this.itemList.children[i].children[2].getComponent(cc.Label);
            const product = products[i - 1];
            if (spriteComp && product) {
                // TODO: 根据 product_id 或 name 设置 spriteComp.spriteFrame
            }
            if (price && product) {
                price.string = (product.price / 100).toString() + "元";
            }
            if (title && product) {
                title.string = product.name;
            }
        }
    }


    //关闭商店界面
    closeShop() {
        //销毁预制体
        this.shop.destroy();
    }

    // update (dt) {}
}
