// Copyright (C) 2025-2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include <QObject>
#include <QTimer>
#include <qcoreevent.h>
#include "shortcutmanager.h"

class ShortcutRunner : public QObject
{
    Q_OBJECT
public:
    explicit ShortcutRunner(QObject *parent = nullptr);

public Q_SLOTS:
    void onActionTrigger(ShortcutAction action, const QString &name, bool isGesture, ShortcutController::KeyFlags keyFlags = {});
    void onActionProgress(ShortcutAction action, qreal progress, const QString &name);
    void onActionFinish(ShortcutAction action, const QString &name, bool isTriggered);

private Q_SLOTS:
    void onModifierReleased(QKeyEvent *event);
    void onQuickSwitchTimeout();

private:
    void updateWorkspaceSwipe(qreal cb);
    void finishWorkspaceSwipe();
    void taskswitchAction(bool isRepeat, bool isSameApp, bool isPrev);

    // dynamic bounce check: true when cb pushes beyond workspace boundary
    inline bool isWorkspaceBounce(qreal cb, int currentIndex, int wsCount) const
    {
        return (cb > 0 && currentIndex >= wsCount - 1) || (cb < 0 && currentIndex <= 0);
    }

    qreal m_desktopOffset = 0;
    int m_fromId = 0;
    int m_toId = 0;
    bool m_slideEnable = false;

    QTimer *m_quickSwitchTimer = nullptr;
    ShortcutAction m_currentAction;
    bool m_quickSwitchPending = false;
    quint32 m_taskAltCount = 0;
};
