import { _decorator, Component, Node, UIOpacity, Button } from 'cc';
import { LOG_TYPE, sendLog, sendWebNetWithToken, WebNetName } from '../../Utils/WebNet/WebNet';
import { ChangeEquipPanel } from './ChangeEquipPanel';
const { ccclass, property } = _decorator;

const MD_MAP = {
    1: 15,
    2: 16,
    3: 17
}

@ccclass('HandItem')
export class HandItem extends Component {

    handType: string = "";

    cePanel: Node = null;

    updateInfo(flag: boolean, handType: string, node: Node) {
        this.handType = handType;
        sendLog(LOG_TYPE.EXPOSURE, MD_MAP[this.handType]);
        this.cePanel = node;
        if (flag) {
            this.node.getChildByName("UseIcon").active = true;
            this.node.getChildByName("MainBtn").active = false;
            this.node.getChildByPath("Border/Select").getComponent(UIOpacity).opacity = 255;
        } else {
            this.node.getChildByName("UseIcon").active = false;
            this.node.getChildByName("MainBtn").active = true;
            this.node.getChildByPath("Border/Select").getComponent(UIOpacity).opacity = 0;
        }
    }

    start() {
        this.node.getChildByName("MainBtn").on(Button.EventType.CLICK, this.changeHand, this);
    }

    /** 更换爪子 */
    async changeHand() {
        sendLog(LOG_TYPE.CLICK, MD_MAP[this.handType]);
        const res = await sendWebNetWithToken(WebNetName.changeHand, {id: this.handType});
        if (res?.success) {
            this.cePanel.getComponent(ChangeEquipPanel).getEquipInfo();
        }
        // await this.cePanel.getComponent(ChangeEquipPanel).handInit();
    }

    update(deltaTime: number) {
        
    }
}

