#include "stdafx.h"

#include "xtr/ui/HelpHandler.h"

#include "resource.h"

namespace xtr::ui {

HelpHandler::HelpHandler() {
  helpBase[HelpID::viewRSForm] = LR"(::/html/050702.htm)";
  helpBase[HelpID::viewRSModel] = LR"(::/html/050902.htm)";
  helpBase[HelpID::viewRSOSS] = LR"(::/html/050802.htm)";

  helpBase[HelpID::editCst] = LR"(::/html/050703.htm)";
  helpBase[HelpID::synthes] = LR"(::/html/050704.htm)";
  helpBase[HelpID::generateCst] = LR"(::/html/050705.htm)";
  helpBase[HelpID::exportRSForm] = LR"(::/html/050710.htm)";
  helpBase[HelpID::options] = LR"(::/html/051000.htm)";
  helpBase[HelpID::operations] = LR"(::/html/050804.htm)";
  helpBase[HelpID::editData] = LR"(::/html/050903.htm)";

  helpBase[HelpID::rslanguage] = LR"(::/html/050711.htm)";
}

void HelpHandler::RunHelp(const HelpID targetPage) {
  CString moduleFolder;
  ::GetModuleFileNameW(::AfxGetApp()->m_hInstance, moduleFolder.GetBuffer(_MAX_PATH + 1), _MAX_PATH + 1);
  moduleFolder.ReleaseBuffer();
  moduleFolder = moduleFolder.Mid(0, moduleFolder.ReverseFind('\\') + 1);

  ::HtmlHelpW(nullptr, moduleFolder + mfc::LoadSID(IXTRS_FILE_HELP) + HID2CStr(targetPage), HH_DISPLAY_TOPIC, 0);
}

HelpHandler& HelpHandler::Instance() {
  static HelpHandler instance{};
  return instance;
}

CString HelpHandler::HID2CStr(const HelpID pageID) {
  return Instance().helpBase[pageID];
}

} // namespace xtr::ui