<commit_before>//
//  ActionSheetController.swift
//  RandomReminders
//
//  Created by <NAME> on 21/02/16.
//  Copyright © 2016 SintraWorks. All rights reserved.
//
//  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
//  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 let LightColor = UIColor.whiteColor()
internal let TransparentLightColor = UIColor.whiteColor().colorWithAlphaComponent(0.75)
internal let DarkColor = UIColor.blackColor()
internal let TransparentDarkColor = UIColor.blackColor().colorWithAlphaComponent(0.75)
internal let UnblurredBackgroundColorForLightStyle = DarkColor.colorWithAlphaComponent(0.2)
internal let UnblurredBackgroundColorForDarkStyle = LightColor.colorWithAlphaComponent(0.2)
internal let ClearColor = UIColor.clearColor()
internal let StackViewRowHeightAnchorConstraint: CGFloat = 44.0


// MARK: - Controller

/// The controller style determines the overall theme of the controller. Either White or Black.

public enum ActionSheetControllerStyle: Int {
    /// The light theme, with a light background.
    case Light
    /// The dark theme, with a dark background.
    case Dark
}


/// iOS control for presenting a view in a style reminiscent of an action sheet/alert.
/// You can add a custom view, and any number of buttons to represent and handle actions.
public class ActionSheetController: UIViewController, UIViewControllerTransitioningDelegate {
    private let interStackViewheightAnchorConstraint: CGFloat = 16.0
    private var cornerRadius: CGFloat {
        get {
            return (UIDevice.currentDevice().userInterfaceIdiom == .Pad) ? 8.0 : 4.0
        }
    }
    
    private(set) var style: ActionSheetControllerStyle = .Light
    
    /// The message shown in the header of the controller.
    public var message: String?
    
    /// Whether to disable background taps. When true, tapping outside the controller has no effect.
    /// When false, tapping outside the controller dismisses the controller without triggering any actions.
    public var disableBackgroundTaps: Bool = false
    
    var additionalActions: [ActionSheetControllerAction] = []
    var doneActions: [ActionSheetControllerAction] = []
    var cancelActions: [ActionSheetControllerAction] = []
    
    var animationConstraint: NSLayoutConstraint?
    
    lazy private var backgroundView: UIView = {
        var backgroundView: UIView? = nil
        if self.blurEffectsDisabled {
            backgroundView = UIView(frame: CGRectZero)
            backgroundView?.backgroundColor = self.style == .Light ?  UnblurredBackgroundColorForLightStyle : UnblurredBackgroundColorForDarkStyle
        } else {
            // Note that on older hardware the blur effect may not render correctly (although still acceptably).
            let effect = UIBlurEffect(style: self.backgroundBlurEffectStyleForCurrentStyle)
            backgroundView = UIVisualEffectView(effect: effect)
        }
        
        guard let resultView = backgroundView else { fatalError("Could not create backgroundView") }
        resultView.translatesAutoresizingMaskIntoConstraints = false
        
        let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(ActionSheetController.backgroundViewTapped))
        resultView.addGestureRecognizer(tapRecognizer)
        
