{
    onStart(pokemon) {
        if (pokemon.baseSpecies.baseSpecies !== "Darmanitan" || pokemon.transformed) {
            return;
        }
        if (!["Zen", "Galar-Zen"].includes(pokemon.species.forme)) {
            pokemon.addVolatile("zenmode");
        }
        if (pokemon.species.name === "Darmanitan-Galar-Zen") {
            pokemon.abilityState.choiceLock = "";
        }
    },
    onResidualOrder: 29,
    onResidual(pokemon) {
        if (pokemon.species.name === "Darmanitan-Zen") {
            this.heal(pokemon.maxhp / 16);
        }
    },
    onBeforeMove(pokemon, target, move) {
        if (pokemon.species.name === "Darmanitan-Galar-Zen") {
            if (move.isZOrMaxPowered || move.id === "struggle") return;
            if (pokemon.abilityState.choiceLock && pokemon.abilityState.choiceLock !== move.id) {
                this.addMove("move", pokemon, move.name);
                this.attrLastMove("[still]");
                this.debug("Disabled by Zen Mode's choice lock");
                this.add("-fail", pokemon);
                return false;
            }
        }
    },
    onModifyMove(move, pokemon) {
        if (pokemon.species.name === "Darmanitan-Galar-Zen") {
            if (pokemon.abilityState.choiceLock || move.isZOrMaxPowered || move.id === "struggle") return;
            pokemon.abilityState.choiceLock = move.id;
        }
    },
    onDisableMove(pokemon) {
        if (pokemon.species.name === "Darmanitan-Galar-Zen") {
            if (!pokemon.abilityState.choiceLock) return;
            if (pokemon.volatiles["dynamax"]) return;
            for (const moveSlot of pokemon.moveSlots) {
                if (moveSlot.id !== pokemon.abilityState.choiceLock) {
                    pokemon.disableMove(moveSlot.id, false, this.effectState.sourceEffect);
                }
            }
        }
    },
    onEnd(pokemon) {
        if (!pokemon.volatiles["zenmode"] || !pokemon.hp) return;
        pokemon.transformed = false;
        delete pokemon.volatiles["zenmode"];
        if (pokemon.species.baseSpecies === "Darmanitan" && pokemon.species.battleOnly) {
            pokemon.formeChange(pokemon.species.battleOnly, this.effect, false, "[silent]");
        }

        if (pokemon.species.name === "Darmanitan-Galar-Zen") {
            pokemon.abilityState.choiceLock = "";
        }
    },
    condition: {
        onStart(pokemon) {
            if (!pokemon.species.name.includes("Galar")) {
                if (pokemon.species.id !== "darmanitanzen") {
                    pokemon.formeChange("Darmanitan-Zen");
                }
            } else {
                if (pokemon.species.id !== "darmanitangalarzen") {
                    pokemon.formeChange("Darmanitan-Galar-Zen");
                }
            }
        },
        onEnd(pokemon) {
            if (["Zen", "Galar-Zen"].includes(pokemon.species.forme)) {
                return;
            }
        }
    },
    flags: { failroleplay: 1, noreceiver: 1, noentrain: 1, notrace: 1, failskillswap: 1, cantsuppress: 1 },
    name: "Zen Mode",
    rating: 0,
    num: 161
}
