:: RefillableBottle_DrinkEvent[indoors_events outdoors_events]
<<event 20>>
	<<if $inventory.get('refillable_bottle')>>
		<<set _refillable_bottle_data = $inventory.metadata('refillable_bottle')>>
		<<if _refillable_bottle_data.fill > 0 && $pc.pcs_hydra < _refillable_bottle_data.autodrink>>
			<<run $inventory.metadataUpdate('refillable_bottle',undefined,{fill:Math.max(0,_refillable_bottle_data.fill-0.5)})>>
			<<set $pc.pcs_hydra += 50>>
		<</if>>
	<</if>>
<</event>>

:: RefillableBottle_RefillEvent[kitchen_events]
<<event 10>>
	<<if $inventory.get('refillable_bottle')>>
		<<if $inventory.metadata('refillable_bottle').autorefill>>
			<<run $inventory.metadataUpdate('refillable_bottle',undefined,{fill:1})>>
		<</if>>
	<</if>>
<</event>>
:: RefillableBottle[menu]

<<set _metadata = $inventory.metadata('refillable_bottle')>>

<<set _autorefill = _metadata.autorefill ? true : false>>
<<set _autodrink  = _metadata.autodrink ?? 0>>

<<image 'pc/items/refillablebottle.jpg'>>

<p>
	<<gs 'RefillableBottleDescription'>>
</p>

<p>
	<<checkbox "_autorefill" false true autocheck>>
	Refill this bottle automatically when at a place where free clean water is easily available (kitchens, bathrooms, etc.).
</p>
<p>
	Automatically drink from this bottle when your thirst drops below this treshhold (enter 0 to disable): <<numberbox "_autodrink" 0>>
</p>

<<act 'Confirm'>>
	<<run $inventory.metadataUpdate('refillable_bottle',undefined,{autodrink:_autodrink,autorefill:_autorefill})>>
	<<gt 'Purse'>>
<</act>>

:: RefillableBottleDescription[include]
<<if $inventory.get('refillable_bottle')>>
	<<set _refillable_bottle_data = $inventory.metadata('refillable_bottle')>>
	The bottle is <<=Math.floor((_refillable_bottle_data.fill ?? 0) * 100)>>% full.
<<else>>
	A bottle that fits into your purse and can be refilled with water an infinite number of times.
	Both the refilling of and the drinking from the bottle can be set to happen automatically.
<</if>>