using System;
using System.Drawing;
using System.Windows.Forms;
using ModernControls;

namespace Elfisa.GradientButtonDemo
{
    internal sealed class GradientButtonDemoForm : Form
    {
        public GradientButtonDemoForm()
        {
            Text = "winforms-modern-buttons skill — демо";
            Size = new Size(980, 700);
            MinimumSize = new Size(860, 600);
            StartPosition = FormStartPosition.CenterScreen;
            BackColor = Color.FromArgb(245, 247, 250);
            Font = new Font("Segoe UI", 10f);

            var header = new Label
            {
                Text = "ModernGradientButton — градиент + тень + скругление (.NET Framework 4.7.2)",
                Dock = DockStyle.Top,
                Height = 52,
                Padding = new Padding(24, 16, 24, 0),
                Font = new Font("Segoe UI Semibold", 13f, FontStyle.Bold),
                ForeColor = Color.FromArgb(30, 41, 59)
            };

            var scroll = new Panel
            {
                Dock = DockStyle.Fill,
                AutoScroll = true,
                Padding = new Padding(24, 8, 24, 24)
            };

            var layout = new TableLayoutPanel
            {
                Dock = DockStyle.Top,
                AutoSize = true,
                ColumnCount = 2,
                Width = 900
            };
            layout.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 240));
            layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));

            AddRow(layout, "Primary (skill)", PresetButton(ModernGradientButton.Preset.Primary, "Сохранить"));
            AddRow(layout, "Success", PresetButton(ModernGradientButton.Preset.Success, "Подтвердить"));
            AddRow(layout, "Danger", PresetButton(ModernGradientButton.Preset.Danger, "Удалить"));
            AddRow(layout, "Neutral", PresetButton(ModernGradientButton.Preset.Neutral, "Отмена"));

            AddRow(layout, "Кастом (оранжевый)", CustomOrangeButton());
            AddRow(layout, "Pharma Trust — синяя", PharmaPrimaryButton());
            AddRow(layout, "Крестик × у поиска", ClearSearchButton());
            AddRow(layout, "Toolbar (мелкая)", ToolbarRow());

            var note = new Label
            {
                AutoSize = true,
                MaximumSize = new Size(860, 0),
                Margin = new Padding(0, 20, 0, 0),
                ForeColor = Color.FromArgb(100, 116, 139),
                Text =
                    "Skill: winforms-modern-buttons · Класс ModernControls.ModernGradientButton\n" +
                    "Наведите и нажмите — видны hover/pressed. Тень: ShadowDepth, градиент: GradientTop/Bottom.\n" +
                    "Основное приложение ЭльФиСА пока на Elfisa.UI.ModernButton — это отдельное демо для сравнения."
            };
            layout.Controls.Add(note, 0, layout.RowCount);
            layout.SetColumnSpan(note, 2);

            scroll.Controls.Add(layout);
            Controls.Add(scroll);
            Controls.Add(header);
        }

        private static void AddRow(TableLayoutPanel layout, string title, Control content)
        {
            var row = layout.RowCount;
            layout.RowStyles.Add(new RowStyle(SizeType.AutoSize));

            layout.Controls.Add(new Label
            {
                Text = title,
                AutoSize = true,
                Margin = new Padding(0, 18, 12, 8),
                Font = new Font("Segoe UI Semibold", 10f, FontStyle.Bold),
                ForeColor = Color.FromArgb(51, 65, 85)
            }, 0, row);

            content.Margin = new Padding(0, 14, 0, 4);
            layout.Controls.Add(content, 1, row);
            layout.RowCount++;
        }

        private static ModernGradientButton PresetButton(ModernGradientButton.Preset preset, string text)
        {
            var btn = new ModernGradientButton
            {
                Text = text,
                Size = new Size(160, 48),
                Margin = new Padding(0, 0, 12, 8)
            };
            btn.ApplyPreset(preset);
            btn.Click += (_, __) => MessageBox.Show(text + " — клик!", "Демо", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return btn;
        }

        private static ModernGradientButton CustomOrangeButton()
        {
            return new ModernGradientButton
            {
                Text = "Свой стиль",
                Size = new Size(180, 50),
                CornerRadius = 20,
                ShadowDepth = 6,
                GradientTop = Color.FromArgb(255, 179, 71),
                GradientBottom = Color.FromArgb(230, 126, 34),
                HoverGradientTop = Color.FromArgb(255, 195, 110),
                HoverGradientBottom = Color.FromArgb(245, 145, 50),
                PressedGradientTop = Color.FromArgb(220, 120, 30),
                PressedGradientBottom = Color.FromArgb(190, 100, 20)
            };
        }

        private static ModernGradientButton PharmaPrimaryButton()
        {
            var btn = new ModernGradientButton
            {
                Text = "Сохранить заказ",
                Size = new Size(190, 44),
                CornerRadius = 6,
                ShadowDepth = 4,
                GradientTop = Color.FromArgb(14, 116, 181),
                GradientBottom = Color.FromArgb(3, 105, 161),
                HoverGradientTop = Color.FromArgb(37, 130, 195),
                HoverGradientBottom = Color.FromArgb(7, 89, 133),
                PressedGradientTop = Color.FromArgb(12, 74, 110),
                PressedGradientBottom = Color.FromArgb(8, 60, 90)
            };
            return btn;
        }

        private static Control ClearSearchRow()
        {
            var panel = new FlowLayoutPanel { AutoSize = true, WrapContents = false };

            var search = new TextBox
            {
                Text = "прокладки",
                Width = 280,
                Height = 32,
                Font = new Font("Segoe UI", 10f),
                Margin = new Padding(0, 8, 8, 0)
            };

            var clear = new ModernGradientButton
            {
                Text = "×",
                Size = new Size(36, 36),
                CornerRadius = 6,
                ShadowDepth = 3,
                Font = new Font("Segoe UI Semibold", 13f, FontStyle.Bold),
                Margin = new Padding(0, 6, 0, 0)
            };
            clear.ApplyPreset(ModernGradientButton.Preset.Danger);
            clear.Click += (_, __) => search.Clear();

            panel.Controls.Add(search);
            panel.Controls.Add(clear);
            return panel;
        }

        private static Control ClearSearchButton()
        {
            return ClearSearchRow();
        }

        private static Control ToolbarRow()
        {
            var panel = new FlowLayoutPanel { AutoSize = true };

            var small = new ModernGradientButton
            {
                Text = "×",
                Size = new Size(32, 32),
                CornerRadius = 5,
                ShadowDepth = 2,
                Font = new Font("Segoe UI", 11f, FontStyle.Bold)
            };
            small.ApplyPreset(ModernGradientButton.Preset.Danger);

            var neutral = new ModernGradientButton
            {
                Text = "Фильтр",
                Size = new Size(100, 34),
                CornerRadius = 8,
                ShadowDepth = 3
            };
            neutral.ApplyPreset(ModernGradientButton.Preset.Neutral);

            panel.Controls.Add(small);
            panel.Controls.Add(neutral);
            return panel;
        }
    }
}
