//
// © 2017-2020 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
//

import UIKit

enum SpinnerReason {
    case unspecified
    case wiFi
    case speakers
    
    func spinnerText() -> String {
        switch self {
        case .unspecified:
            return NSLocalizedString("Please wait...", comment:"Unspecified spinner text")
        case .wiFi:
            return NSLocalizedString("Waiting for Wi-Fi to become available...", comment:"Waiting For Wifi spinner text")
        case .speakers:
            return NSLocalizedString("SEARCHING FOR SPEAKERS", comment:"Speakers spinner text")
        }
    }
}

// MARK: -

class SpinnerViewController: UIViewController {
    @IBOutlet private weak var label: UILabel?
    @IBOutlet private weak var indicator: UIImageView?
    @IBOutlet private weak var boxView: UIView?
    
    var reason: SpinnerReason = .unspecified {
        didSet {
            label?.text = reason.spinnerText()
        }
    }
}

extension SpinnerViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        boxView?.layer.cornerRadius = 5
        boxView?.clipsToBounds = true
        indicator?.loadAnimationImages(nameStem: "indeterminate-progress-frame", count: 55)
        indicator?.startAnimating()
        
        label?.text = reason.spinnerText()
    }
}
