<commit_before>//
//  ALSectionElementHeader.swift
//  ALTableView
//
//  Created by <NAME> on 26/3/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit

extension ALSectionElement {
    
    //MARK: - Getters
    
    internal func getHeaderFrom(tableView: UITableView) -> UIView? {
        
        guard let viewHeader = self.headerElement?.getViewFrom(tableView: tableView) else {
            return nil
        }
        self.setUpHeaderRecognizer(viewHeader: viewHeader)
        return viewHeader
    }
    
    internal func getHeaderElement() -> ALHeaderFooterElement? {
        
        return self.headerElement
    }
    
    internal func getHeaderHeight() -> CGFloat {
        
        return self.headerElement?.getHeight() ?? 0.0
    }
    
    internal func getHeaderEstimatedHeight() -> CGFloat {
        
        return self.headerElement?.getEstimatedHeight() ?? 0.0
    }
    
}

//MARK: - Managing the opening and close of section

extension ALSectionElement {
    
    fileprivate func setUpHeaderRecognizer (viewHeader: UIView) -> Void {
        
        if self.headerTapGesture == nil {
            self.headerTapGesture = UITapGestureRecognizer(target: self, action: #selector(self.toggleOpen(sender:)))
            if let headerTapGesture = self.headerTapGesture {
                viewHeader.isUserInteractionEnabled = true
                viewHeader.addGestureRecognizer(headerTapGesture)
            }
        }
    }
    
    @objc fileprivate func toggleOpen(sender: Any) {
        
        if self.isExpandable {
            self.toggleOpenWith(userAction: true)
        }
    }
    
    fileprivate func toggleOpenWith(userAction: Bool) {
        
        guard let delegate = self.delegate else {
            return
        }
        self.isOpened = !self.isOpened
        if userAction {
            if self.isOpened {
                delegate.sectionOpened(sectionElement: self)
            } else {
                delegate.sectionClosed(sectionElement: self)
            }
        }
    }
    <commit_msg>fixed an error with taprecognizer and reuse of header views<commit_after>//
//  ALSectionElementHeader.swift
//  ALTableView
//
//  Created by <NAME> on 26/3/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import UIKit

extension ALSectionElement {
    
    //MARK: - Getters
    
    internal func getHeaderFrom(tableView: UITableView) -> UIView? {
        
        guard let viewHeader = self.headerElement?.getViewFrom(tableView: tableView) else {
            return nil
        }
        self.setUpHeaderRecognizer(viewHeader: viewHeader)
        return viewHeader
    }
    
    internal func getHeaderElement() -> ALHeaderFooterElement? {
        
        return self.headerElement
    }
    
    internal func getHeaderHeight() -> CGFloat {
        
        return self.headerElement?.getHeight() ?? 0.0
    }
    
    internal func getHeaderEstimatedHeight() -> CGFloat {
        
        return self.headerElement?.getEstimatedHeight() ?? 0.0
    }
    
}

//MARK: - Managing the opening and close of section

extension ALSectionElement {
    
    fileprivate func setUpHeaderRecognizer (viewHeader: UIView) -> Void {
        if let headerTapGesture = self.headerTapGesture {
            viewHeader.removeGestureRecognizer(headerTapGesture)
            self.headerTapGesture = nil
        }
        if self.headerTapGesture == nil {
            self.headerTapGesture = UITapGestureRecognizer(target: self, action: #selector(self.toggleOpen(sender:)))
            if let headerTapGesture = self.headerTapGesture {
                viewHeader.isUserInteractionEnabled = true
                viewHeader.addGestureRecognizer(headerTapGesture)
            }
        }
    }
    
    @objc fileprivate func toggleOpen(sender: Any) {
        
        if self.isExpandable {
            self.toggleOpenWith(userAction: true)
        }
    }
    
    fileprivate func toggleOpenWith(userAction: Bool) {
        
        guard let delegate = self.delegate else {
            return
        }
        self.isOpened = !self.isOpened
        if userAction {
            if self.isOpened {
                delegate.sectionOpened(sectionElement: self)
            } else {
                delegate.sectionClosed(sectionElement: self)
            }
        }
    }
    
{'fraction_non_alphanumeric': 0.08148661126500462, 'fraction_numerical': 0.006001846722068329, 'mean_word_length': 1.9416157501697218, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1379546', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1188, 'n_words': 254}