using System;
using System.Drawing;
using System.Windows.Forms;
using BettingPredictor.UI;

namespace BettingPredictor
{
    partial class Main
    {
        private System.ComponentModel.IContainer components = null;

        // Layout
        private Panel panelSidebar;
        private Panel panelContent;
        private Panel panelHeader;
        private Label labelAppTitle;
        private Label labelPageTitle;

        // Nav
        private NavButton navFootball;
        private NavButton navHorseRacing;
        private NavButton navSettings;
        private NavButton navInfo;

        // Pagine
        private Panel pageFootball;
        private Panel pageHorseRacing;
        private Panel pageSettings;
        private Panel pageInfo;

        // Football
        private DateTimePicker dateTimePicker;
        private ModernButton btnDownload;
        private ModernButton btnExportCsv;
        private ModernProgressBar progressBarFootball;
        private Label labelStatusFootball;
        private DataGridView dataGridViewFootball;

        // Horse Racing
        private ComboBox cmbRacingDay;
        private ModernButton btnDownloadRacing;
        private ModernButton btnExportRacingCsv;
        private ModernProgressBar progressBarRacing;
        private Label labelStatusRacing;
        private DataGridView dataGridViewRacing;

        // Impostazioni
        private Label lblApiKey;
        private TextBox txtApiKey;
        private Label lblExportPath;
        private TextBox txtExportPath;
        private ModernButton btnBrowseExport;
        private Label lblRacingUser;
        private TextBox txtRacingUser;
        private Label lblRacingPass;
        private TextBox txtRacingPass;
        private ModernButton btnSaveSettings;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
                components.Dispose();
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.SuspendLayout();

            // ============================================================
            // FORM
            // ============================================================
            this.ClientSize = new Size(1050, 620);
            this.MinimumSize = new Size(860, 520);
            this.Text = "Betting Predictor";
            this.Name = "Main";
            this.StartPosition = FormStartPosition.CenterScreen;
            this.BackColor = ModernTheme.ContentBackground;
            this.ForeColor = ModernTheme.TextPrimary;
            this.Font = ModernTheme.BodyFont;
            this.DoubleBuffered = true;
            this.Load += new EventHandler(this.Main_Load);
            this.Resize += new EventHandler(this.Main_Resize);

            // ============================================================
            // SIDEBAR  (Dock=Left, larghezza fissa)
            // ============================================================
            this.panelSidebar = new Panel
            {
                Dock = DockStyle.Left,
                Width = ModernTheme.SidebarWidth,
                BackColor = ModernTheme.SidebarBackground
            };

            this.labelAppTitle = new Label
            {
                Text = "Betting\nPredictor",
                Font = new Font("Segoe UI", 15F, FontStyle.Bold),
                ForeColor = ModernTheme.PrimaryColor,
                BackColor = ModernTheme.SidebarBackground,
                Dock = DockStyle.Top,
                Height = 72,
                TextAlign = ContentAlignment.MiddleCenter
            };

            var sep = new Panel
            {
                Dock = DockStyle.Top,
                Height = 1,
                BackColor = ModernTheme.CardBorder
            };

            // Nav — ordine di aggiunta inverso rispetto a quello visivo (Dock=Top)
            this.navInfo = new NavButton("Info", "i");
            this.navInfo.Click += new EventHandler(this.navInfo_Click);

            this.navSettings = new NavButton("Impostazioni", "#");
            this.navSettings.Click += new EventHandler(this.navSettings_Click);

            this.navHorseRacing = new NavButton("Corse Cavalli", "H");
            this.navHorseRacing.Click += new EventHandler(this.navHorseRacing_Click);

            this.navFootball = new NavButton("Calcio", "F");
            this.navFootball.IsActive = true;
            this.navFootball.Click += new EventHandler(this.navFootball_Click);

            this.panelSidebar.Controls.Add(this.navInfo);
            this.panelSidebar.Controls.Add(this.navSettings);
            this.panelSidebar.Controls.Add(this.navHorseRacing);
            this.panelSidebar.Controls.Add(this.navFootball);
            this.panelSidebar.Controls.Add(sep);
            this.panelSidebar.Controls.Add(this.labelAppTitle);

            // ============================================================
            // HEADER  (Dock=Top dentro panelContent)
            // ============================================================
            this.panelHeader = new Panel
            {
                Dock = DockStyle.Top,
                Height = 56,
                BackColor = ModernTheme.HeaderBackground,
                Padding = new Padding(24, 0, 24, 0)
            };

            this.labelPageTitle = new Label
            {
                Text = "Calcio",
                Font = ModernTheme.TitleFont,
                ForeColor = ModernTheme.TextPrimary,
                BackColor = ModernTheme.HeaderBackground,
                Dock = DockStyle.Fill,
                TextAlign = ContentAlignment.MiddleLeft
            };
            this.panelHeader.Controls.Add(this.labelPageTitle);

