<commit_before>//
//  AlertDataSource.swift
//  Example
//
//  Created by <NAME> on 24/10/2019.
//  Copyright © 2019 Xcore. All rights reserved.
//

import Foundation

final class AlertDataSource: XCCollectionViewDataSource {
    var alerts: [String]
    var identifier: String

    var isExtended: Bool = false {
        didSet {
            if isExtended != oldValue {
                let reloadSet = IndexSet(integersIn: globalSection...(globalSection + allSectionsCount - 1))
                collectionView?.performBatchUpdates({
                    collectionView?.reloadSections(reloadSet)
                })
            }
        }
    }

    private var allSectionsCount: Int {
        return 1 + 1 + alerts.count
    }

    init(collectionView: UICollectionView, alerts: [String], identifier: String) {
        self.alerts = alerts
        self.identifier = identifier
        super.init(collectionView: collectionView)
    }

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        return allSectionsCount
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        switch section {
            case 2:
                return isExtended ? 0 : 1
            case 1:
                return 1
            default:
                return isExtended ? 1 : 0
        }
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let globalIndex = indexPath.with(globalSection)
        switch indexPath.section {
            case 0:
                let cell = collectionView.dequeueReusableCell(for: globalIndex) as HeaderCell
                cell.configure(didTapHide: { [weak self] in
                    self?.isExtended = false
                }, didTapClear: {
                    
                })
                return cell
            case 2:
                let cell = collectionView.dequeueReusableCell(for: globalIndex) as StackEffect
                cell.configure(isTwoOrMore: alerts.count >= 3)
                return cell
            default:
                let cell = collectionView.dequeueReusableCell(for: globalIndex) as FeedTextViewCell
                let index = alertIndexFor(section: indexPath.section)
                cell.configure(
                    title: "Alert Number: \(index)",
                    subtitle: alerts.at(index) ?? ""
                )
                return cell
        }
    }

    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {<commit_msg>Added demostration headers to the Alerts DataSource<commit_after>//
//  AlertDataSource.swift
//  Example
//
//  Created by <NAME> on 24/10/2019.
//  Copyright © 2019 Xcore. All rights reserved.
//

import Foundation

final class AlertDataSource: XCCollectionViewDataSource {
    var alerts: [String]
    var identifier: String

    var isExtended: Bool = false {
        didSet {
            if isExtended != oldValue {
                let reloadSet = IndexSet(integersIn: globalSection...(globalSection + allSectionsCount - 1))
                collectionView?.performBatchUpdates({
                    collectionView?.reloadSections(reloadSet)
                })
            }
        }
    }

    private var allSectionsCount: Int {
        return 1 + 1 + alerts.count
    }

    init(collectionView: UICollectionView, alerts: [String], identifier: String) {
        self.alerts = alerts
        self.identifier = identifier
        super.init(collectionView: collectionView)
    }

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        return allSectionsCount
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        switch section {
            case 2:
                return isExtended ? 0 : 1
            case 1:
                return 1
            default:
                return isExtended ? 1 : 0
        }
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let globalIndex = indexPath.with(globalSection)
        switch indexPath.section {
            case 0:
                let cell = collectionView.dequeueReusableCell(for: globalIndex) as HeaderCell
                cell.configure(didTapHide: { [weak self] in
                    self?.isExtended = false
                }, didTapClear: {
                    
                })
                return cell
            case 2:
                let cell = collectionView.dequeueReusableCell(for: globalIndex) as StackEffect
                cell.configure(isTwoOrMore: alerts.count >= 3)
                return cell
            default:
                let cell = collectionView.dequeueReusableCell(for: globalIndex) as FeedTextViewCell
                let index = alertIndexFor(section: indexPath.section)
                cell.configure(
                    title: "Alert Number: \(index)",
                    subtitle: alerts.at(index) ?? ""
                )
                return cell
        }
    }

    override func collectionView(_ collectionView: UICollectionView, headerAttributesForSectionAt section: Int) -> (enabled: Bool, size: CGSize?) {
        switch section {
            case 0, 2:
                return (false, nil)
            case 1:
                return (true, nil)
            default:
                return  (isExtended, nil)
        }
    }

    override func collectionView(_ collectionView: UICollectionView, viewForHeaderInSectionAt indexPath: IndexPath) -> UICollectionReusableView? {
        let globalIndexPath = indexPath.with(globalSection)
        let header = collectionView.dequeueReusableSupplementaryView(.header, for: globalIndexPath) as FeedTextHeaderFooterViewCell
        header.configure(title: "S: \(alertIndexFor(section: indexPath.section))")
        return header
    }

    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
{'fraction_non_alphanumeric': 0.07535807291666667, 'fraction_numerical': 0.008626302083333334, 'mean_word_length': 1.9040642722117203, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3020037', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1495, 'n_words': 398}