<commit_before>//
//  SwipyCellEnums.swift
//  SwipyCell
//
//  Created by <NAME> on 20.01.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

fileprivate struct Defaults {
    static let stop1: CGFloat               = 0.25  // Percentage limit to trigger the first action
    static let stop2: CGFloat               = 0.75  // Percentage limit to trigger the second action
    static let swipeViewPadding: CGFloat    = 24.0  // Padding of the swipe view (space between cell and swipe view)
    static let shouldAnimateSlideViews      = true
    static let defaultSlideViewColor        = UIColor.white
}

public typealias SwipyCellTriggerBlock = (SwipyCell, SwipyCellState, SwipyCellMode) -> Void

public protocol SwipyCellDelegate {
    func swipyCellDidStartSwiping(_ cell: SwipyCell)
    func swipyCellDidFinishSwiping(_ cell: SwipyCell)
    func swipyCell(_ cell: SwipyCell, didSwipeWithPercentage percentage: CGFloat)
}

public struct SwipyCellTrigger {
    init(mode: SwipyCellMode, color: UIColor, view: UIView, block: SwipyCellTriggerBlock?) {
        self.mode = mode
        self.color = color
        self.view = view
        self.block = block
    }
    
    var mode: SwipyCellMode
    var color: UIColor
    var view: UIView
    var block: SwipyCellTriggerBlock?
    
    func executeTriggerBlock(withSwipyCell cell: SwipyCell, state: SwipyCellState) {
        block?(cell, state, mode)
    }
}

public enum SwipyCellState: Hashable {
    case none
    case state(Int, SwipyCellDirection)
    
    public var hashValue: Int {
        return self.toInt()
    }
    
    static public func ==(lhs: SwipyCellState, rhs: SwipyCellState) -> Bool {
        return lhs.toInt() == rhs.toInt()
    }

    private func toInt() -> Int {
        switch self {
        case .none:
            return 0
        case .state(let stateNum, let stateDirection):
            // add one because state(0,...) would always be 0
            if stateDirection == .left {
                return stateNum + 1
            } else if stateDirection == .right {
                return -(stateNum + 1)
            }
        }
        
        return 0
    }
}

public enum SwipyCellMode: UInt {
    case none = 0
    case exit
    case toggle
}

public enum SwipyCellDirection: UInt {
    case left = 0
    case center
    case right
}

protocol SwipyCellTriggerPointEditable: class {
    var triggerPoints: [CGFloat: SwipyCellState] { get set }
    
    func setTriggerPoint(forState state: SwipyCellState, at point: CGFloat)
    func setTriggerPoint(forIndex index: Int, at point: CGFloat)
    func setTriggerPoints(_ points: [CGFloat: SwipyCellState])
    func setTriggerPoints(_ points: [CGFloat: Int])
    func setTriggerPoints(points: [CGFloat])
    func clearTriggerPoints()
}
extension SwipyCellTriggerPointEditable {
    
    public func setTriggerPoint(forState state: SwipyCellState, at point: CGFloat) {
        var p = fabs(point)
        if case .state(_, let direction) = state, direction == .right {
            p = -p
        }
        triggerPoints[p] = state
    }
    
    public func setTriggerPoint(forIndex index: Int, at point: CGFloat) {
        let p = fabs(point)
        triggerPoints[p] = SwipyCellState.state(index, .left)
        triggerPoints[-p] = SwipyCellState.state(index, .right)
    }
    
    public func setTriggerPoints(_ points: [CGFloat: SwipyCellState]) {
        triggerPoints = points
    }
    
    public func setTriggerPoints(_ points: [CGFloat: Int]) {
        triggerPoints = [:]
        _ = points.map { point, index in
            let p = fabs(point)
            triggerPoints[p] = SwipyCellState.state(index, .left)
            triggerPoints[-p] = SwipyCellState.state(index, .right)
        }
    }
    
    public func setTriggerPoints(points: [CGFloat]) {
        triggerPoints = [:]
        for (index, point) in points.enumerated() {
            let p = fabs(point)
            triggerPoints[p] = SwipyCellState.state(index, .left)
            triggerPoints[-p] = SwipyCellState.state(index, .right)
        }
    }
    
    public func clearTriggerPoints() {
        triggerPoints = [:]
    }
}

public class SwipyCellConfig: SwipyCellTriggerPointEditable {
    static let shared = SwipyCellConfig()
    
