//
//  AV_WaterCell.swift
//  anniversary_Project
//
//  Created by 忆海16 on 2024/7/4.
//

import UIKit

class AV_WaterCell: UITableViewCell {
    @IBOutlet weak var drinkb: UILabel!
    
    @IBOutlet weak var drinkMLLabel: UILabel!
    
    
    @IBOutlet weak var waveView: AV_WaveView!
    
    @IBOutlet weak var collectionView: UICollectionView!

    @IBOutlet weak var bgview: UIView!
    
    
    
    
    let cellWidth: CGFloat = 76
    let cellHeight: CGFloat = 114
    let cellSpacing: CGFloat = 12
    
    let dataimag = ["wateredit","addwater", "milk", "tea", "milkyTea", "beer","redwine","fruitjuice","soup"]
    let drinkml = ["0ml","250ml", "300ml", "300ml", "200ml", "350ml","150ml","200ml","250ml"]
    
    var birtherBlock:(()->())?
    var setingBlock:(()->())?
    
    var blockedit:(()->())?
    var block250:(()->())?
    var block300:(()->())?
    var block200:(()->())?
    var block150:(()->())?
    var block350:(()->())?
    
//    var ql:(()->())?
    override func awakeFromNib() {
        super.awakeFromNib()
        setcollectionV()


    }
    
    func setcollectionV(){
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.collectionViewLayout = layout
        collectionView.register(UINib(nibName: "AV_AddWaterCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "AV_AddWaterCollectionViewCell")
    }
    
    
    @IBAction func birtherBtn(_ sender: Any) {
        if self.birtherBlock != nil{
            self.birtherBlock!()
        }
        
    }
    
    @IBAction func settingBtn(_ sender: Any) {
        
        if self.setingBlock != nil{
            self.setingBlock!()
        }
    }
    
//    @IBAction func ql(_ sender: Any) {
//        if self.ql != nil{
//            self.ql!()
//        }
//        
//    }
    
    
}
extension AV_WaterCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataimag.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AV_AddWaterCollectionViewCell", for: indexPath) as! AV_AddWaterCollectionViewCell
        cell.bgImageV.image = UIImage(named: "\(self.dataimag[indexPath.row])")
        cell.nameLabel.text = self.drinkml[indexPath.row]
        return cell
        
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: cellWidth, height: cellHeight)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return cellSpacing
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: cellSpacing, bottom: 0, right: cellSpacing)
    }
    
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0 {
           
            if self.blockedit != nil{
                self.blockedit!()
            }

        }else if indexPath.row == 1 || indexPath.row == 8{
            //250ml
            if self.block250 != nil{
                self.block250!()
            }
        }else if indexPath.row == 2 || indexPath.row == 3{
            //300ml
            if self.block300 != nil{
                self.block300!()
            }
        }else if indexPath.row == 4 || indexPath.row == 7{
            //200ml
            if self.block200 != nil{
                self.block200!()
            }
        }else if indexPath.row == 5{
            //350ml
            if self.block350 != nil{
                self.block350!()
            }
        }else{
            //150ml
            if self.block150 != nil{
                self.block150!()
            }
        }

    }
    
}
