VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmNewCounter
   Caption         =   "360LM — Add New Counter"
   ClientHeight    =   8640
   ClientLeft      =   108
   ClientTop       =   452
   ClientWidth     =   7200
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "frmNewCounter"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

' ── Controls (created in UserForm_Initialize) ─────────────────────────────────
' lblBrand, cmbBrand, lblCounter, txtCounter
' lblCity,  txtCity,  lblState,   txtState
' Frame1 (items), lblItemsHdr
' For up to 6 items: lblType(i), cmbType(i), txtSize(i), txtQty(i), txtRemP(i), txtRemI(i)
' btnAddItem, btnGenerate, btnCancel

Private ITEM_TYPES As Variant
Private Const MAX_ITEMS As Integer = 6
Private itemCount As Integer
Private itemControls() As Object   ' dynamic array of item row controls

Private Sub UserForm_Initialize()
    ITEM_TYPES = Array( _
        "Glow Sign Board", "Backlit Board", "Flex Banner", _
        "ACP Board", "One Way Vision", "Window Decal", _
        "Floor Graphic", "Translit", "Fabric Board", _
        "Lollypop", "Clip on Board", "Vinyl Print", "Inshop Branding")

    Me.Width  = 500
    Me.Height = 620

    ' ── Header label
    AddLabel Me, "brand", "Brand:", 8, 12, 80, 18
    Set cmbBrand = Me.Controls.Add("Forms.ComboBox.1", "cmbBrand")
    With cmbBrand
        .Left = 92: .Top = 10: .Width = 180: .Height = 18
        Dim brands As Variant
        brands = Array("KFC", "McDonald's", "HP", "Lenovo", "Philips", "Liebherr", "Samsung", "Other")
        Dim b As Variant
        For Each b In brands: .AddItem b: Next b
    End With

    AddLabel Me, "lblCtr", "Counter / Store:", 8, 36, 100, 18
    Set txtCounter = Me.Controls.Add("Forms.TextBox.1", "txtCounter")
    With txtCounter: .Left = 112: .Top = 34: .Width = 350: .Height = 18: End With

    AddLabel Me, "lblCity", "City:", 8, 60, 40, 18
    Set txtCity = Me.Controls.Add("Forms.TextBox.1", "txtCity")
    With txtCity: .Left = 52: .Top = 58: .Width = 140: .Height = 18: End With

    AddLabel Me, "lblState", "State:", 200, 60, 40, 18
    Set txtState = Me.Controls.Add("Forms.TextBox.1", "txtState")
    With txtState: .Left = 244: .Top = 58: .Width = 140: .Height = 18: End With

    ' ── Items section header
    AddLabel Me, "lblItems", "Branding Items:", 8, 90, 120, 14, True

    ' Column headers
    AddLabel Me, "h1", "Item Type",    8,   108, 130, 14
    AddLabel Me, "h2", "Size W×H",   142,   108,  80, 14
    AddLabel Me, "h3", "Qty",         226,   108,  30, 14
    AddLabel Me, "h4", "Remarks Prod",260,   108, 100, 14
    AddLabel Me, "h5", "Rem Install", 364,   108, 100, 14

    itemCount = 0
    ReDim itemControls(MAX_ITEMS - 1, 4)
    Dim i As Integer
    For i = 0 To 2: AddItemRow i: Next i   ' start with 3 rows

    ' ── Buttons
    Dim btnAdd As Object
    Set btnAdd = Me.Controls.Add("Forms.CommandButton.1", "btnAdd")
    With btnAdd
        .Caption = "+ Add Row"
        .Left = 8: .Top = 400: .Width = 80: .Height = 22
    End With

    Dim btnGen As Object
    Set btnGen = Me.Controls.Add("Forms.CommandButton.1", "btnGen")
    With btnGen
        .Caption = "Generate Slide"
        .Left = 300: .Top = 400: .Width = 100: .Height = 22
        .BackColor = RGB(31, 56, 100)
        .ForeColor = RGB(255, 255, 255)
    End With

    Dim btnCancel As Object
    Set btnCancel = Me.Controls.Add("Forms.CommandButton.1", "btnCnl")
    With btnCancel
        .Caption = "Cancel"
        .Left = 406: .Top = 400: .Width = 60: .Height = 22
    End With
End Sub

Private Sub btnAdd_Click()
    If itemCount >= MAX_ITEMS Then
        MsgBox "Maximum " & MAX_ITEMS & " items per counter slide.", vbInformation
        Exit Sub
    End If
    AddItemRow itemCount
