local mad = require "MoonAdditions"

-- Constants
local MENU_TITLE = "Main Menu"
local MENU_X = 45
local MENU_Y = 240
local MENU_TITLE_SIZE = 1.40
local MENU_ITEM_HEIGHT = 17
local MENU_ITEM_WIDTH = 125
local MENU_WIDTH = 190
local MENU_ITEM_SPACING = 1  -- Additional space between items
local MENU_COLOR = {r = 153, g = 238, b = 153, a = 255}
local TEXT_COLOR = {r = 255, g = 255, b = 255, a = 255}
local CURSOR_HOVER_COLOR = {r = 255, g = 170, b = 255, a = 255}
local DESCRIPTION_COLOR = {r = 255, g = 230, b = 100, a = 255} -- Yellow color for descriptions
local DESCRIPTION_FONT_SIZE = 0.75  -- Smaller font size for descriptions

-- Define menu items, their actions, and descriptions
local menuItems = {
    {label = "Recording", action = function() printStringNow("Recording action triggered!", 500) end, description = "Start audio recording"},
    {label = "Playback", action = function() printStringNow("Playback action triggered!", 500) end, description = "Play recorded audio"},
    {label = "Pause", action = function() printStringNow("Pause action triggered!", 500) end, description = "Pause current action"},
    {label = "Car slot", action = function() printStringNow("Car slot action triggered!", 500) end, description = "Manage car storage"},
    {label = "Save/Load", action = function() printStringNow("Save/Load action triggered!", 500) end, description = "Save or load settings"},
    {label = "Triggers", action = function() printStringNow("Triggers action triggered!", 500) end, description = "Configure trigger actions"},
    {label = "Options", action = function() printStringNow("Options action triggered!", 500) end, description = "Adjust settings"}
}

-- Draw a text with given attributes
local function drawText(text, x, y, size, color, isHovered)
    local style = mad.font_style.FONT_SUBTITLES
    local width = size * 0.58
    local height = size * 1.02
    local align = mad.font_align.LEFT
    local wrap = MENU_WIDTH
    local proportional = true
    local justify = false  

    local textColor = isHovered and CURSOR_HOVER_COLOR or color
    mad.draw_text(text, x, y, style, width, height, align, wrap, proportional, justify, 
                  textColor.r, textColor.g, textColor.b, textColor.a, 
                  1, 0, 0, 0, 0, 255, 0, 0, 0, 0)
end

-- Check if a point is within a rectangular area
local function isPointInArea(pointX, pointY, rectX, rectY, rectWidth, rectHeight)
    return pointX >= rectX and pointX <= rectX + rectWidth and
           pointY >= rectY and pointY <= rectY + rectHeight
end

-- Main function
function main()
    while not isPlayerPlaying(PLAYER_HANDLE) do wait(100) end
    wait(100)

    local wasLMBDown = false

    while true do
        wait(0)

        drawText(MENU_TITLE, MENU_X, MENU_Y, MENU_TITLE_SIZE, MENU_COLOR, false)

        local cursorX, cursorY = getCursorPos()
        local isLMBDown = isKeyDown(1)  -- Check if the left mouse button is pressed
        local currentDescription = ""

        for i, item in ipairs(menuItems) do
            local itemY = MENU_Y + 10 + (MENU_ITEM_HEIGHT + MENU_ITEM_SPACING) * i
            local isHovered = isPointInArea(cursorX, cursorY, MENU_X, itemY, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT)

            -- Draw the menu item
            drawText(item.label, MENU_X, itemY, 1, TEXT_COLOR, isHovered)

            -- Update the current description based on the hovered item
            if isHovered then
                currentDescription = item.description
            end

            if isHovered and isLMBDown and not wasLMBDown then
                item.action()
            end
        end

        -- Draw the current description under the last menu item with smaller size
        local descriptionY = MENU_Y + 15 + (MENU_ITEM_HEIGHT + MENU_ITEM_SPACING) * (#menuItems + 1)
        drawText(currentDescription, MENU_X, descriptionY, DESCRIPTION_FONT_SIZE, DESCRIPTION_COLOR, false)

        wasLMBDown = isLMBDown  -- Update the LMB state
    end
end


сделай этиот код более расширяемым, добавь в него поддержку сразу несколькоих возможных меню