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

import UIKit
import Alamofire
import SwiftyJSON

class SendViewController: UIViewController {

    @IBOutlet weak var popup: UIView!
    @IBOutlet weak var imageCall: UIImageView!
    @IBOutlet weak var titleCall: UILabel!
    
    var callId: Int!
    var idPatient: Int!
    var idCaregiver: Int!
    let callsTitle = Call.getCallTitle()
    let callsImage = Call.getCallImage()
    
    var sendCallJSON: JSON!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setWhiteBackground(viewForBackground: popup)
        popup.layer.cornerRadius = 5
        popup.layer.masksToBounds = true
        imageCall.layer.cornerRadius = 7
        imageCall.layer.masksToBounds = true
        
        imageCall.image = self.callsImage[callId]
        titleCall.text = self.callsTitle[callId]
        
        print(callId)
        print(idPatient)
        print(idCaregiver)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func closePopup(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
    @IBAction func cancelPopup(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
    @IBAction func sendCall(_ sender: UIButton) {
        let parameters = ["idCall": callId! + 1,
                          "idPatient": idPatient!,
                          "idCaregiver": idCaregiver!]
        
        Alamofire.request("https://kalkerapp.pl/api/sendCall.php", method: .post, parameters: parameters)
            .responseJSON { response in
                if let jsonData = response.result.value {
                    self.sendCallJSON = JSON(jsonData)
                    print(self.sendCallJSON)
                    
                }
        }
        self.dismiss(animated: true, completion: nil)
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
