using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using YKanBan.Models;
namespace YKanBan.ViewModels.Board;
///
/// One board column: a header with its title, card count and actions, plus the
/// vertically stacked cards.
///
public sealed partial class ColumnViewModel : ViewModelBase
{
private readonly BoardViewModel _board;
///
/// Initializes the column view from its model and cards.
///
/// The owning board view model.
/// The column model.
/// The already sorted cards belonging to this column.
public ColumnViewModel(BoardViewModel board, ColumnModel column, IEnumerable cards)
{
_board = board;
Model = column;
Cards = new ObservableCollection(cards);
width = board.ColumnWidth;
}
///
/// Gets the underlying column model.
///
public ColumnModel Model { get; }
///
/// Gets the column id.
///
public long Id => Model.Id;
///
/// Gets the column title.
///
public string Title => Model.Title;
///
/// Gets the column description.
///
public string Description => Model.Description;
///
/// Gets the cards in this column, already in display order.
///
public ObservableCollection Cards { get; }
///
/// Gets the number of cards in this column.
///
public int CardCount => Cards.Count;
///
/// Gets the tooltip text: the column description when present, otherwise
/// so no tooltip is shown.
///
public string? ToolTipText => Model.Description.Length > 0 ? Model.Description : null;
///
/// Gets or sets the rendered column width in pixels, applied globally.
///
[ObservableProperty]
private double width;
///
/// Opens the editor for a new card in this column.
///
[RelayCommand]
private void AddCard() => _ = _board.RequestAddCardAsync(this);
///
/// Opens the editor for this column.
///
[RelayCommand]
private void Edit() => _ = _board.RequestEditColumnAsync(this);
///
/// Asks the board to delete this column.
///
[RelayCommand]
private void Delete() => _ = _board.RequestDeleteColumnAsync(this);
}