using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.ObjectModel;
using TodoList.Maui.Models;

namespace TodoList.Maui.ViewModels;

public partial class QuickEntryViewModel : ObservableObject
{
	private readonly Action _closeAction;

	[ObservableProperty]
	private string content = string.Empty;

	[ObservableProperty]
	private string priority = "中";

	public ObservableCollection<string> Priorities { get; } = new ObservableCollection<string>
	{
		"高",
		"中",
		"低"
	};

	public QuickEntryViewModel(Action closeAction)
	{
		_closeAction = closeAction;
	}

	[RelayCommand]
	private void Save()
	{
		if (string.IsNullOrWhiteSpace(Content)) return;

		var newTask = new TodoItem
		{
			Content = Content,
			Priority = Priority,
			IsCompleted = false
		};

		Content = string.Empty;
		Priority = "中";
		_closeAction?.Invoke();
	}

	[RelayCommand]
	private void Cancel()
	{
		_closeAction?.Invoke();
	}
}
