using System.Runtime.InteropServices;

namespace Theriapolis.Game.Platform;

/// <summary>
/// Cross-platform clipboard writer via SDL2, which MonoGame.Framework.DesktopGL
/// already loads. Silently no-ops if the native call fails so debug-only callers
/// never crash the game.
/// </summary>
public static class Clipboard
{
    [DllImport("SDL2", EntryPoint = "SDL_SetClipboardText", CallingConvention = CallingConvention.Cdecl)]
    private static extern int SDL_SetClipboardText([MarshalAs(UnmanagedType.LPUTF8Str)] string text);

    public static bool TrySetText(string text)
    {
        try { return SDL_SetClipboardText(text) == 0; }
        catch { return false; }
    }
}
