require( "scripts/style.lua" );

local minQuality = curQuality + 1;
local quality = minQuality;

function updateQuality(qlt)
	SetLabel("value", "$"..tostring(GetHiringPriceSelecting(qlt)));
end

function updateButtons(qlt)
	for i = 1, 4 do
		SetButtonToggleState( "star"..i, false );
	end
	for i = 1, qlt-1 do
		SetButtonToggleState( "star"..i, true );
	end
	
end

function setQuality(qlt)
	local price = GetHiringPriceSelecting(qlt)
	if price <= availableMoney then
		if qlt >= minQuality then
			quality = qlt
			updateQuality(qlt)
			updateButtons(qlt)
		else SetButtonToggleState( "star"..qlt, false)
		end
	else SetButtonToggleState( "star"..qlt, true)	
	end
end

function setFontSize(size)
	local temp = {
		standardFont,
		size,
		BlackColor
	}	
	return temp;	
end

MakeDialog
{
	name="hireviniculture",
    
    FaderWindow
	{
		wait=0,
		duration=100,
		fit = true,
		startalpha = 0,
		finalalpha = 1,
		skip = false,
    
		--Bitmap
		--{
		--	image="backgrounds/shade",
		--	alpha = 1,
		--},
		
		Bitmap
		{
			image="backgrounds/dialog",
			x=306,
			y=226,

			SetStyle(DialogTitleText),
			Text
			{
				name = "hiretitle",
				label= "hireprofessional_title",
			},

			SetStyle(DialogBodyText),
			Text
			{
				name = "hirebody",
				label= "hireprofessional",
				font= setFontSize(16),
				y=0,
			},
			
			Text
			{
				name = "servicename",
				font = setFontSize(30),
				label= "selectinggrapes",
				x=50,
				y=60,		
			},
			
			Text
			{
				name = "value",
				font= setFontSize(25),
				x=50,
				y=176,		
			},
			
			SetStyle(ButtonStdOkStyle),
			--ShadowedButton
			Button
			{
				command = function()
							--PopModal("hireWindow");
							HireSelecting(quality);
							ModalReturn(1);
						 end,
				clickSound = "audio/sfx/buttons/default_click.ogg",
				close = true,
				flags = 5,
				--mylabel = GetString("hire"),
				label = "hire",
				name = startname,
				x = 200,
				y = 200,
			},
			--ShadowedButton
			Button
			{
				--command=cancelfunction;
				command = function ()
						ModalReturn(0)
					end,
				clickSound = "audio/sfx/buttons/default_click.ogg",
				close = true,
				flags = 5,
				--mylabel = GetString("cancel"),
				label = "cancel",
				name = cancelname,
				x = 288,
				y = 200,
			},
			SetStyle(StarButtonStyle),
			Button
			{
				name="star1",
				command= function()
							setQuality(1);
						 end,
				close = false,
				x=105,
				y=145,
				type=kToggle,
			},
			Button
			{
				name="star2",
				command= function()
							setQuality(2);
						 end,
				close = false,
				x=155,
				y=145,
				type=kToggle,
			},
			Button
			{
				name="star3",
				command= function()
							setQuality(3);
						 end,
				close = false,
				x=205,
				y=145,
				type=kToggle,
			},
			Button
			{
				name="star4",
				command= function()
							setQuality(4);
						 end,
				close = false,
				x=255,
				y=145,
				type=kToggle,
			},
		},
	},
	PlayPopupSound();
}
updateButtons(quality+1);
updateQuality(quality);