Imports System.Drawing

Public Class usrCntlMessenger_ChatEmoji
    Property BG_COLOR As Color = Color.FromArgb(192, 255, 192) ' Color.Azure
    Property CHAT_MSG As VERAG_PROG_ALLGEMEIN.cMessenger.cMessenger_ChatMessages
    Dim frmM As frmMessenger
    'Public FI As String = ""
    Dim ttp As New System.Windows.Forms.ToolTip

    Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub

    Sub New(frmM As frmMessenger, CHAT_MSG As VERAG_PROG_ALLGEMEIN.cMessenger.cMessenger_ChatMessages)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.CHAT_MSG = CHAT_MSG
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Me.frmM = frmM
    End Sub
    Sub setBgCOLOR(BG_COLOR)
        ' Me.BG_COLOR = BG_COLOR
        ' txtChatmessage.BackColor = BG_COLOR
        Panel1.BackColor = BG_COLOR
    End Sub

    Private Sub usrCntlMessenger_ChatAnhang_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ttp.SetToolTip(lblDel, "Element innerhalb 60 Sek. löschen")
        init()
    End Sub

    Sub init()
        If CHAT_MSG IsNot Nothing Then
            If CHAT_MSG.chatMg_type.Contains("DEL_") Then
                pic.Visible = False
            Else
                ' txtChatmessage.Text = CHAT_MSG.chatMg_text

                Dim imgPath = CHAT_MSG.chatMg_text
                Try
                    'Dim frmM As frmMessenger = DirectCast(Me.Parent, frmMessenger)
                    If frmM.EMOJI_PATH <> frmM.EMOJI_PATH_MAIN Then
                        If IO.File.Exists(imgPath.Replace(frmM.EMOJI_PATH_MAIN, frmM.EMOJI_PATH)) Then
                            imgPath = imgPath.Replace(frmM.EMOJI_PATH_MAIN, frmM.EMOJI_PATH)
                        End If
                    End If
                Catch ex As Exception
                    MsgBox(ex.Message & ex.StackTrace)
                End Try

                Try
                    pic.BackgroundImage = Image.FromFile(imgPath)
                    pic.BackgroundImageLayout = Windows.Forms.ImageLayout.Zoom
                Catch ex As Exception
                    '  MsgBox(ex.Message & ex.StackTrace)
                End Try
                lblDateTime.Text = CHAT_MSG.chatMg_datetime.ToString("dd.MM.yyyy HH:mm:ss")
                lblName.Text = CHAT_MSG.chatMg_maName & " (" & CHAT_MSG.chatMg_maFirma & ")"

                Dim cnt = 0

                setRead()


                If CHAT_MSG.chatMg_maId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                    If CHAT_MSG.chatMg_datetime > Now.AddSeconds(-60) Then
                        lblDel.Visible = True
                        Timer1.Enabled = True
                    End If
                End If

            End If
        End If
    End Sub

    Sub setRead()
        For Each ST In CHAT_MSG.CHAT_MESSAGES_STATUS_LIST
            If ST.chatMgSt_MaId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                lblNewMsg.Visible = Not ST.chatMgSt_gelesen
            End If
        Next
    End Sub

    Private Sub pic_Click(sender As Object, e As EventArgs) Handles pic.Click
        If CHAT_MSG IsNot Nothing Then
            Dim PATH = cDATENSERVER.GET_PDFPath_BY_DocID(CHAT_MSG.chatMg_anhang_docId, True)
            'Process.Start(PATH)
        End If
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If CHAT_MSG IsNot Nothing Then
            If CHAT_MSG.chatMg_maId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                If CHAT_MSG.chatMg_datetime > Now.AddSeconds(-60) Then
                    lblDel.Visible = True
                Else
                    lblDel.Visible = False
                    Timer1.Enabled = False
                End If
            End If
        End If
    End Sub

    Private Sub lblDel_Click(sender As Object, e As EventArgs) Handles lblDel.Click
        CHAT_MSG.DELETE_MESSAGE()
        usrCntlMessenger_ChatAnhang_Load(Me, New EventArgs)
        lblDel.Visible = False
    End Sub
End Class
