<commit_before>//
//  AccordionTableViewController.swift
//  Example
//
//  Created by <NAME> on 7/5/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit
import AccordionSwift

class AccordionTableViewController: UITableViewController {
    
    // MARK: - Typealias
    
    typealias ParentCellModel = Parent<GroupCellModel, CountryCellModel>
    typealias ParentCellConfig = CellViewConfig<ParentCellModel, UITableViewCell>
    typealias ChildCellConfig = CellViewConfig<CountryCellModel, CountryTableViewCell>
    
    // MARK: - Properties
    
    /// The Data Source Provider with the type of DataSource and the different models for the Parent and Child cell.
    var dataSourceProvider: DataSourceProvider<DataSource<ParentCellModel>, ParentCellConfig, ChildCellConfig>?
    
    // MARK: - UIViewController
    
    override func viewDidLoad() {
        super.viewDidLoad()
        configDataSource()
        navigationItem.title = "World Cup 2018"
    }
}

extension AccordionTableViewController {
    
    // MARK: - Methods
    
    /// Configure the data source
    private func configDataSource() {
        
        let groupA = Parent(state: .collapsed, item: GroupCellModel(name: "Group A"),
                            children: [CountryCellModel(name: "Uruguay"),
                                     CountryCellModel(name: "Russia"),
                                     CountryCellModel(name: "Saudi Arabia"),
                                     CountryCellModel(name: "Egypt")]
        )
        
        let groupB = Parent(state: .expanded, item: GroupCellModel(name: "Group B"),
                            children: [CountryCellModel(name: "Spain"),
                                     CountryCellModel(name: "Portugal"),
                                     CountryCellModel(name: "Iran"),
                                     CountryCellModel(name: "Morocco")]
        )
        
        let groupC = Parent(state: .expanded, item: GroupCellModel(name: "Group C"),
                            children: [CountryCellModel(name: "France"),
                                     CountryCellModel(name: "Denmark"),
                                     CountryCellModel(name: "Peru"),
                                     CountryCellModel(name: "Australia")]
        )
        
        let groupD = Parent(state: .expanded, item: GroupCellModel(name: "Group D"),
                            children: [CountryCellModel(name: "Croatia"),
                                     CountryCellModel(name: "Argentina"),
                                     CountryCellModel(name: "Nigeria"),
                                     CountryCellModel(name: "Iceland")]
        )
        
        let groupE = Parent(state: .collapsed, item: GroupCellModel(name: "Group E"),
                            children: [CountryCellModel(name: "Brazil"),
                                     CountryCellModel(name: "Switzerland"),
                                     CountryCellModel(name: "Serbia"),
                                     CountryCellModel(name: "Costa Rica")]
        )
        
        let groupF = Parent(state: .collapsed, item: GroupCellModel(name: "Group F"),
                            children: [CountryCellModel(name: "Sweden"),
                                     CountryCellModel(name: "Mexico"),
                                     CountryCellModel(name: "South Korea"),
                                     CountryCellModel(name: "Germany")]
        )
        
        let groupG = Parent(state: .collapsed, item: GroupCellModel(name: "Group G"),
                            children: [CountryCellModel(name: "Belgium"),
                                     CountryCellModel(name: "England"),
                                     CountryCellModel(name: "Tunisia"),
                                     CountryCellModel(name: "Panama")]
        )
        
        let groupH = Parent(state: .collapsed, item: GroupCellModel(name: "Group H"),
                            children: [CountryCellModel(name: "Colombia"),
                                     CountryCellModel(name: "Japan"),
                                     CountryCellModel(name: "Senegal"),
                                     CountryCellModel(name: "Poland")]
        )
        
        let section0 = Section([groupA, groupB, groupC, groupD, groupE, groupF, groupG, groupH], headerTitle: nil)
        let dataSource = DataSource(sections: section0)
        
        let parentCellConfig = CellViewConfig<Parent<GroupCellModel, CountryCellModel>, UITableViewCell>(
        reuseIdentifier: "GroupCell") { (cell, model, tableView, indexPath) -> UITableViewCell in
            cell.textLabel?.text = model?.item.name
            return cell
        }
        
        let childCellConfig = CellViewConfig<CountryCellModel, CountryTableViewCell>(
        reuseIdentifier: "CountryCell") { (cell, item, tableView, indexPath) -> CountryTableViewCell in
            cell.contryLabel.text = item?.name
            cell.countryImageView.image = UIImage(named: "\(item!.name.lowercased())")
            return cell
        }
        
        let didSelectParentCell = { (tableView: UITableView, indexPath: IndexPath, item: ParentCellModel?) -> Void in
            print("Parent cell \(item!.item.name) tapped")
        }
        
        let didSelectChildCell = { (tableView: UITableView, indexPath: IndexPath, item: CountryCellModel?) -> Void in
            print("Child cell \(item!.name) tapped")
        }
        
        let scrollViewDidScroll = { (scrollView: UIScrollView) -> Void in
            print(scrollView.contentOffset)
            
        }
        
        dataSourceProvider = DataSourceProvider(
            dataSource: dataSource,
            parentCellConfig: parentCellConfig,
            childCellConfig: childCellConfig,
            didSelectParentAtIndexPath: didSelectParentCell,
            didSelectChildAtIndexPath: didSelectChildCell,
            scrollViewDidScroll: scrollViewDidScroll
        )
        <commit_msg>Updated Example to include only one parent expanded at a time<commit_after>//
//  AccordionTableViewController.swift
//  Example: AccordionTableViewController + Only one parent expanded at a time
//
//  Created by <NAME> on 7/5/18.
//  Updated by <NAME> on 15/10/19.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit
import AccordionSwift

class AccordionTableViewController: UITableViewController {

    // MARK: - Typealias

    typealias ParentCellModel = Parent<GroupCellModel, CountryCellModel>
    typealias ParentCellConfig = CellViewConfig<ParentCellModel, UITableViewCell>
    typealias ChildCellConfig = CellViewConfig<CountryCellModel, CountryTableViewCell>

    // MARK: - Properties

    /// The Data Source Provider with the type of DataSource and the different models for the Parent and Child cell.
    var dataSourceProvider: DataSourceProvider<DataSource<ParentCellModel>, ParentCellConfig, ChildCellConfig>?

    // MARK: - UIViewController

    override func viewDidLoad() {
        super.viewDidLoad()
        configDataSource()
        navigationItem.title = "World Cup 2018"
    }
}

extension AccordionTableViewController {

    // MARK: - Methods

    /// Configure the data source
    private func configDataSource() {

        let groupA = Parent(state: .collapsed, item: GroupCellModel(name: "Group A"),
                children: [CountryCellModel(name: "Uruguay"),
                           CountryCellModel(name: "Russia"),
                           CountryCellModel(name: "Saudi Arabia"),
                           CountryCellModel(name: "Egypt")]
        )

        let groupB = Parent(state: .collapsed, item: GroupCellModel(name: "Group B"),
                children: [CountryCellModel(name: "Spain"),
                           CountryCellModel(name: "Portugal"),
                           CountryCellModel(name: "Iran"),
                           CountryCellModel(name: "Morocco")]
        )

        let groupC = Parent(state: .collapsed, item: GroupCellModel(name: "Group C"),
                children: [CountryCellModel(name: "France"),
                           CountryCellModel(name: "Denmark"),
                           CountryCellModel(name: "Peru"),
                           CountryCellModel(name: "Australia")]
        )

        let groupD = Parent(state: .collapsed, item: GroupCellModel(name: "Group D"),
                children: [CountryCellModel(name: "Croatia"),
                           CountryCellModel(name: "Argentina"),
                           CountryCellModel(name: "Nigeria"),
                           CountryCellModel(name: "Iceland")]
        )

        let groupE = Parent(state: .collapsed, item: GroupCellModel(name: "Group E"),
                children: [CountryCellModel(name: "Brazil"),
                           CountryCellModel(name: "Switzerland"),
                           CountryCellModel(name: "Serbia"),
                           CountryCellModel(name: "Costa Rica")]
        )

        let groupF = Parent(state: .collapsed, item: GroupCellModel(name: "Group F"),
                children: [CountryCellModel(name: "Sweden"),
                           CountryCellModel(name: "Mexico"),
                           CountryCellModel(name: "South Korea"),
                           CountryCellModel(name: "Germany")]
        )

        let groupG = Parent(state: .collapsed, item: GroupCellModel(name: "Group G"),
                children: [CountryCellModel(name: "Belgium"),
                           CountryCellModel(name: "England"),
                           CountryCellModel(name: "Tunisia"),
                           CountryCellModel(name: "Panama")]
        )

        let groupH = Parent(state: .collapsed, item: GroupCellModel(name: "Group H"),
                children: [CountryCellModel(name: "Colombia"),
                           CountryCellModel(name: "Japan"),
                           CountryCellModel(name: "Senegal"),
                           CountryCellModel(name: "Poland")]
        )

        let section0 = Section([groupA, groupB, groupC, groupD, groupE, groupF, groupG, groupH], headerTitle: nil)
        let dataSource = DataSource(sections: section0)

        let parentCellConfig = CellViewConfig<Parent<GroupCellModel, CountryCellModel>, UITableViewCell>(
                reuseIdentifier: "GroupCell") { (cell, model, tableView, indexPath) -> UITableViewCell in
            cell.textLabel?.text = model?.item.name
            return cell
        }

        let childCellConfig = CellViewConfig<CountryCellModel, CountryTableViewCell>(
                reuseIdentifier: "CountryCell") { (cell, item, tableView, indexPath) -> CountryTableViewCell in
            cell.contryLabel.text = item?.name
            cell.countryImageView.image = UIImage(named: "\(item!.name.lowercased())")
            return cell
        }

        let didSelectParentCell = { (tableView: UITableView, indexPath: IndexPath, item: ParentCellModel?) -> Void in
            print("Parent cell \(item!.item.name) tapped")
        }

        let didSelectChildCell = { (tableView: UITableView, indexPath: IndexPath, item: CountryCellModel?) -> Void in
            print("Child cell \(item!.name) tapped")
        }

        let scrollViewDidScroll = { (scrollView: UIScrollView) -> Void in
            print(scrollView.contentOffset)

        }

        dataSourceProvider = DataSourceProvider(
                dataSource: dataSource,
                parentCellConfig: parentCellConfig,
                childCellConfig: childCellConfig,
                didSelectParentAtIndexPath: didSelectParentCell,
                didSelectChildAtIndexPath: didSelectChildCell,
                scrollViewDidScroll: scrollViewDidScroll,
                // Configure DataSourceProvider to have only one parent expanded at a time
                numberExpandedParentCells: .single
        )

{'fraction_non_alphanumeric': 0.09452902794043835, 'fraction_numerical': 0.002844236238915844, 'mean_word_length': 1.864845434938893, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519095', 'n_tokens_mistral': 3077, 'n_tokens_neox': 2866, 'n_words': 684}