/*
 * Copyright (C) 2020, 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/>.
 */
#ifndef COMMANDPAGE_H
#define COMMANDPAGE_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QQuickWidget>
#include <QQmlContext>
#include <QSettings>
#include <QQuickItem>
#include <QScrollArea>
#include <QScrollBar>
#include <kborderlessbutton.h>

#include "libukcc/widgets/SettingWidget/settinggroup.h"
#include "commandconfigdialog.h"
#include "global/kaglobal.h"
#include "commandtemplatelist.h"
#include "lightlabel.h"
#include "titlelabel.h"

using namespace std;

class CommandPage : public QWidget
{

    Q_OBJECT

public:
    explicit CommandPage(QWidget *parent = nullptr);
    void initCommandPageWidget();
    // 获取当前是否在编辑状态
    bool isInEditingState() const;

    ~CommandPage();

signals:
    void editModeChanged(bool editing);
    void sigDeleteActiveCommand(int actorId, QString name);


public slots:
    // 添加自定义提示词弹窗
    void onAddBtnClicked();
    // 二次编辑和查看弹窗
    void onCommandClicked(int type, int actorId, QString name, QString content);
    // 创建提示词
    void onCreateCommand(QString name, QString content);
    // 编辑提示词
    void onEditCommand(int actorId, QString name, QString content);
    // 删除确认弹窗
    void showConfirmMessage(int actorId, QString name);
    // 更新QML内容区高度
    void onContentHeightChanged(int height);

private:
    void initLayout();
    void initConnection();
    // 报错弹窗
    void showErrorMessage(const QString &message, QWidget *parent);

private:
    QLabel *m_titleLabel = nullptr;
    LightLabel *m_tipLabel = nullptr;
    kdk::KBorderlessButton *m_addButton = nullptr;

    QWidget *m_titleWidget = nullptr;
    QWidget *m_tipWidget = nullptr;
    QQuickWidget *m_commandWidget = nullptr;

    QWidget *m_scrollWidget = nullptr;
    QScrollArea *m_scrollArea = nullptr;

};

#endif // COMMANDPAGE_H
