using Elwig.Helpers;
using System.Windows;
using System.Windows.Controls;

namespace Elwig.Dialogs {
    public partial class AreaComTransferDialog : Window {

        public int CancelSeason { get; set; }
        public int SuccessorSeason => CancelSeason + 1;
        public bool MaintainYearFrom { get; set; }

        public string AreaComNum { get; set; }
        public string Area { get; set; }

        public AreaComTransferDialog(string name, int areaComNum, int area) {
            CancelSeason = Utils.FollowingSeason - 1;
            AreaComNum = $"{areaComNum:N0}";
            Area = $"{area:N0}";
            InitializeComponent();
            SeasonInput.Text = $"{CancelSeason}";
            Title = $"Aktive Flächenbindungen kündigen - {name}";
            QuestionBlock1.Visibility = Visibility.Hidden;
            QuestionBlock2.Visibility = Visibility.Visible;
            DescBlock1.Visibility = Visibility.Hidden;
            DescBlock2.Visibility = Visibility.Visible;
            CopyYearToInput.Visibility = Visibility.Hidden;
            Height = 240;
            SeasonInput.Margin = new(0, 40, 0, 0);
            SeasonLabel.Margin = new(0, 40, 100, 0);
        }

        public AreaComTransferDialog(string name, string successorName, int areaComNum, int area) {
            CancelSeason = Utils.FollowingSeason - 1;
            AreaComNum = $"{areaComNum:N0}";
            Area = $"{area:N0}";
            InitializeComponent();
            SeasonInput.Text = $"{CancelSeason}";
            Title = $"Aktive Flächenbindungen übertragen - {name} - {successorName}";
            InfoBlock.Visibility = Visibility.Hidden;
        }

        private void SeasonInput_TextChanged(object sender, TextChangedEventArgs evt) {
            CancelSeason = (int)SeasonInput.Value!;
            CancelSeason1.Text = $"{CancelSeason}";
            CancelSeason2.Text = $"{CancelSeason}";
            TransferSeason.Text = MaintainYearFrom ? "" : $"{SuccessorSeason}";
            DescBlock1Season.Text = MaintainYearFrom ? "dem originalen Beginn der FB" : "inkl. Saison ";
        }

        private void CopyYearToInput_Changed(object sender, RoutedEventArgs evt) {
            TransferSeason.Text = MaintainYearFrom ? "" : $"{SuccessorSeason}";
            DescBlock1Season.Text = MaintainYearFrom ? "dem originalen Beginn der FB" : "inkl. Saison ";
        }

        private void ConfirmButton_Click(object sender, RoutedEventArgs evt) {
            DialogResult = true;
            Close();
        }
    }
}
