//
//  CommonSectionComponent.swift
//  ClockWidget
//
//  Created by TSYH on 2023/10/17.
//

import UIKit

class CommonSectionComponent: CollectionViewSectionComponent {
    var cellComponents: [CollectionViewCellComponent]
    var header: CollectionViewReuseViewComponent?
    var footer: CollectionViewReuseViewComponent?
    var inset: UIEdgeInsets
    var rowSpacing: CGFloat
    var columnSpacing: CGFloat
    
    init(cellComponents: [CollectionViewCellComponent],
         header: CollectionViewReuseViewComponent? = nil,
         footer: CollectionViewReuseViewComponent? = nil,
         inset: UIEdgeInsets = .zero,
         rowSpacing: CGFloat = 10.0,
         columnSpacing: CGFloat = 10.0) {
        self.cellComponents = cellComponents
        self.header = header
        self.footer = footer
        self.inset = inset
        self.rowSpacing = rowSpacing
        self.columnSpacing = columnSpacing
    }
    
    var cells: [CollectionViewCellComponent] {
        return cellComponents
    }
    
    var headerComponent: CollectionViewReuseViewComponent? {
        return header
    }
    
    var footerComponent: CollectionViewReuseViewComponent? {
        return footer
    }
    
    func clear() {
        cellComponents.removeAll()
    }
    
    func append(_ cellComponents: [CollectionViewCellComponent]) {
        self.cellComponents.append(contentsOf: cellComponents)
    }
   
    var sectionInset: UIEdgeInsets {
        return inset
    }
    
    var lineSpacing: CGFloat {
        return rowSpacing
    }
    
    var itemSpacing: CGFloat {
        return columnSpacing
    }
}
