{
  onStart(pokemon) {
    this.effectState.boosterUsed = false;
    this.effectState.applied = false;
    this.effectState.trigger = null;

    if (!pokemon.volatiles['chronocatalystbooster']) {
      pokemon.addVolatile('chronocatalystbooster');
    }

    if (pokemon.getItem()?.id === 'boosterenergy') {
      this.effectState.boosterUsed = true;
      this.effectState.applied = true;
      this.effectState.trigger = 'booster';
      this.effectState.boostStat = pokemon.getBestStat(false, true);
      this.effectState.boostValue = this.effectState.boostStat === 'spe' ? 1.5 : 1.3;
      pokemon.addVolatile('chronocatalyst');
      this.add('-activate', pokemon, 'ability: Chrono Catalyst', '[from] Booster Energy');
      pokemon.useItem();
    }

    this.singleEvent('TerrainChange', this.effect, this.effectState, pokemon);
    this.singleEvent('WeatherChange', this.effect, this.effectState, pokemon);
  },

  onTerrainChange(pokemon) {
    if (this.effectState.applied) {
      if (this.effectState.trigger === 'terrain') {
        if (!this.field.isTerrain('electricterrain')) {
          this.effectState.applied = false;
          this.effectState.trigger = null;
          pokemon.removeVolatile('chronocatalyst');
          this.singleEvent('WeatherChange', this.effect, this.effectState, pokemon);
        }
      }
      return;
    }

    if (!this.effectState.boosterUsed && this.field.isTerrain('electricterrain')) {
      this.effectState.applied = true;
      this.effectState.trigger = 'terrain';
      this.effectState.boostStat = pokemon.getBestStat(false, true);
      this.effectState.boostValue = this.effectState.boostStat === 'spe' ? 1.5 : 1.3;
      pokemon.addVolatile('chronocatalyst');
      this.add('-activate', pokemon, 'ability: Chrono Catalyst', '[from] Electric Terrain');
    }
  },

  onWeatherChange(pokemon) {
    if (this.effectState.applied) {
      if (this.effectState.trigger === 'sunlight') {
        if (!(this.field.isWeather('sunnyday') || this.field.isWeather('desolateland'))) {
          this.effectState.applied = false;
          this.effectState.trigger = null;
          pokemon.removeVolatile('chronocatalyst');
          this.singleEvent('TerrainChange', this.effect, this.effectState, pokemon);
        }
      }
      return;
    }

    if (!this.effectState.boosterUsed &&
        (this.field.isWeather('sunnyday') || this.field.isWeather('desolateland')) &&
        this.effectState.trigger !== 'terrain') {
      this.effectState.applied = true;
      this.effectState.trigger = 'sunlight';
      this.effectState.boostStat = pokemon.getBestStat(false, true);
      this.effectState.boostValue = this.effectState.boostStat === 'spe' ? 1.5 : 1.3;
      pokemon.addVolatile('chronocatalyst');
      this.add('-activate', pokemon, 'ability: Chrono Catalyst', '[from] Harsh Sunlight');
    }
  },

  onSwitchOut(pokemon) {
    pokemon.removeVolatile('chronocatalyst');
    pokemon.removeVolatile('chronocatalystbooster');
    this.effectState.applied = false;
    this.effectState.trigger = null;
  },

  condition: {
    noCopy: true,
    onStart(pokemon, source, effect) {
      this.effectState.bestStat = this.effectState.boostStat;
    },
    onModifyAtkPriority: 5,
    onModifyAtk(atk, pokemon) {
      if (this.effectState.bestStat !== 'atk' || pokemon.ignoringAbility()) return;
      return this.chainModify(this.effectState.boostValue);
    },
    onModifyDefPriority: 6,
    onModifyDef(def, pokemon) {
      if (this.effectState.bestStat !== 'def' || pokemon.ignoringAbility()) return;
      return this.chainModify(this.effectState.boostValue);
    },
    onModifySpAPriority: 5,
    onModifySpA(spa, pokemon) {
      if (this.effectState.bestStat !== 'spa' || pokemon.ignoringAbility()) return;
      return this.chainModify(this.effectState.boostValue);
    },
    onModifySpDPriority: 6,
    onModifySpD(spd, pokemon) {
      if (this.effectState.bestStat !== 'spd' || pokemon.ignoringAbility()) return;
      return this.chainModify(this.effectState.boostValue);
    },
    onModifySpe(spe, pokemon) {
      if (this.effectState.bestStat !== 'spe' || pokemon.ignoringAbility()) return;
      return this.chainModify(1.5);
    },
    onEnd(pokemon) {
      this.add('-end', pokemon, 'Chrono Catalyst');
    }
  },

  flags: { failroleplay: 1, noreceiver: 1, noentrain: 1, notrace: 1, failskillswap: 1, notransform: 1 },
  name: 'Chrono Catalyst',
  rating: 4.5,
  num: -932
}
