using CommunityToolkit.Mvvm.ComponentModel;
using Elwig.Models.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace Elwig.ViewModels {
    public partial class DeliveryAncmtAdminViewModel : ObservableObject {

        [ObservableProperty]
        private string? _searchQuery = "";
        public List<string> TextFilter => [.. SearchQuery?.ToLower().Split(' ').ToList().FindAll(e => e.Length > 0) ?? []];

        [ObservableProperty]
        private bool _filterOnlyUpcoming;
        [ObservableProperty]
        private bool _filterFromAllSchedules;
        [ObservableProperty]
        private string? _filterSeasonString;
        public int? FilterSeason {
            get => int.TryParse(FilterSeasonString, out var year) ? year : null;
            set => FilterSeasonString = $"{value}";
        }

        [ObservableProperty]
        private DeliveryAncmt? _selectedDeliveryAncmt;
        [ObservableProperty]
        private IEnumerable<DeliveryAncmt> _deliveryAncmts = [];
        [ObservableProperty]
        private DeliverySchedule? _selectedDeliverySchedule;
        [ObservableProperty]
        private IEnumerable<DeliverySchedule> _deliverySchedules = [];
        [ObservableProperty]
        private bool _enableSearchInputs = true;

        [ObservableProperty]
        private string? _mgNrString;
        public int? MgNr {
            get => int.TryParse(MgNrString, out var mgnr) ? mgnr : null;
            set => MgNrString = $"{value}";
        }
        [ObservableProperty]
        private Member? _member;
        [ObservableProperty]
        private IEnumerable<Member> _memberSource = [];
        [ObservableProperty]
        private string? _memberAddress;

        [ObservableProperty]
        private DeliverySchedule? _deliverySchedule;
        [ObservableProperty]
        private IEnumerable<DeliverySchedule> _deliveryScheduleSource = [];
        [ObservableProperty]
        private string? _sortId;
        [ObservableProperty]
        private WineVar? _wineVariety;
        [ObservableProperty]
        private IEnumerable<WineVar> _wineVarietySource = [];

        [ObservableProperty]
        private string? _weightString;
        public int? Weight {
            get => int.TryParse(WeightString, out var w) ? w : null;
            set => WeightString = $"{value}";
        }

        [ObservableProperty]
        private string _statusAncmts = "-";
        [ObservableProperty]
        private string _statusWeight = "-";
        [ObservableProperty]
        private string _statusAncmtCreated = "-";
        [ObservableProperty]
        private string _statusAncmtModified = "-";

        [ObservableProperty]
        private Grid? _statusWeightToolTip;

        [ObservableProperty]
        private Visibility _controlButtonsVisibility = Visibility.Visible;
        [ObservableProperty]
        private Visibility _editingButtonsVisibility = Visibility.Hidden;
    }
}
