 import QRCodeReader
 import MessageUI
 
+
+fileprivate enum ConnectionState
+{
+	case disconnected, joined, hosting
+	
+	var actionText: String
+	{
+		var text = ""
+		
+		switch self
+		{
+		case .disconnected: text = "Disconnect"
+		case .joined: text = "Join"
+		case .hosting: text = "Host"
+		}
+		
+		return NSLocalizedString(text, comment: "A label for an action that changes an online state")
+	}
+	
+	var processingText: String
+	{
+		var text = ""
+		
+		switch self
+		{
+		case .disconnected: text = "Disconnecting"
+		case .joined: text = "Joining"
+		case .hosting: text = "Hosting"
+		}
+		
+		return NSLocalizedString(text, comment: "A label for a processing online state")
+	}
+	
+	var ongoingText: String
+	{
+		var text = ""
+		
+		switch self
+		{
+		case .disconnected: text = "Disconnected"
+		case .joined: text = "Joined"
+		case .hosting: text = "Hosting"
+		}
+		
+		return NSLocalizedString(text, comment: "A label for an ongoing online state")
+	}
+}
+
 @IBDesignable class ConnectionUIView: CustomXibView, QRCodeReaderViewControllerDelegate, UITableViewDataSource, UITableViewDelegate, MFMailComposeViewControllerDelegate, ConnectionListener
 {
 	// OUTLETS	--------------

		bookSelectionTableView.dataSource = self
		bookSelectionTableView.delegate = self
		
		do
		{
			if let projectId = Session.instance.projectId, let project = try Project.get(projectId)
			{
				targetTranslations = try project.targetTranslationQuery().resultObjects()
			}
		}
		catch
		{
			print("ERROR: Failed to read target translation data. \(error)")
		}
		
		updateStatus()

		return QRCodeReaderViewController(builder: builder)
	}()
	
	private var canHost = false
	private var canJoin = false
	
	
	// COMPUTED PROPERTIES	----
	
	private var availableConnectionStates: [(ConnectionState, Int)]
	{
		var states = [(ConnectionState.disconnected, 0)]
		var nextIndex = 1
		
		if canJoin
		{
			states.add((ConnectionState.joined, nextIndex))
			nextIndex += 1
		}
		if canHost
		{
			states.add((ConnectionState.hosting, nextIndex))
			nextIndex += 1
		}
		
		return states
	}
	
	
	// INIT	--------------------
	
