#pragma once

#include "xtr/doc/RSFacade.h"

#include "xtr/dialog/CstDataPage.h"
#include "xtr/dialog/RSModelPage.h"

namespace xtr::dialog {

//! Dialog: Edit constituenta
class EditConstituentaDlg final : public CPropertySheet {
public:
  EntityUID activeUID{};
  doc::RSFacade* editor{ nullptr };

private:
  std::unique_ptr<CstDataPage> m_CstPage{ nullptr };
  std::unique_ptr<RSModelPage> m_ModelPage{ nullptr };
  std::unique_ptr<CMenu> m_Menu{ nullptr };

public:
  ~EditConstituentaDlg() override;
  EditConstituentaDlg(doc::RSFacade& editor, EntityUID activeUID, CWnd* pParentWnd = nullptr);

private:
  BOOL OnInitDialog() override;
  void CreateMenu();
  void FixWindowSize();

public:
  void StepNext();
  void StepPrev();

private:
  BOOL PreTranslateMessage(MSG* pMsg) override;
  [[nodiscard]] static BOOL IsControlAndSPressed(const WPARAM& key) noexcept;
  [[nodiscard]] static BOOL IsControlAndEnterPressed(const WPARAM& key) noexcept;

DECLARE_MESSAGE_MAP()
  afx_msg void OnInitMenuPopup(CMenu* pMenu, uint32_t nIndex, BOOL bSysMenu);
  afx_msg BOOL OnInsertCst(uint32_t command);
  afx_msg BOOL OnCommandRun(uint32_t command);
  afx_msg void OnUpdateCommandUI(CCmdUI* pCmdUI);

private:
  void UpdateMenuState(CMenu& menu);
};

} // namespace xtr::dialog