import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { Achievement } from "./achievement";
export class CartoonAchievement extends Achievement {
    constructor() {
        super(...arguments);
        this.total = 16;
        this.SkinIndex = 3;
    }
    onSetup() {
        mc.world.afterEvents.itemUseOn.subscribe(this.useDyeOnSign.bind(this));
    }
    useDyeOnSign(event) {
        if (event.block.typeId.includes("sign") && event.itemStack.typeId.includes("dye")) {
            const player = new utils.SafetyCheckedPlayer(event.source);
            const progress = this.getProgress(player);
            const newDye = utils.addUniqueToArray(progress.items, event.itemStack.typeId);
            if (newDye) {
                const remaining = this.total - progress.items.length;
                utils.mclog(`Total Remaining ${remaining}`);
                this.setProgress(player, progress);
                if (remaining <= 0) {
                    this.setStatus(player, true);
                }
            }
        }
    }
    getProgress(player) {
        var _a;
        return (_a = utils.readDynamicProperty(player, utils.GlobalNamespace.Namespace + "achievement.cartoon")) !== null && _a !== void 0 ? _a : { items: [] };
    }
    setProgress(player, progress) {
        utils.writeDynamicProperty(player, utils.GlobalNamespace.Namespace + "achievement.cartoon", progress);
    }
    onReset(player) {
        super.onReset(player);
        this.setProgress(player, { items: [] });
    }
    getStatusText(player) {
        if (this.getStatus(player)) {
            return { rawtext: [
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.title.completed` },
                    { text: "\n" },
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.status.completed` },
                    { text: "\n\n" },
                ] };
        }
        else {
            return { rawtext: [
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.title.in_progress` },
                    { text: "\n" },
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.status.in_progress`, with: [String(this.total - this.getProgress(player).items.length)] },
                    { text: "\n\n" },
                ] };
        }
    }
}
new CartoonAchievement();
