<commit_before>import UIKit

protocol CollectionViewHeaderDelegate: class {
    func collectionViewHeaderButtonWasPressed(_ collectionViewHeader: CollectionViewHeader)
}

class CollectionViewHeader: SizeThatFitsReusableView {
    weak var delegate: CollectionViewHeaderDelegate?
    
    public enum Style {
        case explore
        case detail
        case history
        case recentSearches
        case pageHistory
    }
    
    public var style: Style = .explore {
        didSet {
            updateFonts(with: traitCollection)
        }
    }

    private let titleLabel: UILabel = UILabel()
    private let subtitleLabel: UILabel = UILabel()
    private let button: UIButton = UIButton()
    private let spacing: CGFloat = 5
    
    var title: String? {
        get {
            return titleLabel.text
        }
        set {
            titleLabel.text = newValue
            setNeedsLayout()
        }
    }

    var titleTextColorKeyPath: KeyPath<Theme, UIColor> = \Theme.colors.primaryText
    
    var subtitle: String? {
        get {
            return subtitleLabel.text
        }
        set {
            subtitleLabel.text = newValue
            subtitleLabel.isHidden = subtitleLabel.text == nil
            setNeedsLayout()
        }
    }
    
    var buttonTitle: String? {
        get {
            return button.title(for: .normal)
        }
        set {
            button.setTitle(newValue, for: .normal)
            button.isHidden = newValue == nil
        }
    }

    override func setup() {
        super.setup()
        addSubview(button)
        addSubview(subtitleLabel)
        addSubview(titleLabel)
        button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside)
        button.isHidden = true
    }
    
    @objc func buttonPressed(_ sender: UIButton?) {
        delegate?.collectionViewHeaderButtonWasPressed(self)
    }
    
    override func updateFonts(with traitCollection: UITraitCollection) {
        super.updateFonts(with: traitCollection)
        let titleTextStyle: DynamicTextStyle
        let subtitleTextStyle: DynamicTextStyle = .subheadline
        let buttonTextStyle: DynamicTextStyle = .subheadline
        switch style {
        case .detail:
            fallthrough
        case .explore:
            titleTextStyle = .boldTitle2
        case .pageHistory:
            titleTextStyle = .semiboldSubheadline
        default:
            titleTextStyle = .semiboldHeadline
        }
        titleLabel.font = UIFont.wmf_font(titleTextStyle, compatibleWithTraitCollection: traitCollection)
        subtitleLabel.font = UIFont.wmf_font(subtitleTextStyle, compatibleWithTraitCollection: traitCollection)
        button.titleLabel?.font = UIFont.wmf_font(buttonTextStyle, compatibleWithTraitCollection: traitCollection)
    }
    
    override func sizeThatFits(_ size: CGSize, apply: Bool) -> CGSize {
        let additionalMargins: UIEdgeInsets
        switch style {
        case .history:
            additionalMargins = UIEdgeInsets(top: 30, left: 0, bottom: 10, right: 0)
        case .recentSearches:
            additionalMargins = UIEdgeInsets(top: 10, left: 0, bottom: 5, right: 0)
        case .detail:
            additionalMargins = UIEdgeInsets(top: 45, left: 0, bottom: 35, right: 0)
        case .pageHistory:
            additionalMargins = UIEdgeInsets(top: 10, left: 6, bottom: 30, right: 6)
        default:
            additionalMargins = .zero
        }<commit_msg>don't define another titleTextStyle for the .pageHistory case in CollectionViewHeader<commit_after>import UIKit

protocol CollectionViewHeaderDelegate: class {
    func collectionViewHeaderButtonWasPressed(_ collectionViewHeader: CollectionViewHeader)
}

class CollectionViewHeader: SizeThatFitsReusableView {
    weak var delegate: CollectionViewHeaderDelegate?
    
    public enum Style {
        case explore
        case detail
        case history
        case recentSearches
        case pageHistory
    }
    
    public var style: Style = .explore {
        didSet {
            updateFonts(with: traitCollection)
        }
    }

    private let titleLabel: UILabel = UILabel()
    private let subtitleLabel: UILabel = UILabel()
    private let button: UIButton = UIButton()
    private let spacing: CGFloat = 5
    
    var title: String? {
        get {
            return titleLabel.text
        }
        set {
            titleLabel.text = newValue
            setNeedsLayout()
        }
    }

    var titleTextColorKeyPath: KeyPath<Theme, UIColor> = \Theme.colors.primaryText
    
    var subtitle: String? {
        get {
            return subtitleLabel.text
        }
        set {
            subtitleLabel.text = newValue
            subtitleLabel.isHidden = subtitleLabel.text == nil
            setNeedsLayout()
        }
    }
    
    var buttonTitle: String? {
        get {
            return button.title(for: .normal)
        }
        set {
            button.setTitle(newValue, for: .normal)
            button.isHidden = newValue == nil
        }
    }

    override func setup() {
        super.setup()
        addSubview(button)
        addSubview(subtitleLabel)
        addSubview(titleLabel)
        button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside)
        button.isHidden = true
    }
    
    @objc func buttonPressed(_ sender: UIButton?) {
        delegate?.collectionViewHeaderButtonWasPressed(self)
    }
    
    override func updateFonts(with traitCollection: UITraitCollection) {
        super.updateFonts(with: traitCollection)
        let titleTextStyle: DynamicTextStyle
        let subtitleTextStyle: DynamicTextStyle = .subheadline
        let buttonTextStyle: DynamicTextStyle = .subheadline
        switch style {
        case .detail:
            fallthrough
        case .explore:
            titleTextStyle = .boldTitle2
        default:
            titleTextStyle = .semiboldHeadline
        }
        titleLabel.font = UIFont.wmf_font(titleTextStyle, compatibleWithTraitCollection: traitCollection)
        subtitleLabel.font = UIFont.wmf_font(subtitleTextStyle, compatibleWithTraitCollection: traitCollection)
        button.titleLabel?.font = UIFont.wmf_font(buttonTextStyle, compatibleWithTraitCollection: traitCollection)
    }
    
    override func sizeThatFits(_ size: CGSize, apply: Bool) -> CGSize {
        let additionalMargins: UIEdgeInsets
        switch style {
        case .history:
            additionalMargins = UIEdgeInsets(top: 30, left: 0, bottom: 10, right: 0)
        case .recentSearches:
            additionalMargins = UIEdgeInsets(top: 10, left: 0, bottom: 5, right: 0)
        case .detail:
            additionalMargins = UIEdgeInsets(top: 45, left: 0, bottom: 35, right: 0)
        case .pageHistory:
            additionalMargins = UIEdgeInsets(top: 10, left: 6, bottom: 30, right: 6)
        default:
            additionalMargins = .zero
        }
{'fraction_non_alphanumeric': 0.07370087807686772, 'fraction_numerical': 0.007197351374694113, 'mean_word_length': 2.216666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5757160', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1887, 'n_words': 455}