:: phone_widgets[widget]

<<widget 'phoneConversation'>>
	<<set $conversationNpcID = _args[0]>>
	<<set _conversationPassage = _args[1]>>
	<div class="call conversation">
		<<image $npc(_callingNpcID).image>>
		<h2><<=$npc(_callingNpcID).fullname>></h2>
		<div id="phoneConversationBody">
			<<include _conversationPassage>>
		</div>
	</div>

<</widget>>

<<widget 'phoneConversationEnd'>>
	<<set _label = _args[0]>>
	<<link _label>>
		<<phoneOverlayRemove>>
	<</link>>
<</widget>>

<<widget "phoneCoversationOption" container>>
	<<set _label = _args[0]>>
	<<capture _contents>>
		<<link _label>>
			<<replace "#phoneConversationBody">>
				_contents
			<</replace>>
		<</link>>
	<</capture>>
<</widget>>

<<widget 'phoneMain'>>
	<<if !$phoneTheme>><<set $phoneTheme = 'Custom_Standard'>><</if>>
	<<set _iconFolder = 'system/phone/theme/'+$phoneTheme+'/'>>
	<<phoneOverlayAdd>>
		<<phoneMainMenu>>
	<</phoneOverlayAdd>>
<</widget>>

<<widget 'phoneMainMenu'>>
	<div id="mainMenu">
		<<linkedImage `_iconFolder+'icon_sms.png'`>>
			<<replace '#phonecontents'>>
				<<phoneSMSMenu>>
			<</replace>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_calendar.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_call.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_camera.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_megafon.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_music.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_notebook.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_pictures.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_settings.png'`>>
		<</linkedImage>>
		<<linkedImage `_iconFolder+'icon_weather.png'`>>
		<</linkedImage>>
	</div>
<</widget>>

<<widget 'phoneRing'>>
	<<set _callingNpcID = _args[0]>>
	<<set _callingTopic = _args[1]>>
	<<phoneOverlayAdd>>
		<div class="call incomming">
			<<image $npc(_callingNpcID).image>>
			<h2><<=$npc(_callingNpcID).fullname>></h2>
			<div class="answerButton">
				<<link "Answer">>
					<<replace "#phonecontents">>
						<<phoneConversation _callingNpcID _callingTopic>>
					<</replace>>
				<</link>>
			</div>
		</div>
	<</phoneOverlayAdd>>
<</widget>>

<<widget "phoneOverlayAdd" container>>
	<<done>>
		<<append "#passages">>
			<div id="phoneContainer">
				<div id="phone">
					<div id="head"><<time_current>><span id="signalStrength">📶</span></div>
					<div id="phonecontents">_contents</div>
				</div>
			</div>
		<</append>>

		<<timed 1s>>
			<<append "#phoneContainer">>
				<<link "">>
					<<phoneOverlayRemove>>
				<</link>>
			<</append>>
		<</timed>>
	<</done>>
<</widget>>

<<widget 'phoneOverlayRemove'>>
	<<remove "#phoneContainer">>
<</widget>>

<<widget 'phoneReceivePendingCall'>>
	<<set _callNpcs = []>>
	<<for _npcID range $npcs.datingNPCs>>
		<<set _npcNextDateExpected = $npc(_npcID).date.nextDateExpected>>
		<<if _npcNextDateExpected >= 0 and _npcNextDateExpected <= $time.daystart>>
			<<set _dayTheNPCWantsToCall = $time.daystart - _npcNextDateExpected>>
			<<set _weight = Math.pow(_dayTheNPCWantsToCall + 1 , 2)>>
			<<run _callNpcs.push({
				npcId: _npcID,
				weight: _weight,
				topic: 'boyfriendPhoneIncomming'
			})>>
		<</if>>

	<</for>>

	<<if _callNpcs.length > 0>>
		<<set _callData = _callNpcs.getRandomWeighted()>>
		<<run console.log('Phone',_callNpcs,_callData)>>
		<<phoneRing _callData.npcId _callData.topic>>
	<</if>>
<</widget>>

