<commit_before>//
//  TwicketSegmentedControl.swift
//  Twicket
//
//  Created by <NAME> on 7/11/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

protocol TwicketSegmentedControlDelegate: class {
    func didSelect(_ segmentIndex: Int)
}

open class TwicketSegmentedControl: UIControl {
    static let height: CGFloat = Constants.height + Constants.topBottomMargin * 2

    struct Constants {
        static let height: CGFloat = 30
        static let topBottomMargin: CGFloat = 5
        static let leadingTrailingMargin: CGFloat = 10
    }

    class SliderView: UIView {
        // MARK: - Properties
        fileprivate let sliderMaskView = UIView()

        var cornerRadius: CGFloat! {
            didSet {
                layer.cornerRadius = cornerRadius
                sliderMaskView.layer.cornerRadius = cornerRadius
            }
        }

        override var frame: CGRect {
            didSet {
                sliderMaskView.frame = frame
            }
        }

        override var center: CGPoint {
            didSet {
                sliderMaskView.center = center
            }
        }

        init() {
            super.init(frame: .zero)
            setup()
        }

        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            setup()
        }

        private func setup() {
            layer.masksToBounds = true
            sliderMaskView.backgroundColor = .black
            sliderMaskView.addShadow(with: .black)
        }
    }

    weak var delegate: TwicketSegmentedControlDelegate?

    open var defaultTextColor: UIColor = Color.appDarkGray40 {
        didSet {
            updateLabelsColor(with: defaultTextColor, selected: false)
        }
    }

    open var highlightTextColor: UIColor = .white {
        didSet {
            updateLabelsColor(with: highlightTextColor, selected: true)
        }
    }

    open var segmentsBackgroundColor: UIColor = Color.appGray70 {
        didSet {
            backgroundView.backgroundColor = backgroundColor
        }
    }

    open var sliderBackgroundColor: UIColor = Color.appSecondaryColor {
        didSet {
            selectedContainerView.backgroundColor = sliderBackgroundColor
        }
    }

    open var font: UIFont = UIFont.systemFont(ofSize: 15, weight: UIFontWeightMedium) {
        didSet {
            updateLabelsFont(with: font)
        }
    }

    open var selectedSegmentIndex: Int = 0 {
        didSet {
            move(to: selectedSegmentIndex)
        }
    }

    fileprivate var segments: [String] = []

    fileprivate var numberOfSegments: Int {
        return segments.count
    }

    fileprivate var segmentWidth: CGFloat {
        return self.backgroundView.frame.width / CGFloat(numberOfSegments)
    }

    fileprivate var correction: CGFloat = 0

    fileprivate lazy var containerView: UIView = UIView()
    fileprivate lazy var backgroundView: UIView = UIView()
    fileprivate lazy var selectedContainerView: UIView = UIView(frame: .zero)
    fileprivate lazy var sliderView: SliderView = SliderView()

    public override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }

    // MARK: Setup

    fileprivate func setup() {
        addSubview(containerView)
        containerView.addSubview(backgroundView)
        containerView.addSubview(selectedContainerView)
        containerView.addSubview(sliderView)

        selectedContainerView.layer.mask = sliderView.sliderMaskView.layer
        addTapGesture()
        addDragGesture()
    }<commit_msg>Convert selectedSegmentIndex into a readonly prop<commit_after>//
//  TwicketSegmentedControl.swift
//  Twicket
//
//  Created by <NAME> on 7/11/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

protocol TwicketSegmentedControlDelegate: class {
    func didSelect(_ segmentIndex: Int)
}

open class TwicketSegmentedControl: UIControl {
    static let height: CGFloat = Constants.height + Constants.topBottomMargin * 2

    struct Constants {
        static let height: CGFloat = 30
        static let topBottomMargin: CGFloat = 5
        static let leadingTrailingMargin: CGFloat = 10
    }

    class SliderView: UIView {
        // MARK: - Properties
        fileprivate let sliderMaskView = UIView()

        var cornerRadius: CGFloat! {
            didSet {
                layer.cornerRadius = cornerRadius
                sliderMaskView.layer.cornerRadius = cornerRadius
            }
        }

        override var frame: CGRect {
            didSet {
                sliderMaskView.frame = frame
            }
        }

        override var center: CGPoint {
            didSet {
                sliderMaskView.center = center
            }
        }

        init() {
            super.init(frame: .zero)
            setup()
        }

        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            setup()
        }

        private func setup() {
            layer.masksToBounds = true
            sliderMaskView.backgroundColor = .black
            sliderMaskView.addShadow(with: .black)
        }
    }

    weak var delegate: TwicketSegmentedControlDelegate?

    open var defaultTextColor: UIColor = Color.appDarkGray40 {
        didSet {
            updateLabelsColor(with: defaultTextColor, selected: false)
        }
    }

    open var highlightTextColor: UIColor = .white {
        didSet {
            updateLabelsColor(with: highlightTextColor, selected: true)
        }
    }

    open var segmentsBackgroundColor: UIColor = Color.appGray70 {
        didSet {
            backgroundView.backgroundColor = backgroundColor
        }
    }

    open var sliderBackgroundColor: UIColor = Color.appSecondaryColor {
        didSet {
            selectedContainerView.backgroundColor = sliderBackgroundColor
        }
    }

    open var font: UIFont = UIFont.systemFont(ofSize: 15, weight: UIFontWeightMedium) {
        didSet {
            updateLabelsFont(with: font)
        }
    }

    private(set) open var selectedSegmentIndex: Int = 0

    fileprivate var segments: [String] = []

    fileprivate var numberOfSegments: Int {
        return segments.count
    }

    fileprivate var segmentWidth: CGFloat {
        return self.backgroundView.frame.width / CGFloat(numberOfSegments)
    }

    fileprivate var correction: CGFloat = 0

    fileprivate lazy var containerView: UIView = UIView()
    fileprivate lazy var backgroundView: UIView = UIView()
    fileprivate lazy var selectedContainerView: UIView = UIView()
    fileprivate lazy var sliderView: SliderView = SliderView()

    public override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }

    // MARK: Setup

    fileprivate func setup() {
        addSubview(containerView)
        containerView.addSubview(backgroundView)
        containerView.addSubview(selectedContainerView)
        containerView.addSubview(sliderView)

        selectedContainerView.layer.mask = sliderView.sliderMaskView.layer
        addTapGesture()
        addDragGesture()
    }
{'fraction_non_alphanumeric': 0.07520131022246486, 'fraction_numerical': 0.006278149310768391, 'mean_word_length': 2.0972104818258663, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6317781', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1955, 'n_words': 476}