<?xml version="1.0" encoding="UTF-8"?>
<component name="Account" extends="Panel"  initialFocus="buttons">

	<script type="text/brightscript" uri="pkg:/components/generalUtils.brs"/>
	<script type="text/brightscript" >
		 <![CDATA[
		
			sub init()
			  m.top.panelSize = "wide"
			  m.top.focusable = true
			  m.top.hasNextPanel = false
			  
			  m.button = m.top.findNode("buttons")
			  m.infolabel = m.top.findNode("infoLabel")
			  str = "User Account: " + m.global.user
			  str = str + chr(10) + "Expiration: " + m.global.expire
			  str = str + chr(10) + "Device: " + GetModel()
			  str = str + chr(10) + "Serial Number: " + GetDeviceESN()
			  str = str + chr(10)  + "App Version: " + GetAppVersion()
			  m.infolabel.text = str
			  
			  m.button.observeField("itemSelected","unlink")
			end sub
			
			sub unlink()
				'print "In unlink()"
				m.unlinkTask = createObject("roSGNode","unlinkTask")
				m.unlinkTask.observeField("state","unlinkDone")
		        m.busyDialog = createObject("roSGNode", "ProgressDialog")
		        m.top.getScene().dialog = m.busyDialog
			end sub
			
			sub unlinkDone()
			    'print "in unlinkDone()"
			    if m.unlinkTask.state = "stop" then
			        if m.unlinkTask.validated then
			            m.busyDialog.close = true 
			            m.dialog = createObject("roSGNode", "Dialog")
			            m.dialog.title = "Unlinked Successfully"
			            m.dialog.optionsDialog = true
			            m.dialog.message = "You have successfully unlinked this device from your account" 
				        m.dialog.buttons = ["OK"]
                        m.dialog.observeField("buttonSelected", "unlinkSuccess")
			            m.top.getScene().dialog = m.dialog
			        else 
			        	m.busyDialog.close = true 
			            m.dialog = createObject("roSGNode", "Dialog")
			            m.dialog.title = "Unlinking Failed"
			            m.dialog.optionsDialog = true
			            m.dialog.message = "The unlinking process failed." 
				        m.dialog.buttons = ["OK"]
                        m.dialog.observeField("buttonSelected", "showExitButton")
			            m.top.getScene().dialog = m.dialog
			        end if 
			    end if
			 end sub
			  
			 sub unlinkSuccess()
			    m.top.getScene().close = true
			 end sub
			 
			 sub showExitButton()
			    m.top.getScene().dialog.close = true
			 end sub

		]]>

  	</script>
	<children>
		<LabelList
			id="buttons"
			translation="[250,630]"
			focusedColor="0xddddddff"
			focusBitmapUri="pkg:/images/red.9.png"
			textHorizAlign="center">
			<ContentNode id = "buttonsContent" role = "content" >
		    	<ContentNode title = "Unlink Device" />
		    </ContentNode>
		
			<Rectangle 
		      id = "infoRectangle" 
		      translation = "[ -130, -590 ]" 
		      height = "560" 
		      width = "820" 
		      color = "0x101010C0" >
		
		      <Label 
		        id = "infoLabel" 
		        translation = "[ 15, 15 ]" 
		        height = "530" 
		        width = "790" 
		        wrap = "true" 
		        font = "font:MediumBoldSystemFont" />
			
		    </Rectangle>
		</LabelList> 
	</children>
</component>