            var headerLine = new Panel
            {
                Dock = DockStyle.Bottom,
                Height = 1,
                BackColor = ModernTheme.CardBorder
            };
            this.panelHeader.Controls.Add(headerLine);

            // ============================================================
            // CONTENT WRAPPER  (Dock=Fill, contiene header + pagine)
            // ============================================================
            this.panelContent = new Panel
            {
                Dock = DockStyle.Fill,
                BackColor = ModernTheme.ContentBackground
            };

            // ============================================================
            // PAGE: CALCIO
            // ============================================================
            this.pageFootball = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(24, 16, 24, 16),
                BackColor = ModernTheme.ContentBackground,
                Visible = true
            };

            // -- toolbar (altezza fissa, posizionamento manuale) --
            var toolbarFb = new Panel
            {
                Dock = DockStyle.Top,
                Height = 48,
                BackColor = ModernTheme.ContentBackground
            };

            this.dateTimePicker = new DateTimePicker
            {
                Format = DateTimePickerFormat.Short,
                Value = DateTime.Today,
                Font = ModernTheme.BodyFont,
                CalendarMonthBackground = ModernTheme.InputBackground,
                CalendarForeColor = ModernTheme.InputText
            };

            this.btnDownload = new ModernButton { Text = "Scarica Partite", Size = new Size(140, 34) };
            this.btnDownload.Click += new EventHandler(this.btnDownload_Click);

            this.btnExportCsv = new ModernButton
            {
                Text = "Esporta CSV",
                AccentColor = ModernTheme.SuccessColor,
                Size = new Size(120, 34),
                Enabled = false
            };
            this.btnExportCsv.Click += new EventHandler(this.btnExportCsv_Click);

            toolbarFb.Controls.Add(this.dateTimePicker);
            toolbarFb.Controls.Add(this.btnDownload);
            toolbarFb.Controls.Add(this.btnExportCsv);

            // -- status --
            var statusFb = new Panel
            {
                Dock = DockStyle.Top,
                Height = 30,
                BackColor = ModernTheme.ContentBackground
            };

            this.progressBarFootball = new ModernProgressBar { Dock = DockStyle.Top };

            this.labelStatusFootball = new Label
            {
                Text = "Pronto",
                Font = ModernTheme.SmallFont,
                ForeColor = ModernTheme.TextSecondary,
                BackColor = ModernTheme.ContentBackground,
                Dock = DockStyle.Fill,
                TextAlign = ContentAlignment.MiddleLeft
            };
            statusFb.Controls.Add(this.labelStatusFootball);
            statusFb.Controls.Add(this.progressBarFootball);

            // -- grid --
            this.dataGridViewFootball = new DataGridView { Dock = DockStyle.Fill };
            ((System.ComponentModel.ISupportInitialize)this.dataGridViewFootball).BeginInit();
            ModernTheme.StyleDataGridView(this.dataGridViewFootball);

            this.pageFootball.Controls.Add(this.dataGridViewFootball);
            this.pageFootball.Controls.Add(statusFb);
            this.pageFootball.Controls.Add(toolbarFb);

