import * as utils from "../../utils/index";
import { WornHat } from "../worn_hat";
class TopHat extends WornHat {
    constructor() {
        super(...arguments);
        this.hatTypeId = "ldz_crcomp:hat_top";
        this.cachedXP = 0;
    }
    async onEquip() {
        const wearer = this.hatWearer.Entity.getPlayer();
        if (wearer === null || wearer === void 0 ? void 0 : wearer.isValid()) {
            this.cachedXP = wearer.getTotalXp();
            utils.waitForLoopEvent(20, () => {
                if (wearer.isValid()) {
                    if (wearer.getTotalXp() > this.cachedXP) {
                        const xpGained = wearer.getTotalXp() - this.cachedXP;
                        this.cachedXP = wearer.addExperience(xpGained);
                    }
                    else if (wearer.getTotalXp() < this.cachedXP) {
                        this.cachedXP = wearer.getTotalXp();
                    }
                }
                return false;
            }, this.cancelCategory);
        }
    }
    async onUnequip() {
        utils.abortEvents(this.cancelCategory);
    }
}
WornHat.HatTable["ldz_crcomp:hat_top"] = TopHat;
