' menu_recent.pb — Recent files list (MRU) simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL recentFiles(50) AS LONG
    LOCAL recentCount AS LONG
    LOCAL maxRecent AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL newFileID AS LONG
    LOCAL steps AS LONG
    LOCAL found AS LONG
    LOCAL tempFile AS LONG
    LOCAL result AS LONG
    LOCAL limit AS LONG
    LOCAL fileStr AS STRING
    LOCAL displayStr AS STRING

    maxRecent = 10
    recentCount = 0

    PRINT "=== Recent Files Manager ==="
    PRINT "Max recent files: " + STR$(maxRecent)

    FOR steps = 1 TO 15
        IF steps = 1 THEN newFileID = 1
        IF steps = 2 THEN newFileID = 2
        IF steps = 3 THEN newFileID = 3
        IF steps = 4 THEN newFileID = 4
        IF steps = 5 THEN newFileID = 5
        IF steps = 6 THEN newFileID = 6
        IF steps = 7 THEN newFileID = 7
        IF steps = 8 THEN newFileID = 8
        IF steps = 9 THEN newFileID = 9
        IF steps = 10 THEN newFileID = 10
        IF steps = 11 THEN newFileID = 2
        IF steps = 12 THEN newFileID = 11
        IF steps = 13 THEN newFileID = 12
        IF steps = 14 THEN newFileID = 3
        IF steps = 15 THEN newFileID = 13

        IF newFileID > 0 THEN
            IF newFileID = 1 THEN fileStr = "report.doc"
            IF newFileID = 2 THEN fileStr = "budget.xls"
            IF newFileID = 3 THEN fileStr = "notes.txt"
            IF newFileID = 4 THEN fileStr = "presentation.ppt"
            IF newFileID = 5 THEN fileStr = "photo.jpg"
            IF newFileID = 6 THEN fileStr = "index.html"
            IF newFileID = 7 THEN fileStr = "data.csv"
            IF newFileID = 8 THEN fileStr = "config.ini"
            IF newFileID = 9 THEN fileStr = "script.bas"
            IF newFileID = 10 THEN fileStr = "readme.md"
            IF newFileID = 11 THEN fileStr = "summary.pdf"
            IF newFileID = 12 THEN fileStr = "archive.zip"
            IF newFileID = 13 THEN fileStr = "newfile.cpp"

            found = -1
            FOR i = 0 TO recentCount - 1
                IF recentFiles(i) = newFileID THEN
                    found = i
                END IF
            NEXT i

            IF found >= 0 THEN
                tempFile = recentFiles(found)
                FOR i = found TO 1 STEP -1
                    recentFiles(i) = recentFiles(i - 1)
                NEXT i
                recentFiles(0) = tempFile
                PRINT "  Moved to top: " + fileStr
            ELSE
                IF recentCount < maxRecent THEN
                    FOR i = recentCount TO 1 STEP -1
                        recentFiles(i) = recentFiles(i - 1)
                    NEXT i
                    recentFiles(0) = newFileID
                    recentCount = recentCount + 1
                    PRINT "  Added: " + fileStr
                ELSE
                    FOR i = maxRecent - 1 TO 1 STEP -1
                        recentFiles(i) = recentFiles(i - 1)
                    NEXT i
                    recentFiles(0) = newFileID
                    PRINT "  Added (full): " + fileStr
                END IF
            END IF
        END IF
    NEXT steps

    PRINT "--- Recent Files (" + STR$(recentCount) + ") ---"
    FOR i = 0 TO recentCount - 1
        tempFile = recentFiles(i)
        IF tempFile = 1 THEN displayStr = "report.doc"
        IF tempFile = 2 THEN displayStr = "budget.xls"
        IF tempFile = 3 THEN displayStr = "notes.txt"
        IF tempFile = 4 THEN displayStr = "presentation.ppt"
        IF tempFile = 5 THEN displayStr = "photo.jpg"
        IF tempFile = 6 THEN displayStr = "index.html"
        IF tempFile = 7 THEN displayStr = "data.csv"
        IF tempFile = 8 THEN displayStr = "config.ini"
        IF tempFile = 9 THEN displayStr = "script.bas"
        IF tempFile = 10 THEN displayStr = "readme.md"
        IF tempFile = 11 THEN displayStr = "summary.pdf"
        IF tempFile = 12 THEN displayStr = "archive.zip"
        IF tempFile = 13 THEN displayStr = "newfile.cpp"
        PRINT "  " + STR$(i + 1) + ". " + displayStr + " (ID=" + STR$(tempFile) + ")"
    NEXT i

    PRINT "Removing index.html..."
    found = -1
    FOR i = 0 TO recentCount - 1
        IF recentFiles(i) = 6 THEN
            found = i
        END IF
    NEXT i
    IF found >= 0 THEN
        FOR i = found TO recentCount - 2
            recentFiles(i) = recentFiles(i + 1)
        NEXT i
        recentCount = recentCount - 1
    END IF
    PRINT "Recent count: " + STR$(recentCount)

    PRINT "=== End Recent Files ==="
    FUNCTION = 0
END FUNCTION
