
Public Class Individual

    Sub Load_GUI()
        ' Initialize GUI
        Init_Form()

        Draw_Grating.Update_GratingPoints()
    End Sub

    ' --- Initialize GUI (form) size and position ---
    Private Sub Init_Form()
        Me.Width = AppForm.Width
        Me.Height = AppForm.Height

        If AppForm.fillMode = True Then
            Init_Multiple()
        Else
            Init_Individual()
        End If

        Me.ComboBox_Material.Enabled = False
        Me.ComboBox_Mesh.Enabled = False
        Me.ComboBox_Height.Enabled = False
        Me.ComboBox_Thickness.Enabled = False
        Me.ComboBox_Width.Enabled = False
        Me.TextBox_Width.Enabled = False
        Me.TextBox_Length.Enabled = False
        Me.Button_Export_GUI.Enabled = False
        Me.Button_Export_SW.Enabled = False

        Me.Button_Angle_Corner.Enabled = False
        Me.Button_Angle_Side.Enabled = False
        Me.Button_Square_Corner.Enabled = False
        Me.Button_Square_Side.Enabled = False
        Me.Button_Square_Middle.Enabled = False
    End Sub

    Private Sub Init_Individual()
        Me.Panel_Data.BackColor = Color.AliceBlue
        Me.Panel_Recesses.BackColor = Color.LightGray

        Dim CheckTemp As New CheckBox With {
           .Name = "CheckBox_Whole_Mesh",
           .Text = "Whole Mesh Widths",
           .Left = 110,
           .Top = 443,
           .Font = New Font("Microsoft Sans Serif", 7.8),
           .Checked = True,
           .Enabled = False,
           .AutoSize = True,
           .BackColor = Color.Transparent
        }
        AddHandler CheckTemp.CheckedChanged, AddressOf CheckBox_Whole_Mesh_CheckedChanged
        Me.Panel_Data.Controls.Add(CheckTemp)

        Me.ComboBox_Width.Visible = True
        Me.TextBox_Width.Visible = False
    End Sub

    Private Sub Init_Multiple()
        Me.Panel_Data.BackColor = Color.Salmon
        Me.Panel_Recesses.BackColor = Color.LightPink

        Dim LabelTemp As New Label With {
            .Name = "Label_Max_Load",
            .Text = "Max Load",
            .Left = 35,
            .Top = 525,
            .AutoSize = True,
            .Font = New Font("Microsoft Sans Serif", 10)
        }
        Me.Panel_Data.Controls.Add(LabelTemp)

        Dim textBoxTemp As New TextBox With {
            .Name = "TextBox_Max_Load",
            .Text = "5",
            .Left = 110,
            .Top = 525,
            .Width = 155,
            .Font = New Font("Microsoft Sans Serif", 8),
            .Enabled = False
            }
        AddHandler textBoxTemp.KeyPress, AddressOf TextBox_Max_Load_KeyPress
        Me.Panel_Data.Controls.Add(textBoxTemp)

        Dim LabelTemp2 As New Label With {
            .Name = "Label_Max_Load_Unit",
            .Text = "kN/m²",
            .Left = 269,
            .Top = 529,
            .Font = New Font("Microsoft Sans Serif", 8)
        }
        Me.Panel_Data.Controls.Add(LabelTemp2)

        Dim calculateButton As New Button With {
            .Name = "Button_Calculate",
            .Text = "Calculate",
            .Left = 100,
            .Top = 600,
            .Width = 100,
            .Height = 40,
            .BackColor = Color.Transparent,
            .UseVisualStyleBackColor = False,
            .Enabled = False
        }
        AddHandler calculateButton.Click, AddressOf Button_Calculate_Click
        Me.Panel_Data.Controls.Add(calculateButton)

        Me.ComboBox_Width.Visible = False
        Me.TextBox_Width.Visible = True
    End Sub

    ' ---------------------------------- Individual Templates ----------------------------------
    ' --- TextBox Template ---
    Public Sub Create_TextBox_Recesses(TextBoxName As String, TextBoxText As String, TextBoxLeft As Integer, TextBoxTop As Integer,
                              TextBoxWidth As Integer)
        Dim textBoxTemp As New TextBox With {
            .Name = TextBoxName,
            .Text = TextBoxText,
            .Left = TextBoxLeft,
            .Top = TextBoxTop,
            .Width = TextBoxWidth,
            .Font = New Font("Microsoft Sans Serif", 10)
        }
        Me.Panel_Recesses.Controls.Add(textBoxTemp)
    End Sub

    ' --- Label Template for Individual ---
    Public Sub Create_Label_Recesses(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
        Dim LabelTemp As New Label With {
            .Name = LabelName,
            .Text = LabelText,
            .Left = LabelLeft,
            .Top = LabelTop,
            .Font = New Font("Microsoft Sans Serif", 10)
        }
        Me.Panel_Recesses.Controls.Add(LabelTemp)
    End Sub


    ' ---------------------------------- Gratings Data ----------------------------------
    ' --- When user changes grating type ---
    Private Sub ComboBox_Type_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Type.TextChanged
        User_Input.TypeChanged(sender, e)
    End Sub


    ' --- When user changes grating material ---
    Private Sub ComboBox_Material_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Material.TextChanged
        User_Input.MaterialChanged(sender, e)
    End Sub

    ' --- When user changes mesh size ---
    Private Sub ComboBox_Mesh_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Mesh.TextChanged
        User_Input.MeshChanged(sender, e)
    End Sub

    ' --- When user changes grating height ---
    Private Sub ComboBox_Height_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Height.TextChanged
        User_Input.HeightChanged(sender, e)
    End Sub

    ' --- When user changes grating thickness ---
    Private Sub ComboBox_Thickness_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Thickness.TextChanged
        User_Input.ThicknessChanged(sender, e)
    End Sub

    ' --- When user checkes/uncheckes whole meshes ---
    Private Sub CheckBox_Whole_Mesh_CheckedChanged(sender As Object, e As EventArgs)
        User_Input.WholeMeshWidthsChanged(sender, e)
    End Sub

    ' --- Grating width changed ---
    Private Sub ComboBox_Width_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Width.TextChanged
        User_Input.WidthChanged(sender, e)
    End Sub

    ' --- Check if width is a number ---
    Private Sub ComboBox_Width_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ComboBox_Width.KeyPress
        User_Input.Check_IfNumber(e)
    End Sub

    ' --- Grating width changed ---
    Private Sub TextBox_Width_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Width.TextChanged
        User_Input.WidthChanged(sender, e)
    End Sub

    ' --- Check if width is a number ---
    Private Sub TextBox_Width_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox_Width.KeyPress
        User_Input.Check_IfNumber(e)
    End Sub

    ' --- Grating length changed ---
    Private Sub LengthBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox_Length.TextChanged
        User_Input.LengthChanged(sender, e)
    End Sub

    ' --- Check if length is a number ---
    Private Sub ComboBox_Length_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox_Length.KeyPress
        User_Input.Check_IfNumber(e)
    End Sub

    ' --- Check if max laod is a number ---
    Public Sub TextBox_Max_Load_KeyPress(sender As Object, e As KeyPressEventArgs)
        User_Input.Check_IfNumber(e)
    End Sub

    ' ---------------------------------- Functions ----------------------------------
    ' --- When angle button is pressed ---
    Private Sub Button_Angle_Corner_Click(sender As Object, e As EventArgs) Handles Button_Angle_Corner.Click
        Corner_Angle.AngleButton(sender, e)
    End Sub

    ' --- When angle side button is pressed ---
    Private Sub Button_Angle_Side_Click(sender As Object, e As EventArgs) Handles Button_Angle_Side.Click

    End Sub

    ' --- When square corner button is pressed ---
    Private Sub Button_Square_Corner_Click(sender As Object, e As EventArgs) Handles Button_Square_Corner.Click
        Corner_Rectangle.SquareButtton(sender, e)
    End Sub

    ' --- When square side button is pressed ---
    Private Sub Button_Square_Side_Click(sender As Object, e As EventArgs) Handles Button_Square_Side.Click
        Side_Rectangle.SquareSideButtton(sender, e)
    End Sub

    ' --- When middle square button is pressed ---
    Private Sub Button_Square_Middle_Click(sender As Object, e As EventArgs) Handles Button_Square_Middle.Click
        Middle_Rectangle.SquareMiddleButtton(sender, e)
    End Sub

    ' ---------------------------------- Calculate ----------------------------------
    ' --- When calculate button is pressed ---
    Public Sub Button_Calculate_Click(sender As Object, e As EventArgs)
        Grating_Fill.Calculate_Grid()
    End Sub

    ' ---------------------------------- Export to SW ----------------------------------
    ' --- When export to SW button is pressed ---
    Private Sub Button_Export_SW_Click(sender As Object, e As EventArgs) Handles Button_Export_SW.Click
        If AppForm.fillMode Then
            Grating_Fill.Calculate_Grid()

            Multiple_Drawing.Create_Models_For_Drawing()        ' Ska flyttas till sist i if satsen

            Multiple_3D.BuildGrid()
        Else
            Individual_3D.BuildGrating()
            Individual_Drawing.Create_Model_For_Drawing()
        End If
    End Sub

    ' ---------------------------------- Export GUI ----------------------------------
    ' --- When export GUI button is pressed ---
    Private Sub Button_Export_GUI_Click(sender As Object, e As EventArgs) Handles Button_Export_GUI.Click
        GUI_Export.Generate_Quote()
    End Sub

    ' ---------------------------------- Back to main menu ----------------------------------
    ' --- When export back button is pressed ---
    Private Sub Button_Back_Click(sender As Object, e As EventArgs) Handles Button_Back.Click
        AppForm.Panel_Start.Controls.Clear()
        Main_Menu.TopLevel = False
        AppForm.Panel_Start.Controls.Add(Main_Menu)
        Main_Menu.Show()
    End Sub
End Class