import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * Fenêtre d'affichage de la version actuelle et des modifications apportées.
 */
public class ChangelogWindow extends JDialog{

    public ChangelogWindow(){
        //Paramétrage de la fenêtre
        this.setTitle("Version " + AppThinker.version);
        this.setModal(true);
        this.setSize(new Dimension(800, 375));
        Image img = null;
        try { img = ImageIO.read(AppThinker.class.getResource("img/logoAppThinker.png")); } catch (Exception ex) { }
        this.setIconImage(img);
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setLayout(new BorderLayout());

        JPanel panel = new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D) g;
                RenderingHints rh = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                g2.setRenderingHints(rh);
                Image img = null;
                try { img = ImageIO.read(AppThinker.class.getResource("img/logoAppThinker.png")); } catch (Exception ex) { }
                g2.drawImage(img, 0, 20, 300, 300, this);
                /*Informations du logiciel*/
                g2.setColor(new Color(63, 169, 245));
                g2.setFont(new Font("Arial", Font.BOLD, 40));
                g2.drawString("Thanks for downloading AppThinker !", 50, 45);
                g2.setFont(new Font("Arial", Font.PLAIN, 20));
                g2.drawString("Version " + AppThinker.version, 305, 80);
                g2.setFont(new Font("Arial", Font.PLAIN, 14));
                int i = 140;
                for(String a : AppThinker.changelog){
                    g2.drawString("> " + a, 305, i);
                    i += 25;
                }
            }
        };

        panel.setLayout(null);

        JButton ideas = new JButton("Add your ideas to the software !");
        ideas.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //Ouverture du lien de téléchargement
                try {
                    Desktop.getDesktop().browse(new URL("https://forms.gle/WG32HT947MKqdzhbA").toURI());
                } catch (URISyntaxException | IOException ex) { }
            }
        });
        panel.add(ideas);
        ideas.setBounds(305, 90, 250, 20);

        this.getContentPane().add(panel);

        this.setVisible(true);
    }
}
