#pragma once

#include "xtr/doc/RSFacade.h"

namespace xtr::dialog {

//! Choose term data parameters
class TerminRefDlg final : public CDialog {
  CListBox singForms{};
  CListBox plurForms{};
  CListBox captionList{};

  enum ACStatus : int32_t {
    ACS_TERMS,
    ACS_WORDFORMS,
  };
  ACStatus state{ ACS_TERMS };

  CPoint position;
  CString initialText;
  doc::RSFacade& editor;

  std::vector<std::string> entities{};

  std::string cstName{};
  ccl::lang::Morphology termForm{};

public:
  TerminRefDlg(doc::RSFacade& editor, CPoint position, CString selection, CWnd* pParent = nullptr);

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

public:
  [[nodiscard]] ccl::lang::Reference CreateRef() const;

private:
  BOOL PreTranslateMessage(MSG* pMsg) override;

private:
  void SetPositionAndSize(BOOL fitBoth = FALSE);

  void SelectTermRef();
  void SelectTermForm(int32_t selection, ccl::lang::Grammem plurality);
  void ChangeTermForm(CListBox* selectedCListBox, ccl::lang::Grammem plurality);
  void UpdateContextNameList();
};

//! Edit form of a term
class TermFormDlg final : public CDialog {
public:
  TermFormDlg(CString initText, RECT position, CWnd* pParent = nullptr);

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

public:
  CString termFormText;

private:
  CEdit textControl;
  RECT position;

private:
  BOOL PreTranslateMessage(MSG* pMsg) override;

private:
  void SetPositionAndSize();
};

} // namespace xtr::dialog