//
//  Alert.swift
//  Kalker
//
//  Created by Łukasz Żukowski on 31.08.2017.
//  Copyright © 2017 Starlab. All rights reserved.
//

import Foundation
import UIKit
import AVFoundation

func setAlert(title: String, message: String) -> UIViewController {
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
    
    return alert
}

func setPhoneAlert(title: String, message: String, phone: String) -> UIViewController {
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "Anuluj", style: .cancel, handler: nil))
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { action in
        switch action.style{
        case .default:
            print("default")
            guard let number = URL(string: "telprompt://\(phone)") else { return }
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(number)
            } else {
                UIApplication.shared.openURL(number)
            }
            
        case .cancel:
            print("cancel")
            
        case .destructive:
            print("destructive")
        }
    }))
    
    return alert
}

func setNotifForCaregiver(title: String, message: String, navcontroller: UINavigationController) -> UIViewController {
    let systemSoundID: SystemSoundID = 1301
    AudioServicesPlaySystemSound(systemSoundID)
    
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "Zobacz", style: .default, handler: { action in
        switch action.style{
        case .default:
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "loginCaregiver") as! CaregiverCallsViewController
            navcontroller.pushViewController(vc, animated: true)
            
        case .cancel:
            print("cancel")
            
        case .destructive:
            print("destructive")
        }
    }))
    
    return alert
}

func setNotifForPatient(title: String, message: String, navcontroller: UINavigationController) -> UIViewController {
    let systemSoundID: SystemSoundID = 1301
    AudioServicesPlaySystemSound(systemSoundID)
    
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
    
    return alert
}