    var triggerPoints: [CGFloat: SwipyCellState]
    var swipeViewPadding: CGFloat
    var shouldAnimateSlideViews: Bool
    var defaultSlideViewColor: UIColor
    <commit_msg>Added getter for trigger points<commit_after>//
//  SwipyCellEnums.swift
//  SwipyCell
//
//  Created by <NAME> on 20.01.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

fileprivate struct Defaults {
    static let stop1: CGFloat               = 0.25  // Percentage limit to trigger the first action
    static let stop2: CGFloat               = 0.75  // Percentage limit to trigger the second action
    static let swipeViewPadding: CGFloat    = 24.0  // Padding of the swipe view (space between cell and swipe view)
    static let shouldAnimateSlideViews      = true
    static let defaultSlideViewColor        = UIColor.white
}

public typealias SwipyCellTriggerBlock = (SwipyCell, SwipyCellState, SwipyCellMode) -> Void

public protocol SwipyCellDelegate {
    func swipyCellDidStartSwiping(_ cell: SwipyCell)
    func swipyCellDidFinishSwiping(_ cell: SwipyCell)
    func swipyCell(_ cell: SwipyCell, didSwipeWithPercentage percentage: CGFloat)
}

public struct SwipyCellTrigger {
    init(mode: SwipyCellMode, color: UIColor, view: UIView, block: SwipyCellTriggerBlock?) {
        self.mode = mode
        self.color = color
        self.view = view
        self.block = block
    }
    
    var mode: SwipyCellMode
    var color: UIColor
    var view: UIView
    var block: SwipyCellTriggerBlock?
    
    func executeTriggerBlock(withSwipyCell cell: SwipyCell, state: SwipyCellState) {
        block?(cell, state, mode)
    }
}

public enum SwipyCellState: Hashable {
    case none
    case state(Int, SwipyCellDirection)
    
    public var hashValue: Int {
        return self.toInt()
    }
    
    static public func ==(lhs: SwipyCellState, rhs: SwipyCellState) -> Bool {
        return lhs.toInt() == rhs.toInt()
    }

    private func toInt() -> Int {
        switch self {
        case .none:
            return 0
        case .state(let stateNum, let stateDirection):
            // add one because state(0,...) would always be 0
            if stateDirection == .left {
                return stateNum + 1
            } else if stateDirection == .right {
                return -(stateNum + 1)
            }
        }
        
        return 0
    }
}

public enum SwipyCellMode: UInt {
    case none = 0
    case exit
    case toggle
}

public enum SwipyCellDirection: UInt {
    case left = 0
    case center
    case right
}

protocol SwipyCellTriggerPointEditable: class {
    var triggerPoints: [CGFloat: SwipyCellState] { get set }
    
    func setTriggerPoint(forState state: SwipyCellState, at point: CGFloat)
    func setTriggerPoint(forIndex index: Int, at point: CGFloat)
    func setTriggerPoints(_ points: [CGFloat: SwipyCellState])
    func setTriggerPoints(_ points: [CGFloat: Int])
    func setTriggerPoints(points: [CGFloat])
    func getTriggerPoints() -> [CGFloat: SwipyCellState]
    func clearTriggerPoints()
}
extension SwipyCellTriggerPointEditable {
    
    public func setTriggerPoint(forState state: SwipyCellState, at point: CGFloat) {
        var p = fabs(point)
        if case .state(_, let direction) = state, direction == .right {
            p = -p
        }
        triggerPoints[p] = state
    }
    
    public func setTriggerPoint(forIndex index: Int, at point: CGFloat) {
        let p = fabs(point)
        triggerPoints[p] = SwipyCellState.state(index, .left)
        triggerPoints[-p] = SwipyCellState.state(index, .right)
    }
    
    public func setTriggerPoints(_ points: [CGFloat: SwipyCellState]) {
        triggerPoints = points
    }
    
    public func setTriggerPoints(_ points: [CGFloat: Int]) {
        triggerPoints = [:]
        _ = points.map { point, index in
            let p = fabs(point)
            triggerPoints[p] = SwipyCellState.state(index, .left)
            triggerPoints[-p] = SwipyCellState.state(index, .right)
        }
    }
    
    public func setTriggerPoints(points: [CGFloat]) {
        triggerPoints = [:]
        for (index, point) in points.enumerated() {
            let p = fabs(point)
            triggerPoints[p] = SwipyCellState.state(index, .left)
            triggerPoints[-p] = SwipyCellState.state(index, .right)
        }
    }
    
    public func getTriggerPoints() -> [CGFloat: SwipyCellState] {
        return triggerPoints
    }
    
    public func clearTriggerPoints() {
        triggerPoints = [:]
    }
}

public class SwipyCellConfig: SwipyCellTriggerPointEditable {
    static let shared = SwipyCellConfig()
    
    internal var triggerPoints: [CGFloat: SwipyCellState]
    var swipeViewPadding: CGFloat
    var shouldAnimateSlideViews: Bool
    var defaultSlideViewColor: UIColor
    
{'fraction_non_alphanumeric': 0.0863626349416171, 'fraction_numerical': 0.006389072482925755, 'mean_word_length': 2.454718417047184, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '1523721', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2788, 'n_words': 758}