//
//  CallProfiViewController.swift
//  Em-call
//
//  Created by Alex Sh on 27.03.2022.
//

import UIKit

class KeyValueCell: UITableViewCell {
    
    var keyLabel: UILabel? = nil
    
  //  var valueLabel: UILabel? = nil

}

class CallProfiViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
 
    @IBOutlet weak var tableView: UITableView!
    let cellReuseIdentifier = "cell"
    var address = "Unknow address"
    var dateAndTime = "2022/02/23"
    var contact = "+1 123 112 11 22"
    var card = "**** **** **** 1234"
    

    override func viewDidLoad() {
        super.viewDidLoad()

      tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier)
      //tableView.rowHeight = 45
        tableView.estimatedRowHeight = 44
        tableView.rowHeight = UITableView.automaticDimension
       tableView.delegate = self
       tableView.dataSource = self
        let item1 = setBarButtom(str: "akar-icons_arrow-left")
        self.navigationItem.setLeftBarButtonItems([item1], animated: true)

       let item2 = setBarButtom(str: "gg_close")
       self.navigationItem.setRightBarButtonItems([item2], animated: true)
    }
    
    func setBarButtom(str:String)->UIBarButtonItem {
        let btn1 = UIButton(type: .custom)
         btn1.setImage(UIImage(named: str), for: .normal)
         btn1.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
         btn1.addTarget(self, action: #selector(self.back), for: .touchUpInside)
         let item1 = UIBarButtonItem(customView: btn1)
        return item1
    }
    @objc
    func back() {
        navigationController?.popViewController( animated: true)
    }
    
    
    @IBAction func pressShowMap(_ sender: Any) {
        guard let vc = storyboard?.instantiateViewController(withIdentifier: "Logo")
        else { return  }
        (vc as! MainViewController).showWorkerMap = 1
       // (vc as! CalendarViewController).delegate = self
        navigationController?.pushViewController(vc, animated: true)
       // self.present(vc, animated: true, completion: nil)
    }
    
    
    func numberOfSections(in tableView: UITableView) -> Int {
       return 4
   }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       // let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath)
      //  let cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell", for: indexPath)
      //  let cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell") as! CustCellTableViewCell
                  //let track = trackList[indexPath.row]
        var cell:CustCellTableViewCell
      let section = indexPath.section
      switch section {
      case 0:
        cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell") as! CustCellTableViewCell
        cell.custCell.text = address
      case 1:
         cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell2") as! CustCellTableViewCell
        cell.custCell2.text = dateAndTime
               // cell.imageCell.isHidden = true
      case 2:
         cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell2") as! CustCellTableViewCell
        cell.custCell2?.text = contact
        cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
      case 3:
         cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell") as! CustCellTableViewCell
        cell.custCell?.text = card
                cell.imageCell?.image = UIImage(named: "Vector")
        cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
     // default:           break
      default:
        cell = tableView.dequeueReusableCell(withIdentifier: "cust_cell2") as! CustCellTableViewCell
       cell.custCell2?.text = contact
        cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
      }
       // cell.textLabel?.textColor = UIColor.darkGray
        //cell.textLabel?.font = UIFont(name: "Helvetica-Regular", size: 13)
       
      
        return cell

    }
    
    func tableView(_ tableView: UITableView, titleForHeaderInSection  section: Int) -> String? {
        switch section {
         case 0:            return ("Work location")
        case 1:            return ("Date and Time")
        case 2:            return ("Your contacts")
         case 3:            return ("Payment")
         default:            return ("")
         }
     }
    
    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        // Создаём константу, именна через неё мы будем обращаться к свойствам и изменять их
    let header = view as! UITableViewHeaderFooterView
        // Установить цвет текста в label
    header.textLabel?.textColor = .black
        // Установить цвет фона для секции
    header.tintColor = UIColor.white
        // Установить шрифт и размер шрифта для label
   // header.textLabel?.font = UIFont(name: "Helvetica-Regular", size: 12)
    }

}
