' Copyright (C) 2025  P4pillon.org
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as
' published by the Free Software Foundation, either version 3 of the
' License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program.  If not, see <https://www.gnu.org/licenses/>.
Public Class USERS_Select

    Private Sub USERS_Select_Load(sender As Object, e As EventArgs) Handles Me.Load
        If current_User.ID <> "" And current_User.Locked = True Then
            password_validated = True
            Me.Close()
        End If
        If COMPTOIR_MAIN.Visible = True And COMPTOIR_MAIN.WindowState = FormWindowState.Minimized Then
            If Not current_User.image Is Nothing Then
                Dim btn As New Button
                btn.Height = 100
                btn.Width = 200
                btn.FlatStyle = FlatStyle.Flat
                btn.FlatAppearance.BorderSize = 0
                btn.BackgroundImage = current_User.image
                btn.BackgroundImageLayout = ImageLayout.Stretch
                btn.Tag = COMPTOIR_MAIN.user_Button.Text
                btn.Text = COMPTOIR_MAIN.user_Button.Text
                btn.Font = New Font("Century Gothic", 10)
                btn.ForeColor = Color.Black
                btn.TextAlign = ContentAlignment.BottomRight
                AddHandler btn.Click, AddressOf Me.Click_event
                FlowLayoutPanel1.Controls.Add(btn)
            Else
                Dim link As New LinkLabel
                link.Text = COMPTOIR_MAIN.user_Button.Text
                link.Tag = COMPTOIR_MAIN.user_Button.Text
                link.Font = New Font("Century Gothic", 20)
                link.LinkColor = Color.Black
                link.BackColor = Color.FromArgb(224, 224, 224)
                link.Height = 50
                link.Width = 200
                link.ActiveLinkColor = Color.Green
                AddHandler link.Click, AddressOf Me.Click_event
                FlowLayoutPanel1.Controls.Add(link)
            End If
        Else




            Dim users = Me.UsersTableAdapter.GetData
            For i = 0 To users.Rows.Count - 1
                If Not users(i).picture = "" Then
                    Dim btn As New Button
                    btn.Height = 100
                    btn.Width = 200
                    btn.FlatStyle = FlatStyle.Flat
                    btn.FlatAppearance.BorderSize = 0
                    Try
                        btn.BackgroundImage = Image.FromFile(Config.LocalNetwork_ServerName & "\images\users\" & users(i).picture)
                    Catch ex As Exception

                    End Try

                    btn.BackgroundImageLayout = ImageLayout.Stretch
                    btn.Tag = users(i).login
                    btn.Text = users(i).login
                    btn.Font = New Font("Century Gothic", 10)
                    btn.ForeColor = Color.Black
                    btn.TextAlign = ContentAlignment.BottomRight
                    AddHandler btn.Click, AddressOf Me.Click_event
                    FlowLayoutPanel1.Controls.Add(btn)
                Else
                    Dim link As New LinkLabel
                    link.Text = users(i).login
                    link.Tag = users(i).login
                    link.Font = New Font("Century Gothic", 20)
                    link.LinkColor = Color.Black
                    link.BackColor = Color.FromArgb(224, 224, 224)
                    link.Height = 50
                    link.Width = 200
                    link.ActiveLinkColor = Color.Green
                    AddHandler link.Click, AddressOf Me.Click_event
                    FlowLayoutPanel1.Controls.Add(link)
                End If
            Next
        End If
    End Sub
    Private Sub Click_event(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.TopMost = False
        Password.user_TextBox.Text = sender.tag
        Password.ShowDialog()
        Me.Dispose()
    End Sub
End Class