using Jovian.EncounterSystem;
using Nox.Game.UI;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Nox.Game {
    public class EncounterView : IMenuView{
        private readonly EncounterPrefabs encounterPrefabs;
        private readonly IEncounterKind encounterKind;
        private IEncounter currentEncounter;

        private Dictionary<IEncounterKind, EncounterReference> encounterKindToPrefab = new ();
        private IEncounterKind currentActiveKind;

        public EncounterView(EncounterPrefabs encounterPrefabs) {
            this.encounterPrefabs = encounterPrefabs;
        }

        public void SetCurrentEncounter(IEncounter encounter) {
            currentEncounter = encounter;
            if(!encounterKindToPrefab.TryGetValue(encounter.EncounterDefinition.Kind, out var encounterReference)) {
                encounterReference = Object.Instantiate(encounterPrefabs.encounterSets.FirstOrDefault(e => e.encounterKind == encounterKind)?.encounterReference);
                encounterKindToPrefab.Add(encounter.EncounterDefinition.Kind, encounterReference);
            }
        }

        public void Initialize() { }

        public void Show() {
            currentActiveKind = currentEncounter.EncounterDefinition.Kind;
            PopulateEncounterReference();
            encounterKindToPrefab[currentActiveKind].gameObject.SetActive(true);
        }
        private void PopulateEncounterReference() {
        }

        public void Hide() {
            encounterKindToPrefab[currentActiveKind].gameObject.SetActive(false);
        }
        public void Tick() { }
    }
}
