#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "ContentPresent.h"
#include "DocsManager.h"
#include "fragmentsorderpresent.h"
#include "manager_docs.h"
#include "messagespresent.h"
#include "presentcontainer.h"
#include "projectpresent.h"
#include "storyboardspresent.h"
#include "storychainspresent.h"
#include "storyconceptspresent.h"
#include "storyunitspresent.h"
#include "tools.h"
#include "welcomepanel.h"
#include <QListView>
#include <QMainWindow>
#include <QSplitter>
#include <QTableView>
#include <QTreeView>
#include <StoryTool.h>
#include <libProjectManager.h>

class MainWindow : public QMainWindow, public Components::PresentHost, public Components::HostListener {
    Q_OBJECT

  public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

  private:
    Core::AppCore *const app_core;

    Tools::StatusSyncCore *const sync_kernel;
    QSplitter *const split_first;
    QSplitter *const split_second;
    QSplitter *const split_third;

    Project::ProjectManager *const project_manager;

    // containers =======================================
    Components::PresentHost *const left_funcs;
    Components::PresentHost *const right_funcs;
    Components::PresentHost *const center_funcs;
    Components::PresentHost *const bottom_funcs;

    // model ============================================
    DataModel::DocumentsManager *const docs_container;
    DataModel::FragmentsOrderviewModel *const fragments_model;
    DataModel::StoryboardsPresentModel *const boards_model;
    DataModel::StorychainsPresentModel *const chains_model;
    DataModel::StoryconceptsPresentModel *const concepts_model;
    DataModel::StoryunitsPresentModel *const units_model;

    // view =============================================
    Components::WelcomePanel *const welcome_list;
    Components::MessagesPresent *const errors_present;
    Components::ProjectPresent *const project_present;
    Components::FragmentsOrderPresent *const fragments_order;
    Components::StoryboardsPresent *const boards_view;
    Components::StorychainsPresent *const chains_view;
    Components::StoryconceptsPresent *const concept_view;
    Components::StoryunitsPresent *const units_view;

    // 内部逻辑 ===========================================
    void initial_menubar(QMenuBar *mbar);
    void initial_commandlist(Schedule::CommandsDispatcher *host);

    void accept_view_transport(const Core::Route &key, Components::GroupType type);

    void refresh_views();

    void build_internal(bool all_from_disk = false);

    void splitter_layout_save(const QList<QString> &path_type, const QList<int> &size);

    // PresentContainer interface
  public:
    virtual QWidget *hostWidget() const override;
    virtual void setVisibleState(bool state) override;
    virtual bool visibleState() const override;

    virtual void append(MakeTools::PresentBase *ins, const Core::Route &unique) override;
    virtual bool active(const Core::Route &unique) override;
    virtual MakeTools::PresentBase *remove(const Core::Route &unique) override;

    virtual bool instContains(MakeTools::PresentBase *ins) const override;

    // HostListener interface
  public:
    virtual void hasBeenAccepted(const Core::Route &key) override;
    virtual void hasBeenRemoved(const Core::Route &key) override;
    virtual void hasBeenClosed(const Core::Route &key) override;

    // QWidget interface
  protected:
    virtual void closeEvent(QCloseEvent *event) override;

    // QObject interface
  public:
    virtual bool eventFilter(QObject *watched, QEvent *event) override;
};
#endif // MAINWINDOW_H
