<commit_before>import UIKit

typealias ScrollableEducationPanelButtonTapHandler = ((_ sender: Any) -> ())
typealias ScrollableEducationPanelDismissHandler = (() -> ())

/*
 Education panels typically have the following items, from top to bottom:
    == Close button ==
    == Image ==
    == Heading text ==
    == Subheading text ==
    == Primary button ==
    == Secondary button ==
    == Footer text ==
 
 This class pairs with a xib with roughly the following structure:
    view
        scroll view
            stack view
                close button
                image view
                heading label
                subheading label
                primary button
                secondary button
                footer label
 
 - Stackview management of its subviews makes it easy to collapse space for unneeded items.
 - Scrollview containment makes long translations or landscape on small phones scrollable when needed.
*/
class ScrollableEducationPanelViewController: UIViewController, Themeable {
    @IBOutlet fileprivate weak var closeButton: UIButton!
    @IBOutlet fileprivate weak var imageView: UIImageView!
    @IBOutlet fileprivate weak var headingLabel: UILabel!
    @IBOutlet fileprivate weak var subheadingLabel: UILabel!
    @IBOutlet fileprivate weak var primaryButton: AutoLayoutSafeMultiLineButton!
    @IBOutlet fileprivate weak var secondaryButton: AutoLayoutSafeMultiLineButton!
    @IBOutlet fileprivate weak var footerLabel: UILabel!

    @IBOutlet fileprivate weak var scrollViewContainer: UIView!
    @IBOutlet fileprivate weak var stackView: UIStackView!
    @IBOutlet fileprivate weak var roundedCornerContainer: UIView!
    @IBOutlet fileprivate weak var effectsView: UIVisualEffectView!

    fileprivate var primaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?
    fileprivate var secondaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?
    fileprivate var dismissHandler: ScrollableEducationPanelDismissHandler?
    fileprivate var showCloseButton = true
    private var discardDismissHandlerOnPrimaryButtonTap = false
    private var primaryButtonTapped = false
    private var theme: Theme = Theme.standard
    
    var image:UIImage? {
        get {
            return imageView.image
        }
        set {
            imageView.image = newValue
            view.setNeedsLayout() // Ensures stackview will collapse if image is set to nil.
        }
    }

    var heading:String? {
        get {
            return headingLabel.text
        }
        set {
            headingLabel.text = newValue
            view.setNeedsLayout()
        }
    }

    var subheading:String? {
        get {
            return subheadingLabel.text
        }
        set {
            subheadingLabel.text = newValue
            view.setNeedsLayout()
        }
    }

    var primaryButtonTitle:String? {
        get {
            return primaryButton.title(for: .normal)
        }
        set {
            primaryButton.setTitle(newValue, for: .normal)
            view.setNeedsLayout()
        }
    }

    var secondaryButtonTitle:String? {
        get {
            return secondaryButton.title(for: .normal)
        }
        set {
            secondaryButton.setTitle(newValue, for: .normal)
            view.setNeedsLayout()
        }
    }

    var footer:String? {
        get {
            return footerLabel.text
        }
        set {
            footerLabel.text = newValue
            view.setNeedsLayout()
        }
    }
    
