#pragma once

#include "xtr/ui/RSTableCtrl.h"
#include "xtr/ui/RSEdit.h"
#include "xtr/doc/RSModelDoc.h"

namespace xtr::view {

//! View: RSModel table
class RSModelView : public CFormView {
  DECLARE_DYNCREATE(RSModelView)

  doc::RSFacade editor{};
  ccl::semantic::RSModel* model{ nullptr };

  CString title{};
  CString alias{};

  ui::RSEdit titleCtrl{};
  ui::RSEdit aliasCtrl{};
  ui::RSEdit searchCtrl{};
  CRichEditCtrl rsformStatusCtrl{};
  CRichEditCtrl rsModelStatusCtrl{};

  CToolTipCtrl tooltips{};
  ui::RSTableCtrl  cstTable{};

private:
  RSModelView();

private:
  void DoDataExchange(CDataExchange* pDX) override;
  void OnInitialUpdate() override;
  void InitControls();
  void InitTooltips();

private:
  BOOL PreTranslateMessage(MSG* pMsg) override;
  BOOL OnCmdMsg(uint32_t nID, int32_t nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) override;
  void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) override;

DECLARE_MESSAGE_MAP()
  afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  afx_msg void OnChange();
  afx_msg void OpenHelp();
  afx_msg BOOL OnCopy(uint32_t msgID);
  afx_msg BOOL OnPaste(uint32_t msgID);
  afx_msg void OnEditComment();
  afx_msg void OnUpdateStatus();
  afx_msg void OnCalculateAll();
  afx_msg BOOL OnOperation(uint32_t command);
  afx_msg BOOL OnInsertCst(uint32_t command);
  afx_msg BOOL OnCommandRun(uint32_t command);
  afx_msg void OnUpdateCommandUI(CCmdUI* pCmdUI);

private:
  const SetOfEntities& Selection() const noexcept;
  BOOL IsCommandActive(uint32_t command) const noexcept;
  BOOL IsContextActive(uint32_t command) const;
  void UpdateStatusBar();
  void OnSearch();

  void InsertNew(ccl::semantic::CstType cstType, int32_t nWhere = -1);
  void InsertFree();
};

} // namespace xtr::view