End Sub

Private Sub btnGen_Click()
    ' Validate required fields
    If Trim(cmbBrand.Value) = "" Then
        MsgBox "Please select a brand.", vbExclamation: Exit Sub
    End If
    If Trim(txtCounter.Value) = "" Then
        MsgBox "Please enter a counter/store name.", vbExclamation: Exit Sub
    End If

    ' Build slide data structure and call generator
    Dim data As New Collection
    ' Pack into a string we pass to slide builder (simpler than custom type)
    Dim brand As String:   brand   = Trim(cmbBrand.Value)
    Dim cname As String:   cname   = Trim(txtCounter.Value)
    Dim city As String:    city    = Trim(txtCity.Value)
    Dim state As String:   state   = Trim(txtState.Value)

    ' Collect items
    Dim items(MAX_ITEMS - 1, 5) As String  ' type, size, qty, remP, remI
    Dim actualItems As Integer: actualItems = 0
    Dim i As Integer
    For i = 0 To itemCount - 1
        Dim itype As String
        itype = Trim(itemControls(i, 0).Value)
        If itype <> "" Then
            items(actualItems, 0) = itype
            items(actualItems, 1) = Trim(itemControls(i, 1).Value)
            items(actualItems, 2) = Trim(itemControls(i, 2).Value)
            items(actualItems, 3) = Trim(itemControls(i, 3).Value)
            items(actualItems, 4) = Trim(itemControls(i, 4).Value)
            actualItems = actualItems + 1
        End If
    Next i

    If actualItems = 0 Then
        MsgBox "Please add at least one branding item.", vbExclamation
        Exit Sub
    End If

    ' Determine next counter number
    Dim prs As Presentation: Set prs = ActivePresentation
    Dim maxNo As Integer: maxNo = 0
    Dim sl As slide
    For Each sl In prs.Slides
        If Module_Main.IsCounterSlide(sl) Then
            Dim n As Integer
            If IsNumeric(Module_Main.GetCounterNo(sl)) Then
                n = CInt(Module_Main.GetCounterNo(sl))
                If n > maxNo Then maxNo = n
            End If
        End If
    Next sl
    Dim newNo As Integer: newNo = maxNo + 1

    ' Add blank slide and build it
    Module_SlideBuilder.BuildCounterSlide prs, newNo, brand, cname, city, state, items, actualItems

    Unload Me
    MsgBox "Counter #" & newNo & " slide added.", vbInformation, "360LM"
End Sub

Private Sub btnCnl_Click()
    Unload Me
End Sub

Private Sub AddItemRow(i As Integer)
    Dim top As Integer: top = 126 + i * 40

    Dim cmb As Object
    Set cmb = Me.Controls.Add("Forms.ComboBox.1", "cmbType" & i)
    With cmb
        .Left = 8: .Top = top: .Width = 130: .Height = 18
        Dim t As Variant
        For Each t In ITEM_TYPES: .AddItem t: Next t
    End With
    Set itemControls(i, 0) = cmb

    Dim txSz As Object
    Set txSz = Me.Controls.Add("Forms.TextBox.1", "txtSize" & i)
    With txSz: .Left = 142: .Top = top: .Width = 80: .Height = 18: .Text = "": End With
    Set itemControls(i, 1) = txSz

    Dim txQty As Object
    Set txQty = Me.Controls.Add("Forms.TextBox.1", "txtQty" & i)
    With txQty: .Left = 226: .Top = top: .Width = 30: .Height = 18: .Text = "1": End With
    Set itemControls(i, 2) = txQty

    Dim txRP As Object
    Set txRP = Me.Controls.Add("Forms.TextBox.1", "txtRP" & i)
    With txRP: .Left = 260: .Top = top: .Width = 100: .Height = 18: End With
    Set itemControls(i, 3) = txRP

    Dim txRI As Object
    Set txRI = Me.Controls.Add("Forms.TextBox.1", "txtRI" & i)
    With txRI: .Left = 364: .Top = top: .Width = 100: .Height = 18: End With
    Set itemControls(i, 4) = txRI

    itemCount = itemCount + 1
End Sub

Private Sub AddLabel(parent As Object, nm As String, caption As String, _
                     l As Integer, t As Integer, w As Integer, h As Integer, _
                     Optional bold As Boolean = False)
    Dim lbl As Object
    Set lbl = parent.Controls.Add("Forms.Label.1", nm)
    With lbl
        .Caption = caption: .Left = l: .Top = t: .Width = w: .Height = h
        .Font.Bold = bold
    End With
End Sub
