//
//  XinZengDiZhiViewController.swift
//  GeliBusinessPlatform
//
//  Created by junye lu on 2020/4/26.
//  Copyright © 2020 junye lu. All rights reserved.
//

import UIKit

class XinZengDiZhiViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource,TitleAndTFAndBtnCellDelegate{
    let titleArr = ["收货人:","地址:","详细地址:","手机号:","电话:","邮编:"]
    let holderArr = ["请填写收货人姓名","请选择城市","请输入详细地址","请输入手机号","请输入电话","请输入邮编"]
    @IBOutlet weak var listView: UITableView!
    @IBAction func saveAction(_ sender: Any) {
        print("保存")
    }
    
    var navTitle:String?
    override func viewDidLoad() {
        super.viewDidLoad()
        navbar.title = navTitle
        if navTitle == "编辑地址" {
            navbar.rightTitle = "删除"
        }
        self.view.addSubview(navbar)
        
        listView.separatorStyle = .none

        listView.snp.makeConstraints { (make) in
            make.top.equalTo(NavCGRect.height)
            make.left.right.equalTo(0)
            make.height.equalTo(418*glscale)
        }
        listView.isScrollEnabled = false
        listView.register(UINib(nibName: "TitleAndTFCell", bundle: nil), forCellReuseIdentifier: "TitleAndTFCell")
        listView.register(UINib(nibName: "TitleAndBtnCell", bundle: nil), forCellReuseIdentifier: "TitleAndBtnCell")
        listView.register(UINib(nibName: "TitleAndSwitchCell", bundle: nil), forCellReuseIdentifier: "TitleAndSwitchCell")
        listView.register(UINib(nibName: "TitleAndTFAndBtnCell", bundle: nil), forCellReuseIdentifier: "TitleAndTFAndBtnCell")
        // Do any additional setup after loading the view.
    }
    func rightBtnClick() {
        print("删除")
    }
    //MARK: -  cell delegate
    func TitleAndTFAndBtnCellBtnClick() {
        let vc = SJMapViewController()
        self.navigationController?.pushViewController(vc, animated: true)
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: fullScreenWidth, height: 10*glscale))
        view.backgroundColor = UIColor.clear
        return view
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section != 0 {
            return 10*glscale
        }
        return 0.001
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 49*glscale
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 6
        }
        return 1
      }
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        switch indexPath.section {
        case 0:
            if indexPath.row != 1 && indexPath.row != 2 {
                let cell = tableView.dequeueReusableCell(withIdentifier: "TitleAndTFCell") as! TitleAndTFCell
                cell.nameLbl.text = titleArr[indexPath.row]
                cell.textTF.placeholder = holderArr[indexPath.row]
                return cell
            }
            if indexPath.row == 1 {
                let cell = tableView.dequeueReusableCell(withIdentifier: "TitleAndBtnCell") as! TitleAndBtnCell
                cell.nameLbl.text = titleArr[indexPath.row]
                cell.contentLbl.text = holderArr[indexPath.row]
                return cell
            }
            let cell = tableView.dequeueReusableCell(withIdentifier: "TitleAndTFAndBtnCell") as! TitleAndTFAndBtnCell
            cell.titleLbl.text = titleArr[indexPath.row]
            cell.textTF.placeholder = holderArr[indexPath.row]
            cell.delegate = self
            return cell
        default:
            let cell = tableView.dequeueReusableCell(withIdentifier: "TitleAndSwitchCell") as! TitleAndSwitchCell
            cell.namelbl.text = "设为默认收货地址"
            if indexPath.section == 1 {
                 cell.namelbl.text = "设为默认寄件地址"
            }
            return cell
        }
      }
    
 
}