using Blahblah.FlowerApp.Data;
using Blahblah.FlowerApp.Data.Model;
using Microsoft.Extensions.Logging;
using static Blahblah.FlowerApp.Extensions;

namespace Blahblah.FlowerApp.Views.User;

public partial class LogPage : AppContentPage
{
    static readonly BindableProperty LogsProperty = CreateProperty<LogItem[], LogPage>(nameof(Logs));

    public LogItem[] Logs
    {
        get => GetValue<LogItem[]>(LogsProperty);
        set => SetValue(LogsProperty, value);
    }

    public Command ItemCommand { get; }

    public LogPage(FlowerDatabase database, ILogger logger) : base(database, logger)
    {
        ItemCommand = new Command(async o =>
        {
            if (o is LogItem item)
            {
                await Navigation.PushAsync(new LogItemPage(item));
            }
        });

        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        Task.Run(async () => Logs = await Database.GetLogs());
    }
}
