using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Wordprocessing;
using ReAct_PME.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static ReAct_PME.ViewModels._ModalGenerateAgain_VM;

namespace ReAct_PME
{
    /// <summary>
    /// Logique d'interaction pour _ModalGenerateAgain.xaml
    /// </summary>
    public partial class _ModalGenerateAgain : Window
    {
        private _ModalGenerateAgain_VM _VM = new();
        public string ReponseNew { get; set; } = "";
        public bool IsOk { get; set; } = false;

        public _ModalGenerateAgain(string reponseOld, List<ContextGeneration> context)
        {
            InitializeComponent();
            DataContext = _VM;
            _VM.ReponseOld = reponseOld;
            //_VM.RaisonNewGenerate = raisonNewGenerate;
            _VM.Context = context;
        }

        private async void OnReGenerate_Click(object sender, RoutedEventArgs e)
        {
            BtnValide.IsEnabled = false;
            BtnGenerateAgain.IsEnabled = false;
            BtnCancel.IsEnabled = false;
            await Task.Delay(10);

            StatusText.Text = "";
            IsOk = await _VM.GenerateAgain();
            if (IsOk)
            {
                ReponseNew = _VM.ReponseNew;
                StatusText.Text = "Message générée avec succès";
                StatusText.Foreground = System.Windows.Media.Brushes.Green;
            }
            else
            {
                StatusText.Text = "Erreur dans la génération";
                StatusText.Foreground = System.Windows.Media.Brushes.Red;
            }

            BtnValide.IsEnabled = IsOk;
            BtnGenerateAgain.IsEnabled = true;
            BtnCancel.IsEnabled = true;
        }

        private void OnValide_Click(object sender, RoutedEventArgs e)
        {
            ReponseNew = _VM.ReponseNew; // en cas de modification par l'utilisateur
            IsOk = true;
            this.Close();
        }

        private void OnCancel_Click(object sender, RoutedEventArgs e)
        {
            IsOk = false;
            this.Close();
        }
    }
}