<<widget 'phoneSMSMenu'>>
	<<if !$phone.hasSms>>
		<p>You don't have any messages.</p>
	<<else>>
		<div id="smsSenderOverview">
			<<for _npcId range $phone.smsContacts>>
				<<set _styleClass = "sender">>
				<<if $phone.smsHasNew(_npcId)>>
					<<set _styleClass += " hasNew">>
				<</if>>
				<div @class=_styleClass>
					<<image $npc(_npcId).image>>
					<div class="nickname"><<=$npc(_npcId).usedname>></div>
					<<capture _npcId>>
						<<link "">>
							<<replace "#phonecontents">>
								<<smsShow _npcId>>
							<</replace>>
						<</link>>
					<</capture>>
				</div>
			<</for>>
		</div>
	<</if>>
<</widget>>

<<widget 'smsSend'>>
	<<set _sms_npcId 		= _args[0]>>
	<<set _sms_datetime 	= _args[1]>>
	<<set _sms_bodyPassage	= _args[2]>>

	/*<<set $sms ??= {}>>
	<<set $sms[_sms_npcId] ??= {messages:[],unread:0}>>

	<<set _message = {time:_sms_datetime,body:_sms_bodyPassage, seed: rand(0,999999)}>>
	<<run $sms[_sms_npcId].messages.push(_message)>>
	<<set $sms[_sms_npcId].unread += 1>>
	<<run console.log('SMS generated',_sms_npcId,_message)>>*/
	<<run $phone.smsCreate(_sms_npcId,_sms_datetime,_sms_bodyPassage)>>
<</widget>>

<<widget 'smsShow'>>
	<<set _sms_npc_id = _args[0]>>
	<!-- <<set _sms = $sms[_sms_npc_id].messages.toReversed()>> -->
	/*<<set _sms = $sms[_sms_npc_id].messages>>*/
	<<set _sms = $phone.smsBySender(_sms_npc_id)>>
	<<for _sm range _sms>>
		<div class="sms">
			<div class="messageBody">
				<<set _messageData = _sm.data ?? {}>>
				<<randomSeed _sm.seed>>
					<!-- Use seed to make sure that a message that contains random elements will always stay the same. -->
					<<include _sm.body>>
				<</randomSeed>>
			</div>
			<div class="time"><<time_print _sm.time>></div>
		</div>
	<</for>>
	<<run $phone.smsSetRead(_sms_npc_id)>>
<</widget>>

:: telefonheader_macro[widget]
<<widget 'telefonheader'>>
	<<if getvar("$telefon['UnreadSMS']") > 0>>
		<<setinit $telefon['SMSstatus'] = 'You have telefon['UnreadSMS'] unread message(s)'>>
	<<else>>
		<<setinit $telefon['SMSstatus'] = ''>>
	<</if>>
	<!-- FAILED TO CONVERT
	$result = '<center>
-----
	<<set $result = ERROR: FAILED TO CONVERT LITERAL: """'<center>""">>

-->
<<warn "CONVERSION ERROR 80353b27d42ecc975fdab0132a975ff1">>
	<b><<$mid(100+hour,2,2)>>:<<$mid(100+minut,2,2)>></b><br>
	<TABLE cellspacing="0" width="80%">
	<TR>
	<TD><<image 'images/system/icons/icon_statusbar_left.png'>></TD>
	<TD><<$telefon[''SMSstatus'']>></TD>
	<TD align="right"><<image 'images/system/icons/icon_statusbar_right.png'>></TD>
	</TR>
	<!-- FAILED TO CONVERT
	</TABLE><br>'
-----
	ERROR: FAILED TO CONVERT LITERAL: """<""" / ERROR: FAILED TO CONVERT LITERAL: """TABLE><br>'"""

-->
<<warn "CONVERSION ERROR 35c9fafeb6f0b947228c8ab2fed29619">>
<</widget>>
:: telefonfooter_macro[widget]
<<widget 'telefonfooter'>>
	<<if $telefon['backButton'] == ''>>
	<<setinit $telefon['backButton'] = 'gs 'telefon', 'Phone_menu''>>

<</if>>
	<!-- FAILED TO CONVERT
	$result = '	<a href="exec:<<$telefon[''backButton'']>>"><img src="images/system/icons/back.png"></a><br><br>
-----
	<<set $result = ERROR: FAILED TO CONVERT LITERAL: """'	<a href="exec:$telefon['backButton']"><<image 'images""" / $system / $icons / ERROR: FAILED TO CONVERT LITERAL: """back.png'>><""" / ERROR: FAILED TO CONVERT LITERAL: """a><br><br>""">>

-->
<<warn "CONVERSION ERROR 4b68b3151eb9ebe33b90b9c376d5dfa2">>
	<<link "Put Phone Away.">><</link>><br>
	<!-- FAILED TO CONVERT
	</center>'
