using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace ExcelAnalyzer
{
    /// <summary>
    /// SummaryForm displays a summary of usage and cost differences in a DataGridView and Chart.
    /// </summary>
    /// <remarks>
    /// This form is designed to present the differences in usage and cost over time, allowing users to visualize trends.
    /// </remarks>
    /// <example>
    /// Usage: Create an instance of SummaryForm with a dictionary containing date keys and tuple values for usage and cost differences.
    /// </example>
     partial class SummaryForm
    {
        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataVisualization.Charting.Chart chartSummary;

        private void InitializeComponent(Dictionary<string, (double usageDiff, double costDiff)> summaryData)
        {

            this.dataGridView1 = new DataGridView();
            this.chartSummary = new Chart();
            // Set up DataGridView
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.Add("Date", "Date");
            this.dataGridView1.Columns.Add("UsageDiff", "Usage Difference");
            this.dataGridView1.Columns.Add("CostDiff", "Cost Difference");
            this.dataGridView1.Location = new System.Drawing.Point(12, 12);
            this.dataGridView1.Size = new System.Drawing.Size(600, 200);
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            // Set up Chart
            ChartArea chartArea = new ChartArea("MainArea");
            chartSummary.ChartAreas.Add(chartArea);
            chartSummary.Location = new System.Drawing.Point(12, 230);
            chartSummary.Size = new System.Drawing.Size(600, 300);
            chartSummary.Titles.Add("Usage and Cost Differences");

            chartSummary.Series.Clear();
            chartSummary.Series.Add("Usage");
            chartSummary.Series.Add("Cost");
            chartSummary.Series["Usage"].ChartType = SeriesChartType.Column;
            chartSummary.Series["Cost"].ChartType = SeriesChartType.Column;

            // Populate data
            foreach (var kvp in summaryData)
            {
                string date = kvp.Key;
                double usageDiff = kvp.Value.usageDiff;
                double costDiff = kvp.Value.costDiff;

                dataGridView1.Rows.Add(date, usageDiff, costDiff);
                chartSummary.Series["Usage"].Points.AddXY(date, usageDiff);
                chartSummary.Series["Cost"].Points.AddXY(date, costDiff);
            }
        }
    }
}