#ifndef SHORTCUTFILTERMODEL_H
/*
 * Copyright (C) 2025, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: youdiansaodongxi <guojiaqi@kylinos.cn>
 *
 */

#define SHORTCUTFILTERMODEL_H

#include <QSortFilterProxyModel>
#include <QQuickItem>

#include "plugin-common-data.h"

namespace UkuiShortcut {

class EditShortcutModel;

class ShortcutFilterModel : public QSortFilterProxyModel
{
    Q_OBJECT
public:
    explicit ShortcutFilterModel(EditShortcutModel* sourceModel, PluginMetaType::AddState addState, QObject *parent = nullptr);

    QVariant data(const QModelIndex &index, int role) const override;

    Q_INVOKABLE void active(int i, PluginMetaType::Action action);
    Q_INVOKABLE void setValue(int i, int value);
    Q_INVOKABLE void disableValueUpdate(bool disable);

    Q_INVOKABLE void moveItem(int sourceIndex, int targetIndex);
    Q_INVOKABLE void setOrder(QString fromId, int toIndex);
    Q_INVOKABLE void changeState(QString idFrom, PluginMetaType::AddState stateFrom, bool atEnd = true);

    Q_INVOKABLE void updateItemRect(QQuickItem* flowItem);
    Q_INVOKABLE void findTargetItem(qreal x, qreal y, QObject* resultObj);

protected:
    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
    bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;

private Q_SLOTS:
    void onSourceModelDataChanged(const QModelIndex &topLeft,
                                  const QModelIndex &bottomRight,
                                  const QVector<int> &roles = QVector<int>());

private:
    int m_itemWidth = 80;
    int m_itemHeight = 72;
    int m_columns = 4;
    int m_rowSpacing = 12;
    int m_columnSpacing = 12;

    QList<QQuickItem *> m_items;

    EditShortcutModel* m_sourceModel = nullptr;
    PluginMetaType::AddState m_addState = PluginMetaType::Add;
};
}
#endif // SHORTCUTFILTERMODEL_H
