:: stock_item_widget[widget]
<<widget 'stockItem'>>
	<<set _stockItem = {}>>
	<<set _stockItem.id = _args[0].id>>
	<<set _stockItem.amount = _args[0].amount || 1>>
	<<set _stockItem.label = _args[0].label || _stockItem.id>>
	<<set _stockItem.price = _args[0].price || 100>>

	<<set _limit = setup.items[_stockItem.id]?.limit || 0>>
	<<set _currentItemAmount = $inventory.get(_stockItem.id)>>

	<<set _stockItem = Object.assign({},_stockItem,$inventory.metadataConst(_stockItem.id))>>

	<<if !_limit or (_currentItemAmount + _stockItem.amount) <= _limit>>
		<div class="stockItem">
			<<if _stockItem.desc or _stockItem.image>>
				<span class="label"><<textWithTooltip _stockItem.label>><<if _stockItem.image>><<image _stockItem.image>><br/><</if>><<if _stockItem.desc>>_stockItem.desc<</if>><</textWithTooltip>></span>			
			<<else>>
				<span class="label">_stockItem.label</span>			
			<</if>>
			<span class="amount">_stockItem.amount</span>
			<span class="price"><<money _stockItem.price>></span>
			<<capture _stockItem>>
				<<buyButton _stockItem.price 3>>
					<<run $inventory.inc(_stockItem.id,_stockItem.amount)>>
					<<refresh>>
				<</buyButton>>
			<</capture>>

		</div>
		<span class="pcOwned"><<=_currentItemAmount>></span>
	<</if>>

<</widget>>

<<widget "buyButton" container>>
	<!--
		Arg 1: Price
		Arg 2: Mode
			1: Cash only
			2: Bank only
			3: Cash and bank
	-->
	<<set _price = _args[0]>>
	<<set _mode to _args[1]>>
	<<set _buyButtonContents to _contents>>

	<<capture _price, _buyButtonContents>>
		<<if _mode == 1 or _mode == 3>>
			<<if $finances.cash >= _price>>
				<div class="buyLink buyLinkCash">
					<<link "Buy (Cash)">>
						<<set $finances.cash -= _price>>
						_buyButtonContents
					<</link>>
				</div>
			<<else>>
				<div class="buyLink buyLinkCash insufficientFunds">
					<<link "Buy (Cash)">><</link>>
				</div>
			<</if>>
		<</if>>
		<<if _mode == 2 or _mode == 3>>
			<<if $finances.hasBankAccount == 0>>
				<div class="buyLink buyLinkBank disabled">
					<<link "Buy (Bank)">><</link>>
				</div>
			<<elseif $finances.bankAvailable >= _price>>
				<div class="buyLink buyLinkBank">
					<<link "Buy (Bank)">>
						<<set $finances.bank -= _price>>
						_buyButtonContents
					<</link>>
				</div>
			<<else>>
				<div class="buyLink buyLinkBank insufficientFunds">
					<<link "Buy (Bank)">><</link>>
				</div>
			<</if>>
		<</if>>
	<</capture>>
<</widget>>

<<widget "shopItemList" container>>
	<div class="shopItemList">
		<div class="header">
			<div>Name</div>
			<div>Amount</div>
			<div>Price</div>
			<div></div>
			<div></div>
			<div>You have</div>
		</div>
		_contents
	</div>
<</widget>>
