// Priority: 3
/**

  █▀▄▀█ █▀█ █▄░█ █░█ █▀▄▀█ █▀▀ █▄░█ ▀█▀ ▄▀█ █░░   █▀▀ ▀▄▀ █▀█ █▀▀ █▀█ █ █▀▀ █▄░█ █▀▀ █▀▀
  █░▀░█ █▄█ █░▀█ █▄█ █░▀░█ ██▄ █░▀█ ░█░ █▀█ █▄▄   ██▄ █░█ █▀▀ ██▄ █▀▄ █ ██▄ █░▀█ █▄▄ ██▄

  ☻/  * @file Starting Kit script for give Player starting items on first login
  /▌  * @copyright KnightDexx's Modded Minecraft World & ModernGamingWorld
  /▌  * Modified by @Cyn-SolveroftheAbsoluteGremlins on Discord
  /\

*/
PlayerEvents.loggedIn(event => {
  const player = event.player

  // Only run if the player hasn't received the starter kit yet
  if (!player.stages.has('starting_items')) {

    // Mark stage immediately
    player.stages.add('starting_items')

    // Main starter items after 1 tick (inventory ready)
    // PORTED: schedule → scheduleInTicks
    event.server.scheduleInTicks(1, () => {

      // === Equip armor & shield ===
      player.setHeadArmorItem(Item.of('minecraft:leather_helmet'))
      player.setChestArmorItem(Item.of('minecraft:leather_chestplate'))
      player.setLegsArmorItem(Item.of('minecraft:leather_leggings'))
      player.setFeetArmorItem(Item.of('minecraft:leather_boots'))
      player.setOffHandItem(Item.of('minecraft:shield'))

      // === Default starter items ===
      const defaultKit = [
        Item.of('minecraft:oak_sapling', 4),
        Item.of('minecraft:iron_sword'),
        Item.of('minecraft:iron_pickaxe'),
        Item.of('minecraft:iron_shovel'),
        Item.of('minecraft:iron_axe'),
        Item.of('constructionwand:iron_wand'),
        Item.of('naturescompass:naturescompass'),
        Item.of('prefab:item_house_improved'),
        Item.of('prefab:item_farm_improved'),
        Item.of('minecraft:cookie', 4),
        Item.of('comforts:sleeping_bag_light_blue'),
        Item.of('minecraft:crafting_table'),
        Item.of('minecraft:smithing_table')
      ]

      defaultKit.forEach(item => player.give(item))
    })

    // Backpack after 2 ticks (inventory fully initialized)
    // PORTED: schedule → scheduleInTicks
    event.server.scheduleInTicks(2, () => {
      if (Platform.isLoaded('sophisticatedbackpacks')) {
        player.give(Item.of('sophisticatedbackpacks:backpack'))
      }
    })
  }
})
