Attribute VB_Name = "z_UIMessages_sample"
' Модуль вывода сообщений и взаимодействия с пользователем
Option Private Module
Option Explicit

'# Коды сообщений
Public Enum MsgCode
  MSG_OK = 0
  
  'EM_DOC_NOT_ADDED
  
  'IM_SCAN_MODE
  
  'QM_ADD_TITLELINK
End Enum

Private g_UI As API_UserInteraction

Public Function UserInteraction() As API_UserInteraction
  If g_UI Is Nothing Then _
    Set g_UI = New API_UserInteraction
  Set UserInteraction = g_UI
End Function

Public Function SetUserInteraction(newUI As API_UserInteraction)
  Set g_UI = newUI
End Function

Public Function ProcessErrorMessages(expectedErrors As Scripting.Dictionary)
  If Err.Number = 0 Then _
    Exit Function
    
  ' Call Unload(CSE_ProgressBar)
  If Not expectedErrors.Exists(Err.Number) Then _
    Call Err.Raise(Err.Number)
  
  Select Case Err.Number
'    Case EM_LINK_NO_FILE: Call UserInteraction.ShowMessage(Err.Number, Err.Source)
  End Select
End Function

Public Function UIShowMessage(theCode As MsgCode, ParamArray params() As Variant)
  Dim unwrapped As Variant: unwrapped = params
  unwrapped = FixForwardedParams(unwrapped)
  
  Select Case theCode
 ' Case EM_DOC_NOT_ADDED
  '  Call MsgBox("Документ не добавлен в Реестр", vbExclamation)

'  Case IM_SCAN_MODE
 '   Call MsgBox("Документ находится в режиме справочника, ссылки не размечаются", vbInformation)
  
  Case Else
    Call MsgBox("Неверный код сообщения", vbCritical)
  End Select
End Function

Public Function UIAskQuestion(theCode As MsgCode, ParamArray params() As Variant) As Boolean
  Dim unwrapped As Variant: unwrapped = params
  unwrapped = FixForwardedParams(unwrapped)
  
  Dim answer As Long: answer = vbNo
  Select Case theCode
 ' Case QM_ADD_TITLELINK
 '   answer = MsgBox("Внимание! В первый абзац будет добавлена соответствующая ссылка. Продолжить?", vbYesNo + vbQuestion)
    
  Case Else
    Call MsgBox("Неверный код сообщения", vbCritical)
  End Select
  UIAskQuestion = answer = vbYes
End Function