-----
	ERROR: FAILED TO CONVERT LITERAL: """<""" / ERROR: FAILED TO CONVERT LITERAL: """center>'"""

-->
<<warn "CONVERSION ERROR 4929f2c41ca2fd9e7e6efbb87973773c">>
	<<setinit $telefon['backButton'] = 'gs 'telefon', 'Phone_menu''>>
<</widget>>
:: telefonprint_macro[widget]
<<widget 'telefonprint'>>
		setup.func('cleanHTML',dyneval($telefon['header']) + $telefon['body'] + dyneval($telefon['footer']))
<</widget>>
:: telefoncontact_macro[widget]
<<widget 'telefoncontact'>>
	<!-- !! Contact Row in phone contact list-->
	<!-- !! _args[0] = NPC icon-->
	<!-- !! _args[1] = NPC Nickname-->
	<!-- !! _args[2] = Code to execute for making a Call-->
	<!-- !! _args[3] = if statement for determining if NPC is avaiable-->
	<<setinit $telefon['ContactIcon'] = _args[0]>>
	<<setinit $telefon['ContactNickName'] = _args[1]>>
	<<setinit $telefon['ContactCallCode'] = _args[2]>>
	<<setinit $telefon['ContactCallSchedule'] = _args[3]>>
	<!-- !!If file extension is not given, .png is assumed-->
	<<if instr($telefon['ContactIcon'],'.') == 0>>
		<<setinit $telefon['ContactIcon'] += '.png'>>
	<</if>>
	<!-- !!If path is not given, default phone icon path is assumed-->
	<<if instr($telefon['ContactIcon'],'/') == 0>>
		<<setinit $telefon['ContactIcon'] = 'images / $system / $phone / $icons /  + $telefon['ContactIcon']>>
	<</if>>
	<!-- !!If Contact is not in available timeframe, we disable contact calling-->
	<<if dyneval('$result = iif(<<$telefon["ContactCallSchedule"]>>,1,0)') = 0>>
		<<setinit $telefon['ContactCallCode'] = "gs 'telefon', 'phone_call_reject'">>
	<</if>>
	<!-- FAILED TO CONVERT
	$result = '<TR>
-----
	<<set $result = ERROR: FAILED TO CONVERT LITERAL: """'<TR>""">>

-->
<<warn "CONVERSION ERROR edb5281e131fc51d862cca5d07e312c8">>
	<TD><img src="<<$telefon[''ContactIcon'']>>" width="75"></TD>
	<TD><<$telefon[''ContactNickName'']>></TD>
	<TD align="right"><a href="exec:$callerid = ''<<$telefon[''ContactIcon'']>>'' & <<$telefon[''ContactCallCode'']>>"><b>Call</b></a></TD>
	<!-- FAILED TO CONVERT
	</TR>'
-----
	ERROR: FAILED TO CONVERT LITERAL: """<""" / ERROR: FAILED TO CONVERT LITERAL: """TR>'"""

-->
<<warn "CONVERSION ERROR 0eefe07fed739a6b0ee6d0d33049cbab">>
<</widget>>
:: telefonSMS_macro[widget]
<<widget 'telefonSMS'>>
	<<setinit $telefon['SMSid'] = _args[0]>>
	<<setinit $telefon['ContactIcon'] = _args[1]>>
	<<setinit $telefon['ContactNickName'] = _args[2]>>
	<<setinit $telefon['SMSTime'] = _args[3]>>
	<<setinit $telefon['SMSStatus'] = _args[4]>>
	<!-- !!If file extension is not given, .png is assumed-->
	<<if instr($telefon['ContactIcon'],'.') == 0>>
		<<setinit $telefon['ContactIcon'] += '.png'>>
	<</if>>
	<!-- !!If path is not given, default phone icon path is assumed-->
	<<if instr($telefon['ContactIcon'],'/') == 0>>
		<<setinit $telefon['ContactIcon'] = 'images / $system / $phone / $icons /  + $telefon['ContactIcon']>>
	<</if>>
	<!-- !! unread will be bold-->
	<<if getvar("$telefon['SMSStatus']") == 0>>
		<<setinit $telefon['SMSstyle1'] = '<b>'>>
		<<setinit $telefon['SMSstyle2'] = '</b>'>>
	<<else>>
		<<setinit $telefon['SMSstyle1'] = ''>>
		<<setinit $telefon['SMSstyle2'] = ''>>
	<</if>>
	<!-- FAILED TO CONVERT
	$result = '<TR>
