using System;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Minint.Core.Models;
using Minint.Core.Services;

namespace Minint.Views;

public partial class PatternDialog : Window
{
    public PatternType SelectedPattern =>
        PatternCombo.SelectedItem is PatternType pt ? pt : PatternType.Checkerboard;

    public RgbaColor PatternColor1
    {
        get
        {
            var c = Color1Picker.Color;
            return new RgbaColor(c.R, c.G, c.B, c.A);
        }
    }

    public RgbaColor PatternColor2
    {
        get
        {
            var c = Color2Picker.Color;
            return new RgbaColor(c.R, c.G, c.B, c.A);
        }
    }

    public int PatternParam1 => (int)(Param1.Value ?? 8);
    public int PatternParam2 => (int)(Param2.Value ?? 8);

    public PatternDialog()
    {
        InitializeComponent();

        PatternCombo.ItemsSource = Enum.GetValues<PatternType>().ToList();
        PatternCombo.SelectedIndex = 0;

        Color1Picker.Color = Color.FromRgb(0, 0, 0);
        Color2Picker.Color = Color.FromRgb(255, 255, 255);

        OkButton.Click += (_, _) => Close(true);
        CancelButton.Click += (_, _) => Close(false);
    }
}
