#pragma once

#include "xtr/doc/Documents.h"

namespace xtr::view {

//! View: RSForm TermTree
class TermTreeView : public CFormView {
  DECLARE_DYNCREATE(TermTreeView)

  doc::SelectableDoc* document{ nullptr };
  const ccl::semantic::RSCore* core{ nullptr };
  CTreeCtrl  termTreeCtrl{};

private:
  TermTreeView();

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

private:
  void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) override;

DECLARE_MESSAGE_MAP()
  afx_msg void OpenHelp();
  afx_msg void OnDblclkTermTree(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnBuild();

private:
  BOOL BuildTree();
  static HTREEITEM FindItemInTree(const CTreeCtrl* termTree, CString sFindName);
  static int32_t InsertSubTree(CTreeCtrl* termTree, HTREEITEM current, CString sName);
};

} // namespace xtr::view