#pragma once

#include "xtr/ui/BuffRichEdit.h"
#include "xtr/ui/RSEdit.h"
#include "xtr/ui/RSListCtrl.h"
#include "xtr/doc/RSFacade.h"

namespace xtr::dialog {

//! Dialog: Create RSTerms from Typification
class Structure2Terms final : public CDialog {
  struct ArgsHeader;
  struct GlobalsHeader;

public:
  VectorOfEntities addedCst{};

private:
  doc::RSFacade& editor;

  EntityUID activeUID{};
  CString activeName;
  CString inputExpr;
  CString m_Interp;

  ui::RSEdit inputCtrl{};
  ui::BuffRichEdit textCtrl{};
  ui::RSListCtrl globalsCtrl{};
  ui::RSListCtrl argsCtrl{};
  CComboBox nameCtrl{};

public:
  Structure2Terms(doc::RSFacade& editor, EntityUID startID, CWnd* pParent = nullptr);

private:
  void DoDataExchange(CDataExchange* pDX) override;
  BOOL OnInitDialog() override;
  void InitControls();
  void InitHeaders();
  void InitCstNameList();
  void OnOK() override;
  BOOL PreTranslateMessage(MSG* pMsg) override;

DECLARE_MESSAGE_MAP()
  afx_msg void OnSelchangeTermCb();
  afx_msg void OnBnClickedRight();
  afx_msg void OnBnClickedLeft();
  afx_msg void OnBnClickedApply();

  afx_msg void OnDblClickList(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnItemActivateArgList(NMHDR *pNMHDR, LRESULT *pResult);

private:
  void UpdateUI();
  void InputArguments();
  void Clear();
  int AddTerms();
};

//! Dialog: Edit text definition
class GetInterpDialog final : public CDialog {
public:
  CString textDef;

private:
  ui::BuffRichEdit input;

public:
  explicit GetInterpDialog(CString text, CWnd* pParent = nullptr);

private:
  BOOL OnInitDialog() override;
  void DoDataExchange(CDataExchange* pDX) override;
};

} // namespace xtr::dialog