//
//  MessageCenterController.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/14.
//

import Foundation
import DDAutoUIKit_Private
import DDControlsKit_Private
import SnapKit
import RxSwift
import MJRefresh

extension MessageCenterController {
    func addActions() {
        messageCenterView.tableView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {
            
        })
    }
}

// MARK: UITableViewDelegate,UITableViewDataSource
extension MessageCenterController : UITableViewDelegate,UITableViewDataSource {
    public func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? MessageCenterCell
        if cell == nil {
            cell = MessageCenterCell(style: .default, reuseIdentifier: "cell")
        }
        
        cell!.descLabel.text = "师傅接单已超6分钟还未发车，请尽快发车备份 2,师傅接单已超6分钟还未发车，请尽快发车备份 2"
        cell!.noticeLabel.text = " 发车提醒 "
        cell!.noticeLabel.backgroundColor = .hex("FA8D14")
        cell!.orderNumLabel.text = "DDA2304142407036"
        cell!.dateLabel.text = TOOL.getDateStringCompareWithNow(dateFormat:"yyyy/MM/dd HH:mm:ss",dateString: "2023/08/13 23:39:42")
        return cell!
    }
}

open class MessageCenterController : DDViewController {
    private let messageCenterView = MessageCenterView()
    open override func viewDidLoad() {
        super.viewDidLoad()
        dd_navigationItemTitle = "消息提醒"
        dd_navigationBarBackgroundColor = .hex("354683")
        dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.white(alpha: 0.7),.font:UIFont.mediumFont(17)]
        
        addSubviews()
        addActions()
    }
    
    func addSubviews() {
        view.backgroundColor = .hex("F4F5F7")
        view.addSubview(messageCenterView)
        messageCenterView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.bottom.equalTo(-view.safeAreaInsets.bottom)
        }
        
        messageCenterView.tableView.delegate = self
        messageCenterView.tableView.dataSource = self
    }
    
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
}

open class MessageCenterView : DDView {
    public let tableView : DDTableView
    public override init(frame: CGRect) {
        tableView = DDTableView(frame: CGRectZero, style: .plain)
        super.init(frame: frame)
        
        tableView.backgroundColor = .hex("F4F5F7")
        tableView.separatorStyle = .none
        addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

open class MessageCenterCell : DDTableViewCell {
    public let radiusView : DDView
    public let noticeLabel : DDLabel
    public let orderNumLabel : DDLabel
    public let dateLabel : DDLabel
    public let descLabel : DDLabel
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        radiusView = DDView()
        noticeLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(10)), textColor: .white)
        orderNumLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(12)), textColor: .hex("000000").alpha(0.55))
        dateLabel = DDLabel.dd_init(withText: "", font: .regularFont(auto(11)), textColor: .hex("000000").alpha(0.55))
        descLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(13)), textColor: .hex("000000").alpha(0.75))
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = .hex("F4F5F7")
        selectionStyle = .none
        
        radiusView.backgroundColor = .white
        radiusView.layer.cornerRadius = auto(6)
        radiusView.layer.shadowColor = UIColor.hex("D8D8D8").cgColor
        radiusView.layer.shadowOffset = CGSize(width: 0, height: 3)
        radiusView.layer.shadowRadius = 5
        radiusView.layer.shadowOpacity = 1
        contentView.addSubview(radiusView)
        noticeLabel.layer.cornerRadius = auto(2)
        noticeLabel.layer.masksToBounds = true
        radiusView.addSubview(noticeLabel)
        radiusView.addSubview(orderNumLabel)
        radiusView.addSubview(dateLabel)
        descLabel.numberOfLines = 0
        radiusView.addSubview(descLabel)
        
        radiusView.snp.makeConstraints { make in
            make.left.top.equalTo(auto(10))
            make.right.equalTo(-auto(10))
            make.bottom.equalTo(0)
        }
        
        noticeLabel.snp.makeConstraints { make in
            make.top.left.equalTo(auto(10))
            make.height.equalTo(auto(15))
        }
        
        orderNumLabel.snp.makeConstraints { make in
            make.left.equalTo(noticeLabel.snp.right).offset(auto(10))
            make.centerY.equalTo(noticeLabel)
        }
        
        dateLabel.snp.makeConstraints { make in
            make.right.equalTo(-auto(10))
            make.centerY.equalTo(noticeLabel)
        }
        
        descLabel.snp.makeConstraints { make in
            make.top.equalTo(noticeLabel.snp.bottom).offset(auto(10))
            make.left.equalTo(noticeLabel)
            make.right.equalTo(dateLabel)
            make.bottom.equalTo(-auto(15))
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
