<?php
	
	include_once __DIR__ . '/include/common.php';
	include_once __DIR__ . '/include/general_functions.php';
	include_once __DIR__ . '/include/utils.php';	
	include_once __DIR__ . '/include/user.php';
	
	if ( ! @$user)
			redirect('/');
	
	$params	=	[];
	
	$item	=	get_item(
		$_GET['id']		//	id	вещи
	);
	
	if ( ! $item)
			redirect('/shop/?');
	
	$sum	=	0;
	$usedItem	=	0;
	
	$place	=	get_item_place(
		$item['type']
	);
	$quality=	get_item_quality(
		$item['quality']
	);
	$bonus	=	get_item_bonus(
		$item['quality']
	);
	$skill	=	get_item_skill(
		$item['quality']
	);
	$bonus_k	=	get_item_bonus_k(
		$item['quality']
	);
	
	$sum	=	$item['str']	+	$item['dex']	+	$item['life']	+	$item['protection'];
	
	if ($user[ $item['type'] ] != 0)
	{
		
		$usedItem	=	get_user_item(
			$user['id'],
			$user[ $item['type'] ]
		);
		$userdItem_bonus_k	=	get_item_bonus_k(
			$usedItem['quality']
		);
		
		$usedItem_rune	=	get_rune_by(
			$usedItem['type']
		);
		$usedItem_rune_bonus	=	get_rune_bonus(
			$usedItem['rune']
		);
		
		$usedItemStr	=	$usedItem['str']	+	ceil($usedItem['bonus'] * $userdItem_bonus_k)	+	($usedItem['up'] * 24);
		$usedItemDex	=	$usedItem['dex']	+	ceil($usedItem['bonus'] * $userdItem_bonus_k)	+	($usedItem['up'] * 24);
		$usedItemProtection
						=	$usedItem['protection']
												+	ceil($usedItem['bonus'] * $userdItem_bonus_k)	+	($usedItem['up'] * 24);	
		$usedItemLife	=	$usedItem['life']	+	ceil($usedItem['bonus'] * $userdItem_bonus_k)	+	($usedItem['up'] * 24);
		
		${'usedItem' . ucfirst($usedItem_rune)}
						+=	$usedItem_rune_bonus;
		
		$usedItemSum	=	$usedItemStr	+	$usedItemDex	+	$usedItemLife	+	$usedItemProtection;
		
	}
	
	$params['title']	=	$item['name'];
	
	ob_start();
	
	include_once __DIR__ . '/include/header.php';
	
	?>
	<div class='container'>
		<table>
			<tr>
			<td style='vertical-align:	top;'><img src='/itemImage.php?index=<?=$item['id']?>' alt='' /></td>
			<td style='vertical-align:	top;'>
				<img src='/images/icon/quality/<?=$item['quality']?>.png' alt='' /> <?=$item['name']?>, <?=$place?><br />
				<span class='small quality-<?=$item['quality']?>'> <?=$quality?> [0/<?=$bonus?>]</span><br />
	<?php
	if ($user['skill']	>=	$skill)
	{
	?>
				<img src='/images/icon/skill.png' alt='' /> <span class='small'>Мастерство: <?=$skill?></span>
	<?php
	}
	else
	{
	?>
				<img src='/images/icon/skill.png' alt='' /> <span class='small'>Мастерство: <span class='c_red'> <?=$skill?></span></span>
	<?php
	}
	?>
			</td>
			</tr></table>
	</div>
	<div class='min-line'></div>
	<div class='container'>
	
	<?php
	if ($user[ $item['type'] ] != 0)
	{
	
		if ($item['str'] > $usedItemStr)
	{
	?>
		<img src='/images/icon/str.png' alt='' /> Сила: <span class='c_green'><?=$item['str']?></span><br />
	<?php
	}
	elseif ($item['str'] ==$usedItemStr)
	{
	?>
		<img src='/images/icon/str.png' alt='' /> Сила: <?=$item['str']?><br />
	<?php
	}
	else
	{
	?>
		<img src='/images/icon/str.png' alt='' /> Сила: <span class='c_red'><?=$item['str']?></span><br />
	<?php
	}
	?>

	<?php
		if ($item['dex'] > $usedItemDex)
	{
	?>
		<img src='/images/icon/agi.png' alt='' /> Ловкость: <span class='c_green'><?=$item['dex']?></span><br />
	<?php
	}
	elseif ($item['dex'] ==$usedItemDex)
	{
	?>
		<img src='/images/icon/agi.png' alt='' /> Ловкость: <?=$item['dex']?><br />
	<?php
	}
	else
	{
	?>
		<img src='/images/icon/agi.png' alt='' /> Ловкость: <span class='c_red'><?=$item['dex']?></span><br />
	<?php
	}
	?>
	
	<?php
		if ($item['life'] > $usedItemLife)
	{
	?>
		<img src='/images/icon/vit.png' alt='' /> Жизни: <span class='c_green'><?=$item['life']?></span><br />
	<?php
	}
	elseif ($item['life'] ==$usedItemLife)
	{
	?>
		<img src='/images/icon/vit.png' alt='' /> Жизни: <?=$item['life']?><br />
	<?php
	}
	else
	{
	?>
		<img src='/images/icon/vit.png' alt='' /> Жизни: <span class='c_red'><?=$item['life']?></span><br />
	<?php
	}
	?>
	
	<?php
		if ($item['protection'] > $usedItemProtection)
	{
	?>
		<img src='/images/icon/def.png' alt='' /> Защита: <span class='c_green'><?=$item['protection']?></span><br />
	<?php
	}
	elseif ($item['protection'] ==$usedItemProtection)
	{
	?>
		<img src='/images/icon/def.png' alt='' /> Защита: <?=$item['protection']?><br />
	<?php
	}
	else
	{
	?>
		<img src='/images/icon/def.png' alt='' /> Защита: <span class='c_red'><?=$item['protection']?></span><br />
	<?php
	}
	?>
	
	<?php		
			$diff	=	$sum	-	$usedItemSum;
		if ($diff > 0)
		{
	?>
		<img src='/images/icon/quest.png' alt='' /> <span class='c_green'>Лучше +<?=$diff?></span>
		
	<?php
		}
	
	}
	else
	{
	
	?>
	
		<img src='/images/icon/str.png' alt='' /> Сила: <?=$item['str']?><br />
		<img src='/images/icon/agi.png' alt='' /> Ловкость: <?=$item['dex']?><br />
		<img src='/images/icon/def.png' alt='' /> Броня: <?=$item['protection']?><br />
		<img src='/images/icon/vit.png' alt='' /> Жизни: <?=$item['life']?>
		
	<?php
	
	}
	?>
	</div>
	<div class='min-line'></div>
	<div class='container cntr'>
		<a href='/complect//<?=$item['id']?>/' class='btn'>Купить за <img src='/images/icon/gold.png' alt='' /> <?=$item['cost']?></a>
	</div>
	<?php
	
	if ($user[ $item['type'] ] != 0)
	{
		
		$quality=	get_item_quality($usedItem['quality']);
		$bonus	=	get_item_bonus($usedItem['quality']);
		
	?>
	<div class='min-line'></div>
	<div class='container cntr large c_blue'>На вас надето</div><div class='dtd-line'></div>
	<div class='container'>
		<table>
			<tr>
			<td style='vertical-align:	top;'><img src='/itemImage.php?index=<?=$usedItem['shop_id']?>&up=<?=$userItem['up']?>' alt='' /></td>
			<td style='vertical-align:	top;'>
				<img src='/images/icon/quality/<?=$usedItem['quality']?>.png' alt='' /> <?=$usedItem['name']?><br />
				<span class='small quality-<?=$usedItem['quality']?>'> <?=$quality?> [<?=$usedItem['bonus']?>/<?=$bonus?>]</span>
			</td>
		</tr></table>
	</div>
	<div class='min-line'></div>
	<div class='container'>
	
		<img src='/images/icon/str.png' alt='' /> Сила: <?=$usedItemStr?><br />
		<img src='/images/icon/agi.png' alt='' /> Ловкость: <?=$usedItemDex?><br />
		<img src='/images/icon/vit.png' alt='' /> Жизни: <?=$usedItemLife?><br />
		<img src='/images/icon/def.png' alt='' /> Защита: <?=$usedItemProtection?>
		
	</div>
		
	<?php
	}
			
	include_once __DIR__ . '/include/footer.php';
	
	setContentType('text/html; charset=UTF-8');
	render(
		__DIR__ . '/include/template.php',
		ob_get_clean(),
		$params
	);
	
?>