using System.Diagnostics;
using System.IO;
using System.Reflection;
using ClaudeDo.Data;
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; }

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

    [RelayCommand]
    private void OpenPath(string? path)
    {
        if (string.IsNullOrWhiteSpace(path)) return;
        try
        {
            var target = File.Exists(path) ? path : (Directory.Exists(path) ? path : null);
            if (target is null) return;
            Process.Start(new ProcessStartInfo("explorer.exe", $"\"{target}\"") { UseShellExecute = true });
        }
        catch { /* ignore */ }
    }
}
