//
//  Component.swift
//  ClockWidget
//
//  Created by TSYH on 2023/10/7.
//

import UIKit

public protocol Component {}

public protocol ComponentView {
    // UI 渲染
    func renderView(with object: Any?, component: CollectionViewComponent, attributes: [String: Any]?)
}

public protocol CollectionViewSectionComponent: Component {
    var cells: [CollectionViewCellComponent] { get }
    var headerComponent: CollectionViewReuseViewComponent? { get }
    var footerComponent: CollectionViewReuseViewComponent? { get }
    var sectionInset: UIEdgeInsets { get }
    var lineSpacing: CGFloat { get }
    var itemSpacing: CGFloat { get }
}

extension CollectionViewSectionComponent {
    var headerComponent: CollectionViewReuseViewComponent? { return nil }
    var footerComponent: CollectionViewReuseViewComponent? { return nil }
    
    var sectionInset: UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
    }
    
    var lineSpacing: CGFloat {
        return 12.0
    }
    
    var itemSpacing: CGFloat {
        return 12.0
    }
}

public enum CollectionViewReuseViewType {
    case header
    case footer
}

public protocol CollectionViewReuseViewComponent: Component {
    var viewClass: UICollectionReusableView.Type { get }
    var viewType: CollectionViewReuseViewType { get }
    var viewSize: CGSize { get }
    var reuseIdentifier: String { get }
}

extension CollectionViewReuseViewComponent {
    var reuseIdentifier: String{
        return viewClass.description()
    }
}

public protocol CollectionViewCellComponent: Component {
    var cellClass: UICollectionViewCell.Type { get }
    func cellSize(with attrubites: [String: Any]?) -> CGSize
}
