 ###
 TAG_NAME = vars.readPrefixed 'card/card-tag'
 
+
+CARD_CLASS = vars.read 'card/card-class'
+FLIPPABLE_CLASS = vars.read 'card/card-flippable-class'
+FLIPPED_CLASS = vars.read 'card/card-flipped-class'
+FLIPPING_CLASS = vars.read 'card/card-flipping-class'
+FLIP_TIME = vars.readTime 'card/card-flip-time'
 
 
 ###*

#
# @module stout-ui/card/CardView
###
defaults        = require 'lodash/defaults'
InteractiveView = require '../interactive/InteractiveView'
template        = require './card.template'
vars            = require '../vars'

# Require shared input variables.
require '../vars/card'

  constructor: (init, events) ->
    defaults init, {template, tagName: TAG_NAME}
    super init, events
    @prefixedClasses.add CARD_CLASS

    @on 'ready', =>
      if @select('.ui-card-back')
        @flippable = true
        @prefixedClasses.add FLIPPABLE_CLASS


  @property 'flippable',
    default: false


  @property 'flipping',
    default: false


  @property 'flipped',
    default: false


  @property 'sideVisible',
    default: 'front'
    values: ['front', 'back']


  ###*
  # Flips the card, if it's flippable.
  #
  # @method flip
  # @memberof stout-ui/card/CardView
  ###
  flip: ->
    new Promise (fulfill, reject) =>
      if not @flippable then reject(
        new TransitionCanceledExc "Card not flippable.")
      if @flipping then reject(
        new TransitionCanceledExc "Card currently flipping.")
      @flipping = true
      @prefixedClasses.add FLIPPING_CLASS
      if @flipped
        @prefixedClasses.remove FLIPPED_CLASS
      else
        @prefixedClasses.add FLIPPED_CLASS
      setTimeout =>
        @prefixedClasses.remove FLIPPING_CLASS
        @flipping = false
        @flipped = not @flipped
        fulfill()
      , FLIP_TIME
