<commit_before>/*
 Copyright © 23/04/2016 Shaps
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */

import UIKit

internal final class CustomSegment: NSObject {
    
    override var description: String {
        return title ?? ""
    }
    
    @objc var enabled: Bool = false
    @objc var title: String?
    @objc var width: CGFloat = 0
    @objc var image: UIImage?
    @objc var contentOffset: CGSize = CGSize.zero
    
    internal override var isLeaf: Bool { return false }
    
    override func preparePeek(with coordinator: Coordinator) {
        if let image = image {
            coordinator.appendPreview(image: image, forModel: self)
        }
        
        coordinator.appendDynamic(keyPaths: [
            "title", "image"
        ], forModel: self, in: .appearance)
        
        coordinator.appendDynamic(keyPaths: [
            "contentOffset", "width"
        ], forModel: self, in: .layout)
        
        coordinator.appendDynamic(keyPaths: [
            "enabled"
        ], forModel: self, in: .states)
        
        super.preparePeek(with: coordinator)
    }
    
}

extension UISegmentedControl {
    
    var segments: [CustomSegment]? {
        var segments = [CustomSegment]()
        
        for index in 0..<numberOfSegments {
            let segment = CustomSegment()
            segment.enabled = isEnabledForSegment(at: index)
            segment.title = titleForSegment(at: index)
            segment.width = widthForSegment(at: index)
            segment.contentOffset = contentOffsetForSegment(at: index)
            segment.image = imageForSegment(at: index)
            segments.append(segment)
        }
        
        return segments
    }
    
    open override func preparePeek(with coordinator: Coordinator) {
        for target in self.allTargets {
            for action in self.actions(forTarget: target, forControlEvent: .valueChanged) ?? [] {
                var detail: String = ""<commit_msg>CustomSegment renamed to SegmentItem<commit_after>/*
 Copyright © 23/04/2016 Shaps
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */

import UIKit

internal final class SegmentItem: NSObject {
    
    override var description: String {
        return title ?? ""
    }
    
    @objc var enabled: Bool = false
    @objc var title: String?
    @objc var width: CGFloat = 0
    @objc var image: UIImage?
    @objc var contentOffset: CGSize = CGSize.zero
    
    internal override var isLeaf: Bool { return false }
    
    override func preparePeek(with coordinator: Coordinator) {
        if let image = image {
            coordinator.appendPreview(image: image, forModel: self)
        }
        
        coordinator.appendDynamic(keyPaths: [
            "title", "image"
        ], forModel: self, in: .appearance)
        
        coordinator.appendDynamic(keyPaths: [
            "contentOffset", "width"
        ], forModel: self, in: .layout)
        
        coordinator.appendDynamic(keyPaths: [
            "enabled"
        ], forModel: self, in: .states)
        
        super.preparePeek(with: coordinator)
    }
    
}

extension UISegmentedControl {
    
    var segments: [SegmentItem]? {
        var segments = [SegmentItem]()
        
        for index in 0..<numberOfSegments {
            let segment = SegmentItem()
            segment.enabled = isEnabledForSegment(at: index)
            segment.title = titleForSegment(at: index)
            segment.width = widthForSegment(at: index)
            segment.contentOffset = contentOffsetForSegment(at: index)
            segment.image = imageForSegment(at: index)
            segments.append(segment)
        }
        
        return segments
    }
    
    open override func preparePeek(with coordinator: Coordinator) {
        for target in self.allTargets {
            for action in self.actions(forTarget: target, forControlEvent: .valueChanged) ?? [] {
                var detail: String = ""
{'fraction_non_alphanumeric': 0.0692450599560885, 'fraction_numerical': 0.0033778078027360244, 'mean_word_length': 2.6286764705882355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7655667', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1472, 'n_words': 599}