    init(showCloseButton: Bool, primaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?, secondaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?, dismissHandler: ScrollableEducationPanelDismissHandler?, discardDismissHandlerOnPrimaryButtonTap: Bool = false, theme: Theme) {
        super.init(nibName: "ScrollableEducationPanelView", bundle: nil)
        self.modalPresentationStyle = .overFullScreen
        self.modalTransitionStyle = .crossDissolve
        self.theme = theme
        self.showCloseButton = showCloseButton
        self.primaryButtonTapHandler = primaryButtonTapHandler
        self.secondaryButtonTapHandler = secondaryButtonTapHandler
        self.dismissHandler = dismissHandler
        self.discardDismissHandlerOnPrimaryButtonTap = discardDismissHandlerOnPrimaryButtonTap
    }
    required public init?(coder aDecoder: NSCoder) {
        return nil
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        assert(stackView.wmf_firstArrangedSubviewWithRequiredNonZeroHeightConstraint() == nil, stackView.wmf_anArrangedSubviewHasRequiredNonZeroHeightConstraintAssertString())
        
        reset()
        
        closeButton.isHidden = !showCloseButton
        [self.view, self.roundedCornerContainer].forEach {view in
            view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.overlayTapped(_:))))
        }
        
        closeButton.setImage(UIImage(named:"places-auth-close")?.withRenderingMode(.alwaysTemplate), for: .normal)
        closeButton.accessibilityLabel = CommonStrings.closeButtonAccessibilityLabel
        
        apply(theme: theme)
    }
    
    @IBAction func overlayTapped(_ sender: UITapGestureRecognizer) {
        if (showCloseButton && sender.view == view) {
            dismiss(animated: true, completion: nil)<commit_msg>re-add panel text alignment<commit_after>import UIKit

typealias ScrollableEducationPanelButtonTapHandler = ((_ sender: Any) -> ())
typealias ScrollableEducationPanelDismissHandler = (() -> ())

/*
 Education panels typically have the following items, from top to bottom:
    == Close button ==
    == Image ==
    == Heading text ==
    == Subheading text ==
    == Primary button ==
    == Secondary button ==
    == Footer text ==
 
 This class pairs with a xib with roughly the following structure:
    view
        scroll view
            stack view
                close button
                image view
                heading label
                subheading label
                primary button
                secondary button
                footer label
 
 - Stackview management of its subviews makes it easy to collapse space for unneeded items.
 - Scrollview containment makes long translations or landscape on small phones scrollable when needed.
*/
class ScrollableEducationPanelViewController: UIViewController, Themeable {
    @IBOutlet fileprivate weak var closeButton: UIButton!
    @IBOutlet fileprivate weak var imageView: UIImageView!
    @IBOutlet fileprivate weak var headingLabel: UILabel!
    @IBOutlet fileprivate weak var subheadingLabel: UILabel!
    @IBOutlet fileprivate weak var primaryButton: AutoLayoutSafeMultiLineButton!
    @IBOutlet fileprivate weak var secondaryButton: AutoLayoutSafeMultiLineButton!
    @IBOutlet fileprivate weak var footerLabel: UILabel!

    @IBOutlet fileprivate weak var scrollViewContainer: UIView!
    @IBOutlet fileprivate weak var stackView: UIStackView!
    @IBOutlet fileprivate weak var roundedCornerContainer: UIView!
    @IBOutlet fileprivate weak var effectsView: UIVisualEffectView!

    fileprivate var primaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?
    fileprivate var secondaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?
    fileprivate var dismissHandler: ScrollableEducationPanelDismissHandler?
    fileprivate var showCloseButton = true
    private var discardDismissHandlerOnPrimaryButtonTap = false
    private var primaryButtonTapped = false
    private var theme: Theme = Theme.standard
    
    var image:UIImage? {
        get {
            return imageView.image
        }
        set {
            imageView.image = newValue
            view.setNeedsLayout() // Ensures stackview will collapse if image is set to nil.
        }
    }

    var heading:String? {
        get {
            return headingLabel.text
        }
        set {
            headingLabel.text = newValue
            view.setNeedsLayout()
        }
    }

    var subheading:String? {
        get {
            return subheadingLabel.text
        }
        set {
            subheadingLabel.text = newValue
            view.setNeedsLayout()
        }
    }

    var primaryButtonTitle:String? {
        get {
            return primaryButton.title(for: .normal)
        }
        set {
            primaryButton.setTitle(newValue, for: .normal)
            view.setNeedsLayout()
        }
    }

    var secondaryButtonTitle:String? {
        get {
            return secondaryButton.title(for: .normal)
        }
        set {
            secondaryButton.setTitle(newValue, for: .normal)
            view.setNeedsLayout()
        }
    }

    var footer:String? {
        get {
            return footerLabel.text
        }
        set {
            footerLabel.text = newValue
            view.setNeedsLayout()
        }
    }
    
    init(showCloseButton: Bool, primaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?, secondaryButtonTapHandler: ScrollableEducationPanelButtonTapHandler?, dismissHandler: ScrollableEducationPanelDismissHandler?, discardDismissHandlerOnPrimaryButtonTap: Bool = false, theme: Theme) {
        super.init(nibName: "ScrollableEducationPanelView", bundle: nil)
        self.modalPresentationStyle = .overFullScreen
        self.modalTransitionStyle = .crossDissolve
        self.theme = theme
        self.showCloseButton = showCloseButton
        self.primaryButtonTapHandler = primaryButtonTapHandler
        self.secondaryButtonTapHandler = secondaryButtonTapHandler
        self.dismissHandler = dismissHandler
        self.discardDismissHandlerOnPrimaryButtonTap = discardDismissHandlerOnPrimaryButtonTap
    }
    required public init?(coder aDecoder: NSCoder) {
        return nil
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        assert(stackView.wmf_firstArrangedSubviewWithRequiredNonZeroHeightConstraint() == nil, stackView.wmf_anArrangedSubviewHasRequiredNonZeroHeightConstraintAssertString())
        
        reset()
        
        primaryButton.titleLabel?.textAlignment = .center
        secondaryButton.titleLabel?.textAlignment = .center
        
        closeButton.isHidden = !showCloseButton
        [self.view, self.roundedCornerContainer].forEach {view in
            view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.overlayTapped(_:))))
        }
        
        closeButton.setImage(UIImage(named:"places-auth-close")?.withRenderingMode(.alwaysTemplate), for: .normal)
        closeButton.accessibilityLabel = CommonStrings.closeButtonAccessibilityLabel
        
        apply(theme: theme)
    }
    
    @IBAction func overlayTapped(_ sender: UITapGestureRecognizer) {
        if (showCloseButton && sender.view == view) {
            dismiss(animated: true, completion: nil)
{'fraction_non_alphanumeric': 0.0654789236844522, 'fraction_numerical': 0.0, 'mean_word_length': 2.656816655473472, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1690903', 'n_tokens_mistral': 2878, 'n_tokens_neox': 2728, 'n_words': 674}