//
//  Cell_HomeDays.swift
//  Service
//
//  Created by Jan on 2023/7/18.
//  Copyright © 2023 yus. All rights reserved.
//

import UIKit

class Cell_HomeDays: UITableViewCell {

    @IBOutlet weak var lab_weekDay1: UILabel!
    @IBOutlet weak var lab_num1: UILabel!
    @IBOutlet weak var lab_day1: UILabel!
    
    //选中标识
    @IBOutlet weak var flagView1: UIView!
    
    @IBOutlet weak var flagView2: UIView!
    
    @IBOutlet weak var flagView3: UIView!
    @IBOutlet weak var flagView4: UIView!
    
    @IBOutlet weak var flagView5: UIView!
    
    @IBOutlet weak var flagView6: UIView!
    
    @IBOutlet weak var flagView7: UIView!
    
    
    @IBOutlet weak var lab_weekDay2: UILabel!
    @IBOutlet weak var lab_num2: UILabel!
    @IBOutlet weak var lab_day2: UILabel!
    
    @IBOutlet weak var lab_weekDay3: UILabel!
    @IBOutlet weak var lab_num3: UILabel!
    @IBOutlet weak var lab_day3: UILabel!
    
    @IBOutlet weak var lab_weekDay4: UILabel!
    @IBOutlet weak var lab_num4: UILabel!
    @IBOutlet weak var lab_day4: UILabel!
    
    @IBOutlet weak var lab_weekDay5: UILabel!
    @IBOutlet weak var lab_num5: UILabel!
    @IBOutlet weak var lab_day5: UILabel!
    
    @IBOutlet weak var lab_weekDay6: UILabel!
    @IBOutlet weak var lab_num6: UILabel!
    @IBOutlet weak var lab_day6: UILabel!
    
    @IBOutlet weak var lab_weekDay7: UILabel!
    @IBOutlet weak var lab_day7: UILabel!
    @IBOutlet weak var lab_num7: UILabel!
    
    var date1 = ""
    var date2 = ""
    var date3 = ""
    var date4 = ""
    var date5 = ""
    var date6 = ""
    var date7 = ""
    
    var selectedIndex = 2 //默认今天
    var callBack: TCRowCallBack?
    override func awakeFromNib() {
        super.awakeFromNib()
       
        flagView1.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
        flagView2.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
        flagView3.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
        flagView4.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
        flagView5.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
        flagView6.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
        flagView7.makeLayerRadius(value: 2, type:[.layerMaxXMaxYCorner,.layerMinXMaxYCorner,.layerMaxXMinYCorner])
    }

    @IBAction func clickAction(_ sender: UIButton) {
        switch sender.tag {
        case 1:
            callBack?((date1,1))
        case 2:
            callBack?((date2,2))
        case 3:
            callBack?((date3,3))
        case 4:
            callBack?((date4,4))
        case 5:
            callBack?((date5,5))
        case 6:
            callBack?((date6,6))
        case 7:
            callBack?((date7,7))
        default:
            break
        }
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func makeTheFlagWithSelectedIndex(){
        //默认选中今天 = 1
        flagView1.isHidden = true
        flagView2.isHidden = true
        flagView3.isHidden = true
        flagView4.isHidden = true
        flagView5.isHidden = true
        flagView6.isHidden = true
        flagView7.isHidden = true
        
        if selectedIndex == 1{flagView1.isHidden = false}
        if selectedIndex == 2{flagView2.isHidden = false}
        if selectedIndex == 3{flagView3.isHidden = false}
        if selectedIndex == 4{flagView4.isHidden = false}
        if selectedIndex == 5{flagView5.isHidden = false}
        if selectedIndex == 6{flagView6.isHidden = false}
        if selectedIndex == 7{flagView7.isHidden = false}
    }
}


extension Cell_HomeDays: TCCell_RowCellUpdateProtocol {

    typealias DataSource = (HomeModel,Int)
    typealias ConfigModel = TCFormCellConfigModel
    
    func row_update(callBack block: TCRowCallBack?) {
        callBack = block
    }
    
    func row_update(config data: TCFormCellConfigModel) {
    
    }
    
    func row_update(dataSource data: (HomeModel,Int)) {
        let selectedIndex = data.1
        self.selectedIndex = selectedIndex
        self.makeTheFlagWithSelectedIndex()
        
        if data.0.dateList.count>0 {
            for (index,item) in data.0.dateList.enumerated() {
                switch index {
                case 0:
                    lab_weekDay1.text = item.week_dayame
                    lab_num1.text = item.orderqty
//                    lab_day1.text = item.dayame
                    date1 = item.date
                    break
                case 1:
                    lab_weekDay2.text = item.week_dayame
                    lab_num2.text = item.orderqty
                    lab_day2.text = item.dayame
                    date2 = item.date
                    break
                case 2:
                    lab_weekDay3.text = item.week_dayame
                    lab_num3.text = item.orderqty
                    lab_day3.text = item.dayame
                    date3 = item.date
                    break
                case 3:
                    lab_weekDay4.text = item.week_dayame
                    lab_num4.text = item.orderqty
                    lab_day4.text = item.dayame
                    date4 = item.date
                    break
                case 4:
                    lab_weekDay5.text = item.week_dayame
                    lab_num5.text = item.orderqty
                    lab_day5.text = item.dayame
                    date5 = item.date
                    break
                case 5:
                    lab_weekDay6.text = item.week_dayame
                    lab_num6.text = item.orderqty
                    lab_day6.text = item.dayame
                    date6 = item.date
                    break
                case 6:
                    lab_weekDay7.text = item.week_dayame
                    lab_num7.text = item.orderqty
                    lab_day7.text = item.dayame
                    date7 = item.date
                    break
                default:
                    break
                }
            }
            
        }
        
    }
    
}
