' Product catalog — parallel arrays for name, category, price, rating, stock
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i  AS LONG
    LOCAL numProds  AS LONG
    DIM prodSKU(20) AS LONG
    DIM prodName(20) AS STRING
    DIM prodCat(20) AS LONG
    DIM prodPrice(20) AS DOUBLE
    DIM prodRating(20) AS LONG
    DIM prodStock(20) AS LONG
    LOCAL s AS STRING
    LOCAL catName AS STRING
    LOCAL searchMin  AS DOUBLE
    LOCAL searchMax  AS DOUBLE
    LOCAL searchCat AS LONG
    LOCAL foundCount AS LONG
    LOCAL searchCharIdx AS LONG

    PRINT "=== Product Catalog ==="
    PRINT

    numProds = 8
    prodSKU(0) = 201
    prodName(0) = "Ergonomic Keyboard          "
    prodCat(0) = 1
    prodPrice(0) = 89.99
    prodRating(0) = 4
    prodStock(0) = 45

    prodSKU(1) = 202
    prodName(1) = "Wireless Mouse              "
    prodCat(1) = 1
    prodPrice(1) = 34.50
    prodRating(1) = 3
    prodStock(1) = 120

    prodSKU(2) = 203
    prodName(2) = "USB-C Hub 7-in-1            "
    prodCat(2) = 1
    prodPrice(2) = 49.99
    prodRating(2) = 5
    prodStock(2) = 30

    prodSKU(3) = 301
    prodName(3) = "Office Chair Premium        "
    prodCat(3) = 2
    prodPrice(3) = 399.00
    prodRating(3) = 4
    prodStock(3) = 10

    prodSKU(4) = 302
    prodName(4) = "Standing Desk Adjustable    "
    prodCat(4) = 2
    prodPrice(4) = 599.00
    prodRating(4) = 5
    prodStock(4) = 5

    prodSKU(5) = 401
    prodName(5) = "Noise Canceling Headphones  "
    prodCat(5) = 3
    prodPrice(5) = 249.99
    prodRating(5) = 4
    prodStock(5) = 25

    prodSKU(6) = 402
    prodName(6) = "Webcam 4K Ultra HD          "
    prodCat(6) = 3
    prodPrice(6) = 129.99
    prodRating(6) = 3
    prodStock(6) = 18

    prodSKU(7) = 501
    prodName(7) = "Mechanical Switch Sampler   "
    prodCat(7) = 1
    prodPrice(7) = 19.99
    prodRating(7) = 2
    prodStock(7) = 200

    PRINT "--- All Products ---"
    FOR i = 0 TO numProds - 1
        s = TRIM$(prodName(i))
        PRINT "SKU" & STR$(prodSKU(i)) & ": " & s & " $" & FORMAT$(prodPrice(i))
    NEXT i
    PRINT

    PRINT "--- Search by Name (contains 'Mouse') ---"
    FOR i = 0 TO numProds - 1
        s = TRIM$(prodName(i))
        searchCharIdx = INSTR(1, s, "Mouse")
        IF searchCharIdx > 0 THEN
            PRINT "  Found: " & TRIM$(s) & " (SKU" & STR$(prodSKU(i)) & ")"
        END IF
    NEXT i
    PRINT

    PRINT "--- Search by Category (Electronics = cat 1) ---"
    searchCat = 1
    foundCount = 0
    FOR i = 0 TO numProds - 1
        IF prodCat(i) = searchCat THEN
            s = TRIM$(prodName(i))
            PRINT "  " & s & " - $" & FORMAT$(prodPrice(i))
            foundCount = foundCount + 1
        END IF
    NEXT i
    IF foundCount = 0 THEN
        PRINT "  No products found in this category"
    END IF
    PRINT

    PRINT "--- Search by Price Range ($50 - $300) ---"
    searchMin = 50.0
    searchMax = 300.0
    foundCount = 0
    FOR i = 0 TO numProds - 1
        IF prodPrice(i) >= searchMin AND prodPrice(i) <= searchMax THEN
            s = TRIM$(prodName(i))
            PRINT "  " & s & " - $" & FORMAT$(prodPrice(i))
            foundCount = foundCount + 1
        END IF
    NEXT i
    PRINT "  " & STR$(foundCount) & " products in this price range"
    PRINT

    PRINT "--- Products with Rating >= 4 ---"
    foundCount = 0
    FOR i = 0 TO numProds - 1
        IF prodRating(i) >= 4 THEN
            s = TRIM$(prodName(i))
            PRINT "  " & s & " (rating: " & STR$(prodRating(i)) & "/5)"
            foundCount = foundCount + 1
        END IF
    NEXT i
    PRINT "  " & STR$(foundCount) & " highly rated products"
    PRINT

    PRINT "--- Low Stock Items (< 15 units) ---"
    foundCount = 0
    FOR i = 0 TO numProds - 1
        IF prodStock(i) < 15 THEN
            s = TRIM$(prodName(i))
            PRINT "  " & s & " (only " & STR$(prodStock(i)) & " left)"
            foundCount = foundCount + 1
        END IF
    NEXT i
    IF foundCount = 0 THEN
        PRINT "  All items well stocked"
    END IF
    PRINT

    PRINT "--- Search by Name (starts with 'W') ---"
    FOR i = 0 TO numProds - 1
        s = TRIM$(prodName(i))
        IF LEFT$(s, 1) = "W" THEN
            PRINT "  " & TRIM$(s)
        END IF
    NEXT i

    PRINT
    PRINT "Product catalog search complete."

    FUNCTION = 0
END FUNCTION
