 import UIKit
 import Darwin
 
+// MARK: -
+// MARK: Enum
+
+/**
+Snackbar display duration types.
+
+- Short:   1 second
+- Middle:  3 seconds
+- Long:    5 seconds
+- Forever: Not dismiss automatically. Must be dismissed manually.
+*/
 public enum TTGSnackbarDuration: NSTimeInterval {
     case Short = 1.0
     case Middle = 3.0

        configure()
    }

    public init(message: String, duration: TTGSnackbarDuration, actionText: String, actionBlock: TTGActionBlock) {
        super.init(frame: CGRectMake(0, 0, 0, 0))
        self.duration = duration

}

public class TTGSnackbar: UIView {
    // MARK: -
    // MARK: Class property.
    
    /// Current instance of Snackbar.
    private static var currentInstance: TTGSnackbar? = nil
    
    /// Animation duration.
    private static let snackbarAnimationDuration: NSTimeInterval = 0.3
    
    /// Snackbar height.
    private static let snackbarHeight: CGFloat = 44
    
    /// Snackbar margin to the bottom of screen.
    private static let snackbarBottomMargin: CGFloat = 4
    
    /// Snackbar margin to the left and right.
    private static let snackbarHorizonMargin: CGFloat = 4
    
    /// Snackbar action button width.
    private static let snackbarActionButtonWidth: CGFloat = 64

    // MARK: -
    // MARK: Typealias
    
    /// Action callback closure definition.
    public typealias TTGActionBlock = (snackbar:TTGSnackbar) -> Void
    
    /// Dismiss callback closure definition.
    public typealias TTGDismissBlock = (snackbar:TTGSnackbar) -> Void

    // MARK: -
    // MARK: Public property.
    
    /// Action callback.
    public var actionBlock: TTGActionBlock? = nil
    
    /// Dismiss callback.
    public var dismissBlock: TTGDismissBlock? = nil
    
    /// Snackbar display duration. Default is Short - 1 second.
    public var duration: TTGSnackbarDuration = TTGSnackbarDuration.Short
    
    /// Snackbar animation type. Default is SlideFromBottomBackToBottom.
    public var animationType: TTGSnackbarAnimationType = TTGSnackbarAnimationType.SlideFromBottomBackToBottom
    
    /// Main text shown on the snackbar.
    public var message: String = "" {
        didSet {
            self.messageLabel.text = message
        }
    }
    
    /// Message text color. Default is white.
    public var messageTextColor: UIColor = UIColor.whiteColor() {
        didSet {
            self.messageLabel.textColor = messageTextColor
        }
    }
    
    /// Action button title.
    public var actionText: String = "" {
        didSet {
            self.actionButton.setTitle(actionText, forState: UIControlState.Normal)
        }
    }
    
    /// Action button title color. Default is white.
    public var actionTextColor: UIColor = UIColor.whiteColor() {
        didSet {
            actionButton.setTitleColor(actionTextColor, forState: UIControlState.Normal)
        }
    }

    // MARK: -
    // MARK: Private property.
    
    private var messageLabel: UILabel!
    private var seperateView: UIView!
    private var actionButton: UIButton!
    private var activityIndicatorView: UIActivityIndicatorView!
    
    /// Timer to dismiss the snackbar.
    private var dismissTimer: NSTimer? = nil

    // Constraints.
    private var centerXConstraint: NSLayoutConstraint? = nil
    private var bottomMarginConstraint: NSLayoutConstraint? = nil
    private var actionButtonWidthConstraint: NSLayoutConstraint? = nil

    // MARK: -
    // MARK: Init
    
    /**
    Show a single message like a Toast.
    
    - parameter message:  Message text.
    - parameter duration: Duration type.
    
    - returns: Void
    */
    public init(message: String, duration: TTGSnackbarDuration) {
        super.init(frame: CGRectMake(0, 0, 0, 0))
        self.duration = duration
