#if ANDROID
using Android.Content;
using Android.App;
using AndroidX.Core.App;
using AndroidX.Core.Content.PM;
using AndroidX.Core.Graphics.Drawable;

namespace TodoList.Maui.Services.Platforms
{
    /// <summary>
    /// Android 平台全局热键服务实现类
    /// 由于 Android 限制全局热键，使用通知快捷方式作为替代方案
    /// </summary>
    public class MobileGlobalHotKeyService : IGlobalHotKeyService
    {
        private Action? _callback;

        /// <summary>
        /// Android 平台不支持全局热键
        /// </summary>
        public bool IsSupported => false;

        /// <summary>
        /// 注册通知快捷方式作为热键替代方案
        /// </summary>
        public void RegisterHotKey(string modifiers, string key, Action callback)
        {
            _callback = callback;
            RegisterAndroidNotificationShortcut();
        }

        /// <summary>
        /// 注销快捷方式（空实现）
        /// </summary>
        public void UnregisterHotKey()
        {
        }

        /// <summary>
        /// 更新快捷方式配置
        /// </summary>
        public void UpdateHotKey(string modifiers, string key)
        {
            if (_callback != null)
            {
                RegisterHotKey(modifiers, key, _callback);
            }
        }

        /// <summary>
        /// 注册 Android 通知快捷方式
        /// </summary>
        private void RegisterAndroidNotificationShortcut()
        {
            try
            {
                var context = Android.App.Application.Context;
                var shortcutId = "quick_entry_shortcut";

                var intent = new Intent(context, typeof(MainActivity));
                intent.SetAction(Intent.ActionView);
                intent.PutExtra("action", "quick_entry");

                var shortcutInfo = new ShortcutInfoCompat.Builder(context, shortcutId)
                    .SetShortLabel("快速记录")
                    .SetLongLabel("快速记录任务")
                    .SetIntent(intent)
                    .Build();

                ShortcutManagerCompat.PushDynamicShortcut(context, shortcutInfo);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Failed to register Android shortcut: {ex.Message}");
            }
        }
    }
}
#endif

#if IOS
using Foundation;
using UIKit;

namespace TodoList.Maui.Services.Platforms
{
    /// <summary>
    /// iOS 平台全局热键服务实现类
    /// 由于 iOS 限制全局热键，提供空实现
    /// </summary>
    public class MobileGlobalHotKeyService : IGlobalHotKeyService
    {
        private Action? _callback;

        /// <summary>
        /// iOS 平台不支持全局热键
        /// </summary>
        public bool IsSupported => false;

        /// <summary>
        /// 注册热键（空实现）
        /// </summary>
        public void RegisterHotKey(string modifiers, string key, Action callback)
        {
            _callback = callback;
        }

        /// <summary>
        /// 注销热键（空实现）
        /// </summary>
        public void UnregisterHotKey()
        {
        }

        /// <summary>
        /// 更新热键（空实现）
        /// </summary>
        public void UpdateHotKey(string modifiers, string key)
        {
            if (_callback != null)
            {
                RegisterHotKey(modifiers, key, _callback);
            }
        }
    }
}
#endif