<commit_before>//
//  PageModificationBulletinPage.swift
//  Pageboy-Example
//
//  Created by <NAME> on 23/07/2018.
//  Copyright © 2018 UI At Six. All rights reserved.
//

import UIKit
import BLTNBoard
import Pageboy

class PageModificationBulletinPage: BLTNPageItem {
    
    // MARK: Types
    
    enum ModificationOption: String, EnumCollection {
        case insertion = "Insert"
        case removal = "Remove"
    }
    
    // MARK: Properties
    
    private var pageStepper: PageStepper!
    private var optionSegmentedControl: UISegmentedControl!
    
    private weak var pageViewController: PageboyViewController!
    
    var modificationOption: ModificationOption {
        return ModificationOption.all[optionSegmentedControl.selectedSegmentIndex]
    }
    var pageIndex: Int {
        return pageStepper.currentPage
    }
    
    // MARK: Init
    
    init(title: String, pageViewController: PageboyViewController) {
        self.pageViewController = pageViewController
        super.init(title: title)
        
        self.actionButtonTitle = "Confirm"
        self.requiresCloseButton = false
    }
    
    // MARK: Lifecycle
    
    override func makeViewsUnderTitle(with interfaceBuilder: BLTNInterfaceBuilder) -> [UIView]? {
        let stack = interfaceBuilder.makeGroupStack(spacing: 16.0)
        
        let intentPrompt = makePromptLabel()
        intentPrompt.text = "I want to"
        stack.addArrangedSubview(intentPrompt)
        
        let optionSegmentedControl = makeOptionSegmentedControl(for: ModificationOption.all)
        stack.addArrangedSubview(optionSegmentedControl)
        self.optionSegmentedControl = optionSegmentedControl
        
        let indexPrompt = makePromptLabel()
        indexPrompt.text = "at page index"
        stack.addArrangedSubview(indexPrompt)
        
        let stepper = makePageStepper()
        stepper.numberOfPages = pageViewController.pageCount ?? 0
        stack.addArrangedSubview(stepper)
        self.pageStepper = stepper
        
        return [stack]
    }
}

extension PageModificationBulletinPage {
    
    private func makePromptLabel() -> UILabel {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 18.0)
        label.textColor = .gray
        label.numberOfLines = 0
        label.textAlignment = .center
        return label
    }
    
    private func makePageStepper() -> PageStepper {
        let stepper = PageStepper()
        stepper.tintColor = appearance.actionButtonColor
        return stepper
    }
    
    private func makeOptionSegmentedControl(for options: [ModificationOption]) -> UISegmentedControl {
        let segmentedControl = UISegmentedControl(items: options.map({ $0.rawValue }))
        
        segmentedControl.tintColor = appearance.actionButtonColor
        segmentedControl.selectedSegmentIndex = 0<commit_msg>Allow insertion of page at end of indexes<commit_after>//
//  PageModificationBulletinPage.swift
//  Pageboy-Example
//
//  Created by <NAME> on 23/07/2018.
//  Copyright © 2018 UI At Six. All rights reserved.
//

import UIKit
import BLTNBoard
import Pageboy

class PageModificationBulletinPage: BLTNPageItem {
    
    // MARK: Types
    
    enum ModificationOption: String, EnumCollection {
        case insertion = "Insert"
        case removal = "Remove"
    }
    
    // MARK: Properties
    
    private var pageStepper: PageStepper!
    private var optionSegmentedControl: UISegmentedControl!
    
    private weak var pageViewController: PageboyViewController!
    
    var modificationOption: ModificationOption {
        return ModificationOption.all[optionSegmentedControl.selectedSegmentIndex]
    }
    var pageIndex: Int {
        return pageStepper.currentPage
    }
    
    // MARK: Init
    
    init(title: String, pageViewController: PageboyViewController) {
        self.pageViewController = pageViewController
        super.init(title: title)
        
        self.actionButtonTitle = "Confirm"
        self.requiresCloseButton = false
    }
    
    // MARK: Lifecycle
    
    override func makeViewsUnderTitle(with interfaceBuilder: BLTNInterfaceBuilder) -> [UIView]? {
        let stack = interfaceBuilder.makeGroupStack(spacing: 16.0)
        
        let intentPrompt = makePromptLabel()
        intentPrompt.text = "I want to"
        stack.addArrangedSubview(intentPrompt)
        
        let optionSegmentedControl = makeOptionSegmentedControl(for: ModificationOption.all)
        stack.addArrangedSubview(optionSegmentedControl)
        self.optionSegmentedControl = optionSegmentedControl
        
        let indexPrompt = makePromptLabel()
        indexPrompt.text = "at page index"
        stack.addArrangedSubview(indexPrompt)
        
        let stepper = makePageStepper()
        stepper.numberOfPages = (pageViewController.pageCount ?? 0) + 1
        stack.addArrangedSubview(stepper)
        self.pageStepper = stepper
        
        return [stack]
    }
}

extension PageModificationBulletinPage {
    
    private func makePromptLabel() -> UILabel {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 18.0)
        label.textColor = .gray
        label.numberOfLines = 0
        label.textAlignment = .center
        return label
    }
    
    private func makePageStepper() -> PageStepper {
        let stepper = PageStepper()
        stepper.tintColor = appearance.actionButtonColor
        return stepper
    }
    
    private func makeOptionSegmentedControl(for options: [ModificationOption]) -> UISegmentedControl {
        let segmentedControl = UISegmentedControl(items: options.map({ $0.rawValue }))
        
        segmentedControl.tintColor = appearance.actionButtonColor
        segmentedControl.selectedSegmentIndex = 0
{'fraction_non_alphanumeric': 0.07310750086415485, 'fraction_numerical': 0.0077773937089526445, 'mean_word_length': 2.603362391033624, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4438779', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1565, 'n_words': 345}