// // PaginationCellItem.swift // VDS // // Created by Bandaru, Krishna Kishore on 05/03/24. // import UIKit import VDSCoreTokens ///This is customised view for Pagination cell item final class PaginationCellItem: UICollectionViewCell { ///Identifier for the PaginationCellItem static let identifier: String = String(describing: PaginationCellItem.self) //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- ///Text color configuration for the element private let textColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark) ///Pagination index label private var indexLabel: Label = Label().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.textAlignment = .center $0.isAccessibilityElement = false $0.numberOfLines = 1 } //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- override init(frame: CGRect) { super.init(frame: frame) setUp() } required init?(coder: NSCoder) { super.init(coder: coder) setUp() } ///Configuring the cell with default setup private func setUp() { let containerView = View() containerView.translatesAutoresizingMaskIntoConstraints = false containerView.addSubview(indexLabel) contentView.addSubview(containerView) containerView.pinToSuperView() indexLabel.pinToSuperView() indexLabel.widthGreaterThanEqualTo(VDSLayout.space5X) contentView.backgroundColor = .clear containerView.backgroundColor = .clear indexLabel.backgroundColor = .clear } ///Updating UI based on selected index, current index along with surface func update(_ selectedIndex: Int, currentIndex: Int, surface: Surface) { indexLabel.textStyle = selectedIndex == currentIndex ? .boldBodySmall : .bodySmall indexLabel.text = "\(currentIndex + 1)" indexLabel.textColor = textColorConfiguration.getColor(surface) } }