//
//  MyCartVC.swift
//  Garmentoo
//
//  Created by Vijith on 31/03/22.
//

import UIKit

class MyCartVC: UIViewController {
    @IBOutlet weak var bottomView:UIView!
    
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    override func viewWillAppear(_ animated: Bool) {
        setui()
        
    }
    
   
    
    @IBAction func OnTapPayments(_ sender: Any) {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let nextVc = sb.instantiateViewController(withIdentifier: "MyAddressVC")as! MyAddressVC
        nextVc.isFromCart = true
        nextVc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(nextVc, animated: true)
    }
}
extension MyCartVC: UITableViewDelegate,UITableViewDataSource
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cartCell", for: indexPath) as! MyCartTableViewCell
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 140
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let nextVc = sb.instantiateViewController(withIdentifier: "ProductDetailVC") as! ProductDetailVC
        nextVc.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(nextVc, animated: true)
    }
    
    // for swpe to delete function
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
            let deleteAction = UIContextualAction(style: .destructive, title: "") {  (contextualAction, view, boolValue) in
                self.deleteData(at: indexPath)
            }
       // deleteAction.backgroundColor = UIColor(patternImage: UIImage(named: "delete_background")!)

//            let editAction = UIContextualAction(style: .normal, title: "Edit") {  (contextualAction, view, boolValue) in
//                self.editData(at: indexPath)
        
//            }
//            editAction.backgroundColor = .purple
        
        deleteAction.image = UIImage(named: "delete1")
        deleteAction.backgroundColor = UIColor.red
            let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction])

            return swipeActions
        }

        func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
            return true
        }

        func deleteData(at indexPath: IndexPath) {
            print(indexPath.row)
        }

        
    
    
}
extension MyCartVC
{
    func setui(){
        bottomView.layer.cornerRadius = 20
        bottomView.clipsToBounds = true
        bottomView.layer.masksToBounds = false
        bottomView.layer.shadowRadius = 4
        bottomView.layer.shadowColor = UIColor.tabcolor.cgColor
        bottomView.layer.shadowOpacity = 0.4
        bottomView.layer.shadowOffset = CGSize(width: 0, height: -1)
        bottomView.layer.maskedCorners = [.layerMinXMinYCorner,.layerMaxXMinYCorner]
        bottomView.layer.shadowColor = UIColor.red.cgColor
        self.bottomView.backgroundColor = UIColor.viewBg
        
       
    
}
}
