local p = {}

function p.link(frame)
    -- Get the current page name ({{PAGENAME}})
    local pageName = mw.title.getCurrentTitle().text

    -- Capture the parameters from the template call
    local args = frame:getParent().args
    -- If param1 is not provided, use the page name, otherwise use param1
    local param1 = args[1] and args[1] ~= "" and args[1] or pageName 
    -- Capture param2 if provided, otherwise default to an empty string
    local param2 = args[2] and args[2] ~= "" and args[2] or ""

    -- Construct the query string with proper encoding
    local query = mw.uri.encode(param1) .. "+" .. mw.uri.encode(param2)

    -- Construct the final URL
    local url = "https://prpm.dbp.gov.my/cari1?keyword=" .. query .. "&d=107200&#LIHATSINI"

    -- Return the final output with the page name as the hyperlink text
    return string.format('[%s "%s"] di Pusat Rujukan Persuratan Melayu (Glosari Dialek Kelantan).', url, pageName)
end

return p