 
 import UIKit
 
+public typealias Position = (row: Int, column: Int)
+
 public protocol NumPadDataSource: class {
     
     func numberOfRowsInNumberPad(numPad: NumPad) -> Int
     func numPad(numPad: NumPad, numberOfColumnsInRow row: Int) -> Int
+    func numPad(numPad: NumPad, titleForButtonAtPosition position: Position) -> String
     
 }
 

    
}



// MARK: - CollectionViewCell
class CollectionViewCell: UICollectionViewCell, ReusableView {

extension NumPad: UICollectionViewDataSource {
    
    public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return (0..<numberOfRows()).map { numberOfColumnsInRow($0) }.reduce(0, combine: +)
    }
    
    public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell: CollectionViewCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
        
        let position = positionForIndexPath(indexPath)
        
        let title = delegate?.numPad(self, titleForButtonAtPosition: position)
        cell.button.setTitle(title, forState: .Normal)
        
        return cell
    }
