/**
 * @author pei-qiao.peng
 * @date   2015/1/19.
 * @email  ppq1991@gmail.com
 * @github https://github.com/ppq1991/
 * @blog   http://pengpeiqiao.tk/
 */

Class(function(extend, using, self){
  'use strict';

  var $main = $('#flower-container');
  var $num = $('#flower-text');
  var $tip = $('#flower-tip');

  var cache_num = 0;

  self.run = function(){


  };

  function setFlowerNumber(n){
        cache_num = n;
        $num.text(n);
    }
  function getTimeFormat(t){
        if($.isNumeric(t)){
            if(t < 0){
                t = 0;
            }
            if(t < 60){
                $tip.css('width', '145px');
                return t + '秒';
            }else{
                $tip.css('width', '165px');
                return Math.floor(t / 60) + '分' + t % 60 + '秒';
            }
        }
    }
  function setTip(time){
        if(cache_num < 9){
            $tip.html('<p>还有 <span>' + getTimeFormat(time) + '</span> 获得一朵新鲜花</p><p>点击赠送,增加主播人气值!</p>');
        }else{
            $tip.html('<p>鲜花已满，请及时赠送</p><p>点击赠送,增加主播人气值!</p>').css('width', '140px');
        }
    }


  self.func(function(){
      window.remaintimechange = function(time){
          setTip(time);
      };

      window.flowerNumsChanged = function(id, num, time){
          setFlowerNumber(num);
          setTip(time);
      };

      $main.on('click', function () {
          window.freegift.sendFlowerNums(1, cache_num);
      });
  })

});