 import UIKit
 
 
-open class ElongationCell: UITableViewCell {
+open class ElongationCell: UITableViewCell, Expandable {
   
   // MARK: Public properties
   open var isExpanded = false
   
-  @IBOutlet public var frontView: UIView!
-  @IBOutlet public var frontViewHeightConstraint: NSLayoutConstraint!
-  
-  @IBOutlet public var backView: UIView!
-  @IBOutlet public var backViewHeightConstraint: NSLayoutConstraint!
-  @IBOutlet public var backViewTopConstraint: NSLayoutConstraint!
+  @IBOutlet public var topView: UIView!
+  @IBOutlet public var topViewHeightConstraint: NSLayoutConstraint!
+  
+  /// This is the top view which can be scaled if `scaleFactor` was configured in `ElongationAppearance`.
+  /// Also to this view can be applied 'parallax' effect.
+  @IBOutlet public var scalableView: UIView!
+  @IBOutlet public var scalableViewTopConstraint: NSLayoutConstraint!
+  @IBOutlet public var scalableViewBottomConstraint: NSLayoutConstraint!
+  
+  @IBOutlet public var bottomView: UIView!
+  @IBOutlet public var bottomViewHeightConstraint: NSLayoutConstraint!
+  @IBOutlet public var bottomViewTopConstraint: NSLayoutConstraint!
+  @IBOutlet public var bottomViewBottomConstraint: NSLayoutConstraint!
   
   // MARK: Private properties
-  fileprivate var dimmingView = UIView()
-  
-  fileprivate var appearance: ElongationAppearance {
-    return ElongationAppearance.defaultAppearance
-  }
+  fileprivate var dimmingView: UIView!
+  fileprivate var topSeparatorLine: UIView?
+  fileprivate var bottomSeparatorLine: UIView?
+  fileprivate var appearance: ElongationConfig {
+    return ElongationConfig.shared
+  }
+  
+  fileprivate var scalableViewTopOffset: CGFloat!
+  fileprivate var scalableViewBottomOffset: CGFloat!
+  fileprivate var scalableViewLastParrallaxOffset: CGFloat!
   
   // MARK: Constructor
   public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {

    dimmingView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  }
  
  open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    let frontViewContainsPoint = frontView.frame.contains(point)
    let backViewContainsPoint = backView.frame.contains(point)
    
    if frontViewContainsPoint {
      return frontView
    }
    
    if backViewContainsPoint {
      return backView
    }
    
    return nil
  }
  
}

// MARK: - Lifecycle 🌎
extension ElongationCell {
  
  open override func layoutSubviews() {
    super.layoutSubviews()
    if #available(iOS 10, *) {
      UIView.animate(withDuration: 0.3) { self.contentView.layoutIfNeeded() }
    }
  }
  
  open override func updateConstraints() {
    frontViewHeightConstraint?.constant = appearance.frontViewHeight
    super.updateConstraints()
  }
  
}

    isExpanded = value
    
    if animated {
      UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseInOut, animations: {
        self.updateCellState()
      }, completion: nil)
    } else {
      updateCellState()
    }
  }
  
  open func dim(_ value: Bool, animated: Bool = true) {
    let alpha: CGFloat = value ? 0.9 : 0
    if animated {
      UIView.animate(withDuration: 0.2) {
        self.dimmingView.alpha = alpha
        self.contentView.backgroundColor = value ? .black : .white
      }
    } else {
      self.dimmingView.alpha = alpha
      self.contentView.backgroundColor = value ? .black : .white
    }
