require "scripts/dialog_common.lua"

play_from_database( "requester_open", false, 1.0, 0, 0 )

CheckboxButtonGraphics = {
	"buttons/checkup",
	"buttons/checkdown",
	"buttons/checkover",
	"buttons/checkdownover"
} ;

CheckboxButtonStyle = {
	parent = DefaultStyle,
	font = RequesterTextFont,
	type = kToggle,
	sound = kDefaultButtonSound,
	graphics = CheckboxButtonGraphics,
} ;

MakeDialog
{
    name = "profile_dialog",

    Bitmap {
        image = "images/background.png",
        x = 0,
        y = 0,
        w = 800,
        h = 600,
        alpha = true,

    ProfilesWindow {
        fit = true,
        x = kCenter,
        y = kCenter,
        w = 497,
        h = dialog_height( 200 ),

        requester_background( 200, "blue", "better" ),

        Text
        {
            font = SmallerSpecialRequesterTitleFont,
            name = "window_title",
            x = kCenter, y = 32 + 0, w = 160, h = 34,
            flags = kHAlignCenter + kVAlignCenter,
            label = "profile_dialog_title"
        },
        
        SetStyle(CheckboxButtonStyle),
        Button
        {
            name = "check_0",
            x = 50 + 17, y = 59 + 30, w = 260,
            Text
            {
                font = RequesterButtonFont,
                name = "label_0",
                x = 54, y = 25, w = kMax, h = kMax,
                flags = kHAlignLeft + kVAlignTop,
                label = "profile_dialog_empty",
            };
        },
        Button
        {
            name = "check_1",
            x = 50 + 17, y = 59 + 70, w = 260,
            Text
            {
                font = RequesterButtonFont,
                name = "label_1",
                x = 54, y = 25, w = kMax, h = kMax,
                flags = kHAlignLeft + kVAlignTop,
                label = "profile_dialog_empty",
            };
        },
        Button
        {
            name = "check_2",
            x = 50 + 17, y = 59 + 110, w = 260,
            Text
            {
                font = RequesterButtonFont,
                name = "label_2",
                x = 54, y = 25, w = kMax, h = kMax,
                flags = kHAlignLeft + kVAlignTop,
                label = "profile_dialog_empty",
            };
        },
        Button
        {
            name = "check_3",
            x = 50 + 17, y = 59 + 150, w = 260,
            Text
            {
                font = RequesterButtonFont,
                name = "label_3",
                x = 54, y = 25, w = kMax, h = kMax,
                flags = kHAlignLeft + kVAlignTop,
                label = "profile_dialog_empty",
            };
        },

		Button
		{
			x = 50 + 250, y = 59 + 50,
			font = RequesterButtonFont,
			graphics = NewButtonGraphics,
			name = "button_new",
			type = kPush,
			default = true,
			command = function()
                play_from_database( "button_click_alt", false, 1.0, 0, 0 )
				local result = ProfilesDialogNew()
				if ( result == 1 ) then
				    DisplayDialog { "scripts/profile_ok.lua", body = "profile_error_too_many" };
				else
				    DisplayDialog { "scripts/new_profile.lua" }
	    			ProfilesDialogUpdateView()
	    		end
			end,
			Text {
			    label = "profile_dialog_new",
                x = 0, y = 2, w = kMax, h = 27,
                flags = kHAlignRight + kVAlignCenter,
                font = RequesterButtonFont,
            },
		},

		Button
		{
			x = 50 + 250, y = 59 + 90,
			font = RequesterButtonFont,
			graphics = NewButtonGraphics,
			name = "button_delete",
			type = kPush,
			command = function()
                play_from_database( "button_click_alt", false, 1.0, 0, 0 )
                DisplayDialog { "scripts/profile_yesno.lua", body = "profile_dialog_delete_confirm" }
                local result = ProfilesDialogDelete()
                if result == 1 then
                    DisplayDialog { "scripts/profile_ok.lua", body = "profile_error_too_few" };
                end
			end,
            Text {
			    label = "profile_dialog_delete",
                x = 0, y = 2, w = kMax, h = 27,
                flags = kHAlignRight + kVAlignCenter,
                font = RequesterButtonFont,
            },
		},

		Button
		{
			x = 50 + 250, y = 59 + 130,
			font = RequesterButtonFont,
			graphics = NewButtonGraphics,
			name = "button_ok",
			type = kPush,
			command = function()
                play_from_database( "button_click_alt", false, 1.0, 0, 0 )
                PopModal( "profile_dialog" )
			end,
            Text {
			    label = "profile_dialog_ok",
                x = 0, y = 2, w = kMax, h = 27,
                flags = kHAlignRight + kVAlignCenter,
                font = RequesterButtonFont,
            },
		},
    },
    },
    FitToChildren(),
}

