#pragma once

#include "xtr/ui/RSEdit.h"
#include "xtr/ui/DataGridCtrl.h"

namespace xtr::dialog {

class EditConstituentaDlg;

//! Dialog: Edit RSModel data
class RSModelPage : public CPropertyPage {
  EditConstituentaDlg& parent;

  CString typification;
  CString textDef;
  BOOL isModified{ FALSE };
  BOOL canceled{ FALSE };

  CComboBox nameCtrl;
  ui::RSEdit exprCtrl;
  ui::RSEdit textCtr;
  CComboBox  dataEditCtrl;
  CButton textBtn;
  ui::DataGridCtrl dataCtrl;

public:
  explicit RSModelPage(EditConstituentaDlg& parent);

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

  BOOL OnApply() override;
  void OnCancel() override;
  void OnOK() override;
  BOOL PreTranslateMessage(MSG* pMsg) override;

DECLARE_MESSAGE_MAP()
  afx_msg void OnConfirm();
  afx_msg void OnSelchangeName();
  afx_msg void OnCbnKillfocusEditData();
  afx_msg void OnBnClickedFillInterp();
  afx_msg void OnEraseData();
  afx_msg void OnExportData();
  afx_msg void OnImportData();
  afx_msg void OnDataChange(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnPrev();
  afx_msg void OnNext();

private:
  void SetModified(BOOL bChanged = TRUE);
  BOOL IsModified() const noexcept;

  void UpdateFormat();
  void UpdateCellText();

  void CancelEdit();
};

} // namespace xtr::dialog