-----
	<<set $result = ERROR: FAILED TO CONVERT LITERAL: """'<TR>""">>

-->
<<warn "CONVERSION ERROR edb5281e131fc51d862cca5d07e312c8">>
	<TD><img height=100 src="<<$telefon[''ContactIcon'']>>"></TD>
	<TD><<$telefon[''SMSstyle1'']>><<$telefon[''ContactNickName'']>><<$telefon[''SMSstyle2'']>></TD>
	<TD align="right"><<$telefon[''SMSstyle1'']>><a href="exec:gs ''telefon'', ''show_sms'', <<telefon[''SMSid'']>>"><<$telefon[''SMSTime'']>></a><<$telefon[''SMSstyle2'']>></TD>
	<!-- FAILED TO CONVERT
	<TD><<$telefon[''SMSstyle1'']>><a href="exec:gs ''telefon'', ''delete_sms'', <<telefon[''SMSid'']>>">Delete</a><<$telefon[''SMSstyle2'']>></TD>
-----
	<TD><<$telefon[''SMSstyle1'']>><<link "Delete">><<gs 'telefon' 'delete_sms' ERROR: FAILED TO CONVERT LITERAL: """<<telefon['SMSid']>>""">><</link>><<$telefon[''SMSstyle2'']>></TD>

-->
<<warn "CONVERSION ERROR f47ba8c6ae6f1db0bd80af1885d33ceb">>
	<!-- FAILED TO CONVERT
	</TR>'
-----
	ERROR: FAILED TO CONVERT LITERAL: """<""" / ERROR: FAILED TO CONVERT LITERAL: """TR>'"""

-->
<<warn "CONVERSION ERROR 0eefe07fed739a6b0ee6d0d33049cbab">>
<</widget>>
:: telefoncontactsms_macro[widget]
<<widget 'telefoncontactsms'>>
	<!-- !! Contact Row in phone contact list-->
	<<setinit $telefon['ContactIcon'] = $contactIcon[_args[0]]>>
	<<setinit $telefon['ContactNPCcode'] = $contact[_args[0]]>>
	<!-- !!If file extension is not given, .png is assumed-->
	<<if instr($telefon['ContactIcon'],'.') == 0>>
		<<setinit $telefon['ContactIcon'] += '.png'>>
	<</if>>
	<!-- !!If path is not given, default phone icon path is assumed-->
	<<if instr($telefon['ContactIcon'],'/') == 0>>
		<<setinit $telefon['ContactIcon'] = 'images / $system / $phone / $icons /  + $telefon['ContactIcon']>>
	<</if>>
	<<set $result = >>
	<TR>
	<TD><img src="<<$telefon[''ContactIcon'']>>" width="75"></TD>
	<TD><<<<=$npc($telefon[''ContactNPCcode'').nickname>>]>></TD>
	<TD><<link "New Message">><<gs 'telefon' 'npcSendListSms' '$telefon['ContactNPCcode']'>><</link>></TD>
	<!-- FAILED TO CONVERT
	</TR>'
-----
	ERROR: FAILED TO CONVERT LITERAL: """<""" / ERROR: FAILED TO CONVERT LITERAL: """TR>'"""

-->
<<warn "CONVERSION ERROR 0eefe07fed739a6b0ee6d0d33049cbab">>
<</widget>>
:: telefonsmsMessageToSend_macro[widget]
<<widget 'telefonsmsMessageToSend'>>
	<<setinit $telefon['ContactNPCcode'] = $SMSSendContact[_args[0]]>>
	<<set $result = >>
	<TR>
	<TD><<<<=$npc($telefon[''ContactNPCcode'').nickname>>]>></TD>
	<TD><a href="exec: gs ''telefon'', ''smsSendMessage'', ''<<ARGS[0]>>''"><<$SMSSendMessage[ARGS[0]]>></a></TD>
	<!-- FAILED TO CONVERT
	</TR>'
-----
	ERROR: FAILED TO CONVERT LITERAL: """<""" / ERROR: FAILED TO CONVERT LITERAL: """TR>'"""

-->
<<warn "CONVERSION ERROR 0eefe07fed739a6b0ee6d0d33049cbab">>
<</widget>> */
