Documentation for this module may be created at ಮಾಡ್ಯೂಲ್:Calendar/kn/doc

local p = {}

-- Kannada numerals for localization
local kannadaNumbers = {
    ["0"] = "೦", ["1"] = "೧", ["2"] = "೨", ["3"] = "೩", ["4"] = "೪",
    ["5"] = "೫", ["6"] = "೬", ["7"] = "೭", ["8"] = "೮", ["9"] = "೯"
}

-- Kannada month names
local kannadaMonths = {
    "ಜನವರಿ", "ಫೆಬ್ರವರಿ", "ಮಾರ್ಚ್", "ಎಪ್ರಿಲ್", "ಮೇ", "ಜೂನ್",
    "ಜುಲೈ", "ಆಗಸ್ಟ್", "ಸೆಪ್ಟೆಂಬರ್", "ಅಕ್ಟೋಬರ್", "ನವೆಂಬರ್", "ಡಿಸೆಂಬರ್"
}

-- Convert numbers to Kannada
local function convertToKannada(number)
    return tostring(number):gsub("%d", function(digit)
        return kannadaNumbers[digit] or digit
    end)
end

-- Function to get the header (month and year in Kannada)
function p.getHeader(frame)
    local year = tonumber(frame.args.year) or 2024
    local month = tonumber(frame.args.month) or 1
    if month < 1 or month > 12 then return "ಅಸಮಾನ್ಯ ತಾರೀಖು" end
    return kannadaMonths[month] .. " " .. convertToKannada(year)
end

-- Function to build the calendar
function p.build(frame)
    local month = tonumber(frame.args.month) or 1
    local year = tonumber(frame.args.year) or 2024

    -- Validate inputs
    if month < 1 or month > 12 then return "ಅಸಮಾನ್ಯ ತಿಂಗಳು" end
    if year < 1 then return "ಅಸಮಾನ್ಯ ವರ್ಷ" end

    -- Calculate days in the month
    local firstDay = os.time{year = year, month = month, day = 1}
    local daysInMonth = os.date("*t", os.time{year = year, month = month + 1, day = 0}).day
    local dayOfWeek = tonumber(os.date("%w", firstDay))

    -- Generate calendar rows
    local calendar = {}
    local row = {}

    -- Fill empty cells before the first day
    for _ = 1, dayOfWeek do
        table.insert(row, '<td style="border: 1px solid #ccc;"> </td>')
    end

    -- Add days to the calendar
    for day = 1, daysInMonth do
        local dayStr = convertToKannada(day)
        table.insert(row, '<td style="border: 1px solid #ccc; text-align: center;">' .. dayStr .. '</td>')
        if #row == 7 then
            table.insert(calendar, "<tr>" .. table.concat(row) .. "</tr>")
            row = {}
        end
    end

    -- Fill remaining empty cells
    while #row < 7 do
        table.insert(row, '<td style="border: 1px solid #ccc;"> </td>')
    end
    if #row > 0 then
        table.insert(calendar, "<tr>" .. table.concat(row) .. "</tr>")
    end

    -- Return the final calendar
    return table.concat(calendar, "\n")
end

return p