using System.IO;
using System.Reflection;
using ClaudeDo.Data;
using ClaudeDo.Ui.Localization;
using ClaudeDo.Ui.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace ClaudeDo.Ui.ViewModels.Modals;

public sealed partial class AboutModalViewModel : ViewModelBase
{
    public string AppVersion { get; } =
        Assembly.GetExecutingAssembly().GetName().Version?.ToString(3) ?? "0.0.0";
    public string DataFolderPath { get; } = Paths.AppDataRoot();
    public string LogsFolderPath { get; } = Path.Combine(Paths.AppDataRoot(), "logs");
    public string WorkerConfigPath { get; } = Path.Combine(Paths.AppDataRoot(), "worker.config.json");

    public Action? CloseAction { get; set; }

    // Mirrors UsageMonitorModalViewModel.ErrorReported — this modal's own window sits in front
    // of the footer strip, so the caller wires this into FlashFooterError.
    public event Action<string>? ErrorReported;

    [RelayCommand] private void Close() => CloseAction?.Invoke();

    [RelayCommand]
    private void OpenPath(string? path)
    {
        var (ok, error) = ShellOpen.Path(path);
        if (!ok && error is not null)
            ErrorReported?.Invoke(Loc.T("vm.about.openPathFailed", error));
    }
}
