class MaintenancePanel extends InteractiveMasterDevice
{
	default m_controllerTypeName = 'MaintenancePanelController';
	private var m_animFeature : AnimFeature_SimpleDevice;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'disassemblableComponent', 'DisassemblableComponent', true );
		super.OnRequestComponents( ri );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_disassemblableComponent = ( ( DisassemblableComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'disassemblableComponent' ) ) );
		super.OnTakeControl( ri );
		m_controller = ( ( MaintenancePanelController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	private const override function GetController() : MaintenancePanelController
	{
		return ( ( MaintenancePanelController )( m_controller ) );
	}

	public const override function GetDevicePS() : MaintenancePanelControllerPS
	{
		return GetController().GetPS();
	}

	protected override function RestoreDeviceState()
	{
		super.RestoreDeviceState();
	}

	protected override function EnterWorkspot( activator : GameObject, optional freeCamera : Bool, optional componentName : CName, optional deviceData : CName )
	{
		var workspotSystem : WorkspotGameSystem;
		workspotSystem = GameInstance.GetWorkspotSystem( activator.GetGame() );
		workspotSystem.PlayInDeviceSimple( this, activator, freeCamera, componentName, 'deviceWorkspot' );
	}

	protected event OnDisassembleDevice( evt : DisassembleDevice )
	{
		var playerStateMachineBlackboard : IBlackboard;
		var playerPuppet : PlayerPuppet;
		playerPuppet = ( ( PlayerPuppet )( GameInstance.GetPlayerSystem( GetGame() ).GetLocalPlayerMainGameObject() ) );
		EnterWorkspot( playerPuppet, false, 'disassembleWorkspot' );
		SetGameplayRoleToNone();
		playerStateMachineBlackboard = GameInstance.GetBlackboardSystem( GetGame() ).GetLocalInstanced( playerPuppet.GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
		playerStateMachineBlackboard.SetBool( GetAllBlackboardDefs().PlayerStateMachine.IsInteractingWithDevice, true );
		UpdateDeviceState();
		DelayApperanceSwitchEvent( 'Yellow', 1.67999995 );
		DelayApperanceSwitchEvent( 'default', 2.98000002 );
		DelayApperanceSwitchEvent( 'red', 4.03000021 );
	}

	protected event OnDelayApperanceSwitchEvent( evt : panelApperanceSwitchEvent ) {}

	protected event OnWorkspotFinished( componentName : CName )
	{
		var playerStateMachineBlackboard : IBlackboard;
		var playerPuppet : PlayerPuppet;
		if( componentName == 'disassembleWorkspot' )
		{
			playerPuppet = ( ( PlayerPuppet )( GameInstance.GetPlayerSystem( GetGame() ).GetLocalPlayerMainGameObject() ) );
			playerStateMachineBlackboard = GameInstance.GetBlackboardSystem( GetGame() ).GetLocalInstanced( playerPuppet.GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
			playerStateMachineBlackboard.SetBool( GetAllBlackboardDefs().PlayerStateMachine.IsInteractingWithDevice, false );
			m_disassemblableComponent.ObtainParts();
			GetDevicePS().RefreshLockOnSlaves();
			UpdateAnimState();
		}
	}

	public const function IsAuthorizationModuleOn() : Bool
	{
		return GetDevicePS().IsAuthorizationModuleOn();
	}

	private function UpdateAnimState()
	{
		if( !( m_animFeature ) )
		{
			m_animFeature = new AnimFeature_SimpleDevice;
		}
		m_animFeature.isOpen = true;
		m_interaction.Toggle( false );
		AnimationControllerComponent.ApplyFeature( this, 'DeviceMaintenancePanel', m_animFeature );
	}

	private function DelayApperanceSwitchEvent( newApperance : CName, time : Float )
	{
		var evt : panelApperanceSwitchEvent;
		evt = new panelApperanceSwitchEvent;
		evt.newApperance = newApperance;
		GameInstance.GetDelaySystem( GetGame() ).DelayEvent( this, evt, time );
	}

}

class panelApperanceSwitchEvent extends Event
{
	var newApperance : CName;
}

