using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CtrEditor
{
    public class DatosDeTrabajo
    {
        public Dictionary<string, string> Imagenes { get; private set; }

        public DatosDeTrabajo()
        {
            Imagenes = new Dictionary<string, string>();
            CargarImagenes(); // Inicializar la carga de imágenes basada en el directorio persistente
        }

        public string ObtenerPathImagenConExtension(string key, string extension)
        {
            if (Imagenes.TryGetValue(key, out string imagePath))
            {
                string jsonPath = Path.ChangeExtension(imagePath, extension);
                return jsonPath;
            }
            return null;
        }

        public string? ObtenerPathAllPages(string extension)
        {
            string folderPath = EstadoPersistente.Instance.directorio; // Usar directamente desde el Singleton

            if (Directory.Exists(folderPath))
                return Path.ChangeExtension(folderPath + "\\allpages", extension);
            else return null;
        }


        public void CargarImagenes()
        {
            Imagenes.Clear();
            string folderPath = EstadoPersistente.Instance.directorio; // Usar directamente desde el Singleton

            if (Directory.Exists(folderPath))
            {
                var archivosImagen = Directory.GetFiles(folderPath, "*.png"); // Ajustar para otros formatos si es necesario
                foreach (var archivo in archivosImagen)
                {
                    var nombreArchivo = Path.GetFileName(archivo);
                    if (!Imagenes.ContainsKey(nombreArchivo))
                    {
                        Imagenes[nombreArchivo] = archivo;
                    }
                }
            }
        }
    }
}