            // ============================================================
            // PAGE: CORSE CAVALLI
            // ============================================================
            this.pageHorseRacing = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(24, 16, 24, 16),
                BackColor = ModernTheme.ContentBackground,
                Visible = false
            };

            // -- toolbar racing --
            var toolbarRacing = new Panel
            {
                Dock = DockStyle.Top,
                Height = 48,
                BackColor = ModernTheme.ContentBackground,
                Name = "toolbarRacing"
            };

            this.cmbRacingDay = new ComboBox
            {
                DropDownStyle = ComboBoxStyle.DropDownList,
                Font = ModernTheme.BodyFont,
                BackColor = ModernTheme.InputBackground,
                ForeColor = ModernTheme.InputText,
                FlatStyle = FlatStyle.Flat,
                Size = new Size(160, 28)
            };
            this.cmbRacingDay.Items.AddRange(new object[] { "Oggi", "Domani" });
            this.cmbRacingDay.SelectedIndex = 0;

            this.btnDownloadRacing = new ModernButton { Text = "Scarica Corse", Size = new Size(140, 34) };
            this.btnDownloadRacing.Click += new EventHandler(this.btnDownloadRacing_Click);

            this.btnExportRacingCsv = new ModernButton
            {
                Text = "Esporta CSV",
                AccentColor = ModernTheme.SuccessColor,
                Size = new Size(120, 34),
                Enabled = false
            };
            this.btnExportRacingCsv.Click += new EventHandler(this.btnExportRacingCsv_Click);

            toolbarRacing.Controls.Add(this.cmbRacingDay);
            toolbarRacing.Controls.Add(this.btnDownloadRacing);
            toolbarRacing.Controls.Add(this.btnExportRacingCsv);

            // -- status racing --
            var statusRacing = new Panel
            {
                Dock = DockStyle.Top,
                Height = 30,
                BackColor = ModernTheme.ContentBackground
            };

            this.progressBarRacing = new ModernProgressBar { Dock = DockStyle.Top };

            this.labelStatusRacing = new Label
            {
                Text = "Pronto",
                Font = ModernTheme.SmallFont,
                ForeColor = ModernTheme.TextSecondary,
                BackColor = ModernTheme.ContentBackground,
                Dock = DockStyle.Fill,
                TextAlign = ContentAlignment.MiddleLeft
            };
            statusRacing.Controls.Add(this.labelStatusRacing);
            statusRacing.Controls.Add(this.progressBarRacing);

            // -- grid racing --
            this.dataGridViewRacing = new DataGridView { Dock = DockStyle.Fill };
            ((System.ComponentModel.ISupportInitialize)this.dataGridViewRacing).BeginInit();
            ModernTheme.StyleDataGridView(this.dataGridViewRacing);

            this.pageHorseRacing.Controls.Add(this.dataGridViewRacing);
            this.pageHorseRacing.Controls.Add(statusRacing);
            this.pageHorseRacing.Controls.Add(toolbarRacing);

            // ============================================================
            // PAGE: IMPOSTAZIONI
            // ============================================================
            this.pageSettings = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(24, 16, 24, 16),
                BackColor = ModernTheme.ContentBackground,
                Visible = false
            };

            var settingsInner = new Panel
            {
                Dock = DockStyle.Top,
                Height = 400,
                BackColor = ModernTheme.CardBackground,
                Padding = new Padding(24)
            };

            this.lblApiKey = new Label
            {
                Text = "API Key (api-football)",
                Font = ModernTheme.SubtitleFont,
                ForeColor = ModernTheme.TextPrimary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(24, 24)
            };

            this.txtApiKey = new TextBox
            {
                Font = ModernTheme.BodyFont,
                BackColor = ModernTheme.InputBackground,
                ForeColor = ModernTheme.InputText,
                BorderStyle = BorderStyle.FixedSingle,
                Location = new Point(24, 52),
                Size = new Size(500, 28)
            };

            this.lblExportPath = new Label
            {
                Text = "Cartella esportazione CSV",
                Font = ModernTheme.SubtitleFont,
                ForeColor = ModernTheme.TextPrimary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(24, 100)
            };

            this.txtExportPath = new TextBox
            {
                Font = ModernTheme.BodyFont,
                BackColor = ModernTheme.InputBackground,
                ForeColor = ModernTheme.InputText,
                BorderStyle = BorderStyle.FixedSingle,
                ReadOnly = true,
                Location = new Point(24, 128),
                Size = new Size(400, 28)
            };

            this.btnBrowseExport = new ModernButton
            {
                Text = "Sfoglia...",
                IsPrimary = false,
                Size = new Size(90, 30),
                Location = new Point(434, 126)
            };
            this.btnBrowseExport.Click += new EventHandler(this.btnBrowseExport_Click);

            // Racing API credentials
            this.lblRacingUser = new Label
            {
                Text = "Racing API — Username",
                Font = ModernTheme.SubtitleFont,
                ForeColor = ModernTheme.TextPrimary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(24, 176)
            };

            this.txtRacingUser = new TextBox
            {
                Font = ModernTheme.BodyFont,
                BackColor = ModernTheme.InputBackground,
                ForeColor = ModernTheme.InputText,
                BorderStyle = BorderStyle.FixedSingle,
                Location = new Point(24, 204),
                Size = new Size(500, 28)
            };

            this.lblRacingPass = new Label
            {
                Text = "Racing API — Password",
                Font = ModernTheme.SubtitleFont,
                ForeColor = ModernTheme.TextPrimary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(24, 248)
            };

            this.txtRacingPass = new TextBox
            {
                Font = ModernTheme.BodyFont,
                BackColor = ModernTheme.InputBackground,
                ForeColor = ModernTheme.InputText,
                BorderStyle = BorderStyle.FixedSingle,
                UseSystemPasswordChar = true,
                Location = new Point(24, 276),
                Size = new Size(500, 28)
            };

            this.btnSaveSettings = new ModernButton
            {
                Text = "Salva impostazioni",
                AccentColor = ModernTheme.SuccessColor,
                Size = new Size(170, 36),
                Location = new Point(24, 330)
            };
            this.btnSaveSettings.Click += new EventHandler(this.btnSaveSettings_Click);

            settingsInner.Controls.Add(this.btnSaveSettings);
            settingsInner.Controls.Add(this.txtRacingPass);
            settingsInner.Controls.Add(this.lblRacingPass);
            settingsInner.Controls.Add(this.txtRacingUser);
            settingsInner.Controls.Add(this.lblRacingUser);
            settingsInner.Controls.Add(this.btnBrowseExport);
            settingsInner.Controls.Add(this.txtExportPath);
            settingsInner.Controls.Add(this.lblExportPath);
            settingsInner.Controls.Add(this.txtApiKey);
            settingsInner.Controls.Add(this.lblApiKey);

            this.pageSettings.Controls.Add(settingsInner);

            // ============================================================
            // PAGE: INFO
            // ============================================================
            this.pageInfo = new Panel
            {
                Dock = DockStyle.Fill,
                Padding = new Padding(24, 16, 24, 16),
                BackColor = ModernTheme.ContentBackground,
                Visible = false
            };

            var infoInner = new Panel
            {
                Dock = DockStyle.Top,
                Height = 280,
                BackColor = ModernTheme.CardBackground,
                Padding = new Padding(32)
            };

            int infoY = 32;

            var lblInfoTitle = new Label
            {
                Text = "Betting Predictor",
                Font = new Font("Segoe UI", 20F, FontStyle.Bold),
                ForeColor = ModernTheme.PrimaryColor,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(32, infoY)
            };
            infoY += 48;

            var lblVersion = new Label
            {
                Text = "Versione 1.0.0",
                Font = ModernTheme.SubtitleFont,
                ForeColor = ModernTheme.TextSecondary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(32, infoY)
            };
            infoY += 36;

            var lblDesc = new Label
            {
                Text = "Applicazione per lo scaricamento e l'analisi di dati sportivi\n" +
                       "tramite API esterne. Supporta l'esportazione in CSV.\n\n" +
                       "Sviluppato con .NET Framework 4.8.1  |  WinForms",
                Font = ModernTheme.BodyFont,
                ForeColor = ModernTheme.TextPrimary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(32, infoY)
            };
            infoY += 90;

            var lblCopy = new Label
            {
                Text = $"© {DateTime.Now.Year}  —  Tutti i diritti riservati",
                Font = ModernTheme.SmallFont,
                ForeColor = ModernTheme.TextSecondary,
                BackColor = ModernTheme.CardBackground,
                AutoSize = true,
                Location = new Point(32, infoY)
            };

            infoInner.Controls.Add(lblCopy);
            infoInner.Controls.Add(lblDesc);
            infoInner.Controls.Add(lblVersion);
            infoInner.Controls.Add(lblInfoTitle);

            this.pageInfo.Controls.Add(infoInner);

            // ============================================================
            // ASSEMBLY
            // ============================================================
            // Le pagine vanno aggiunte PRIMA dell'header nel panelContent
            // perché con Dock=Fill devono occupare lo spazio rimanente.
            this.panelContent.Controls.Add(this.pageFootball);
            this.panelContent.Controls.Add(this.pageHorseRacing);
            this.panelContent.Controls.Add(this.pageSettings);
            this.panelContent.Controls.Add(this.pageInfo);
            this.panelContent.Controls.Add(this.panelHeader);

            this.Controls.Add(this.panelContent);
            this.Controls.Add(this.panelSidebar);

            ((System.ComponentModel.ISupportInitialize)this.dataGridViewFootball).EndInit();
            ((System.ComponentModel.ISupportInitialize)this.dataGridViewRacing).EndInit();
            this.ResumeLayout(false);
        }

        /// <summary>
        /// Posiziona manualmente i controlli nelle toolbar
        /// </summary>
        private void LayoutToolbars()
        {
            // Football toolbar
            if (dateTimePicker != null && dateTimePicker.Parent != null)
            {
                var tb = dateTimePicker.Parent;
                int w = tb.ClientSize.Width;
                int y = 7;

                dateTimePicker.SetBounds(0, y, 200, 28);
                btnExportCsv.Location = new Point(w - btnExportCsv.Width, y);
                btnDownload.Location = new Point(btnExportCsv.Left - btnDownload.Width - 10, y);
            }

            // Horse Racing toolbar
            if (cmbRacingDay != null && cmbRacingDay.Parent != null)
            {
                var tb = cmbRacingDay.Parent;
                int w = tb.ClientSize.Width;
                int y = 7;

                cmbRacingDay.SetBounds(0, y, 160, 28);
                btnExportRacingCsv.Location = new Point(w - btnExportRacingCsv.Width, y);
                btnDownloadRacing.Location = new Point(btnExportRacingCsv.Left - btnDownloadRacing.Width - 10, y);
            }
        }
    }
}