        return resultView
    }()
    
    /// Returns the outer stack view that will hold the inner stackviews adn separator view as appropriate.
    lazy private var outerStackView: UIStackView = {
        return self.stackView()
    }()
    
    /// The stack view to be used as the top stack view. This stack view holds all actions except the cancel actions, and it holds the controller's content view.
    lazy private var topStackView: UIStackView = {
        return self.stackView()
    }()
    
    /// The stack view to be used as the bottom stack view. This stack view holds only the cancel actions, if any.
    lazy private var bottomStackView: UIStackView = {
        return self.stackView()
    }()
    
    /// Set the contentView to hold the view you want to display. If you need only buttons, do not set the content view.
    public var contentView: UIView?
    
    /// Returns a UIView to be used as a separator row between the top and bottom stack views.
    private func interStackViewSeparatorView() -> UIView {
        let emptyView = UIView(frame: CGRectZero)
        emptyView.backgroundColor = ClearColor
        emptyView.heightAnchor.constraintEqualToConstant(self.interStackViewheightAnchorConstraint).active = true
        return emptyView
    }
    
    /// Returns a UILabel with the majority of settings preapared for use in this controller. Only the font needs setting by the caller.
    private func label(text: String) -> UILabel {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.text = text
        label.textAlignment = .Center
        label.textColor = self.style == .Light ? UIColor.darkGrayColor() : UIColor.lightGrayColor()
        label.backgroundColor = UIColor.clearColor()
        label.numberOfLines = 0
        return label
    }
    
    /// Returns a UIStackView prepared for use in this controller.
    private func stackView() -> UIStackView {
        let stackView = UIStackView()
        stackView.translatesAutoresizingMaskIntoConstraints = false
        stackView.axis = .Vertical
        stackView.distribution = .Fill
        stackView.alignment = .Fill
        return stackView
    }
    
    /// Returns a view to enclose a stack view (top ro bottom), prepared such that the stack view will display rounded corners.
    private func roundedCornerContainerForView(view: UIView) -> UIView {
        let roundedCornerContainerView = UIView(frame: CGRectZero)
        roundedCornerContainerView.layer.cornerRadius = 4
        roundedCornerContainerView.layer.masksToBounds = true
        roundedCornerContainerView.backgroundColor = self.contextAwareBackgroundColor
        
        roundedCornerContainerView.addSubview(view)
        view.leftAnchor.constraintEqualToAnchor(roundedCornerContainerView.leftAnchor).active = true
        view.topAnchor.constraintEqualToAnchor(roundedCornerContainerView.topAnchor).active = true
        view.rightAnchor.constraintEqualToAnchor(roundedCornerContainerView.rightAnchor).active = true
        view.bottomAnchor.constraintEqualToAnchor(roundedCornerContainerView.bottomAnchor).active = true
        
        return roundedCornerContainerView
    }
    
    
    private var contextAwareLightColor: UIColor {
        return self.blurEffectsDisabled ? LightColor : TransparentLightColor
    }
    
    private var contextAwareDarkColor: UIColor {
        return self.blurEffectsDisabled ? DarkColor : TransparentDarkColor
        
    }
    
    private var contextAwareBackgroundColor: UIColor {
        switch self.style {
        case .Light:
            return self.contextAwareLightColor
        case .Dark:
            return self.contextAwareDarkColor
        }
    }
    
    /// Whether blur effects are disabled or not.
    public var disableBlurEffects: Bool = false
    public var blurEffectsDisabled: Bool {
        get {
            if UIAccessibilityIsReduceTransparencyEnabled() {
                return true
            }
            return disableBlurEffects
        }
    }
    
    private var backgroundBlurEffectStyleForCurrentStyle: UIBlurEffectStyle {
        switch (self.style) {
        case .Light:
            return .Light
        case .Dark:
            return .Dark;
        }
    }
    
    public var disableBouncingEffects: Bool = false
    /// Set to true to disable bouncing when showing the controller.
    public var bouncingEffectsDisabled: Bool {
        get {
            if UIAccessibilityIsReduceMotionEnabled() {<commit_msg>- Correction of background blur effect for controller style.<commit_after>//
//  ActionSheetController.swift
//  RandomReminders
//
//  Created by <NAME> on 21/02/16.
//  Copyright © 2016 SintraWorks. All rights reserved.
//
//  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
//  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 let LightColor = UIColor.whiteColor()
internal let TransparentLightColor = UIColor.whiteColor().colorWithAlphaComponent(0.75)
internal let DarkColor = UIColor.blackColor()
internal let TransparentDarkColor = UIColor.blackColor().colorWithAlphaComponent(0.75)
internal let UnblurredBackgroundColorForLightStyle = DarkColor.colorWithAlphaComponent(0.2)
internal let UnblurredBackgroundColorForDarkStyle = LightColor.colorWithAlphaComponent(0.2)
internal let ClearColor = UIColor.clearColor()
internal let StackViewRowHeightAnchorConstraint: CGFloat = 44.0


// MARK: - Controller

/// The controller style determines the overall theme of the controller. Either White or Black.

public enum ActionSheetControllerStyle: Int {
    /// The light theme, with a light background.
    case Light
    /// The dark theme, with a dark background.
    case Dark
}


/// iOS control for presenting a view in a style reminiscent of an action sheet/alert.
/// You can add a custom view, and any number of buttons to represent and handle actions.
public class ActionSheetController: UIViewController, UIViewControllerTransitioningDelegate {
    private let interStackViewheightAnchorConstraint: CGFloat = 16.0
    private var cornerRadius: CGFloat {
        get {
            return (UIDevice.currentDevice().userInterfaceIdiom == .Pad) ? 8.0 : 4.0
        }
    }
    
    private(set) var style: ActionSheetControllerStyle = .Light
    
    /// The message shown in the header of the controller.
    public var message: String?
    
    /// Whether to disable background taps. When true, tapping outside the controller has no effect.
    /// When false, tapping outside the controller dismisses the controller without triggering any actions.
    public var disableBackgroundTaps: Bool = false
    
    var additionalActions: [ActionSheetControllerAction] = []
    var doneActions: [ActionSheetControllerAction] = []
    var cancelActions: [ActionSheetControllerAction] = []
    
    var animationConstraint: NSLayoutConstraint?
    
    lazy private var backgroundView: UIView = {
        var backgroundView: UIView? = nil
        if self.blurEffectsDisabled {
            backgroundView = UIView(frame: CGRectZero)
            backgroundView?.backgroundColor = self.style == .Light ?  UnblurredBackgroundColorForLightStyle : UnblurredBackgroundColorForDarkStyle
        } else {
            // Note that on older hardware the blur effect may not render correctly (although still acceptably).
            let effect = UIBlurEffect(style: self.backgroundBlurEffectStyleForCurrentStyle)
            backgroundView = UIVisualEffectView(effect: effect)
        }
        
        guard let resultView = backgroundView else { fatalError("Could not create backgroundView") }
        resultView.translatesAutoresizingMaskIntoConstraints = false
        
        let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(ActionSheetController.backgroundViewTapped))
        resultView.addGestureRecognizer(tapRecognizer)
        
        return resultView
    }()
    
    /// Returns the outer stack view that will hold the inner stackviews adn separator view as appropriate.
    lazy private var outerStackView: UIStackView = {
        return self.stackView()
    }()
    
    /// The stack view to be used as the top stack view. This stack view holds all actions except the cancel actions, and it holds the controller's content view.
    lazy private var topStackView: UIStackView = {
        return self.stackView()
    }()
    
    /// The stack view to be used as the bottom stack view. This stack view holds only the cancel actions, if any.
    lazy private var bottomStackView: UIStackView = {
        return self.stackView()
    }()
    
    /// Set the contentView to hold the view you want to display. If you need only buttons, do not set the content view.
    public var contentView: UIView?
    
    /// Returns a UIView to be used as a separator row between the top and bottom stack views.
    private func interStackViewSeparatorView() -> UIView {
        let emptyView = UIView(frame: CGRectZero)
        emptyView.backgroundColor = ClearColor
        emptyView.heightAnchor.constraintEqualToConstant(self.interStackViewheightAnchorConstraint).active = true
        return emptyView
    }
    
    /// Returns a UILabel with the majority of settings preapared for use in this controller. Only the font needs setting by the caller.
    private func label(text: String) -> UILabel {
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        label.text = text
        label.textAlignment = .Center
        label.textColor = self.style == .Light ? UIColor.darkGrayColor() : UIColor.lightGrayColor()
        label.backgroundColor = UIColor.clearColor()
        label.numberOfLines = 0
        return label
    }
    
    /// Returns a UIStackView prepared for use in this controller.
    private func stackView() -> UIStackView {
        let stackView = UIStackView()
        stackView.translatesAutoresizingMaskIntoConstraints = false
        stackView.axis = .Vertical
        stackView.distribution = .Fill
        stackView.alignment = .Fill
        return stackView
    }
    
    /// Returns a view to enclose a stack view (top ro bottom), prepared such that the stack view will display rounded corners.
    private func roundedCornerContainerForView(view: UIView) -> UIView {
        let roundedCornerContainerView = UIView(frame: CGRectZero)
        roundedCornerContainerView.layer.cornerRadius = 4
        roundedCornerContainerView.layer.masksToBounds = true
        roundedCornerContainerView.backgroundColor = self.contextAwareBackgroundColor
        
        roundedCornerContainerView.addSubview(view)
        view.leftAnchor.constraintEqualToAnchor(roundedCornerContainerView.leftAnchor).active = true
        view.topAnchor.constraintEqualToAnchor(roundedCornerContainerView.topAnchor).active = true
        view.rightAnchor.constraintEqualToAnchor(roundedCornerContainerView.rightAnchor).active = true
        view.bottomAnchor.constraintEqualToAnchor(roundedCornerContainerView.bottomAnchor).active = true
        
        return roundedCornerContainerView
    }
    
    
    private var contextAwareLightColor: UIColor {
        return self.blurEffectsDisabled ? LightColor : TransparentLightColor
    }
    
    private var contextAwareDarkColor: UIColor {
        return self.blurEffectsDisabled ? DarkColor : TransparentDarkColor
        
    }
    
    private var contextAwareBackgroundColor: UIColor {
        switch self.style {
        case .Light:
            return self.contextAwareLightColor
        case .Dark:
            return self.contextAwareDarkColor
        }
    }
    
    /// Whether blur effects are disabled or not.
    public var disableBlurEffects: Bool = false
    public var blurEffectsDisabled: Bool {
        get {
            if UIAccessibilityIsReduceTransparencyEnabled() {
                return true
            }
            return disableBlurEffects
        }
    }
    
    private var backgroundBlurEffectStyleForCurrentStyle: UIBlurEffectStyle {
        switch (self.style) {
        case .Light:
            return .Dark
        case .Dark:
            return .Light;
        }
    }
    
    public var disableBouncingEffects: Bool = false
    /// Set to true to disable bouncing when showing the controller.
    public var bouncingEffectsDisabled: Bool {
        get {
            if UIAccessibilityIsReduceMotionEnabled() {
{'fraction_non_alphanumeric': 0.06381895332390382, 'fraction_numerical': 0.003620933521923621, 'mean_word_length': 2.980184643098401, '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': '5706644', 'n_tokens_mistral': 4466, 'n_tokens_neox': 4353, 'n_words': 1556}