local core = require("core")
local command = require("core.command")

local function log_result(label, result, err)
	if err then
		core.error("%s failed: %s", label, tostring(err))
	else
		core.log("%s result: %s", label, tostring(result))
	end
end

command.register({
	["native-dialog-test:message-info"] = {
		perform = function()
			local result, err = system.show_message_box({
				title = "Lx Native Dialog Test",
				message = "This is system.show_message_box with one OK button.",
				type = "info",
				buttons = { "ok" },
				default = "ok",
				cancel = "ok",
			})
			log_result("message-info", result, err)
		end,
	},

	["native-dialog-test:message-choice"] = {
		perform = function()
			local result, err = system.show_message_box({
				title = "Lx Native Dialog Test",
				message = "Choose one button. The selected value is written to the log.",
				type = "question",
				buttons = { "yes", "no", "cancel" },
				default = "yes",
				cancel = "cancel",
			})
			log_result("message-choice", result, err)
		end,
	},

	["native-dialog-test:confirm-compat"] = {
		perform = function()
			local result, err = system.show_confirm_dialog(
				"Lx Confirm Compatibility Test",
				"This uses the existing system.show_confirm_dialog wrapper."
			)
			log_result("confirm-compat", result, err)
		end,
	},

	["native-dialog-test:open-file"] = {
		perform = function()
			local result, err = system.open_file_dialog({
				default_path = EXE_DIR,
				filters = {
					{ name = "Text and Lua", spec = "txt,lua,md" },
					{ name = "All Files", spec = "*" },
				},
			})
			log_result("open-file", result, err)
		end,
	},
})
