'use strict';

var angular = require('angular');
require('../modules');

angular
  .module('setting')
  .controller('FileCacheCtrl', FileCacheCtrl);

/**
 * @ngInject
 */
function FileCacheCtrl($scope, fileCacheService, $toast) {
  init();

  function init() {
    $scope.osType = ionic.Platform.platform();
    $scope.items = getItems();
    $scope.saveExpire = fileCacheService.saveExpire;
    $scope.clearFile = function () {
      fileCacheService.clearFile().then(function() {
        $toast.showShortCenter('清空缓存成功！');
      });
    };
    $scope.saveExpire = function() {
      fileCacheService.saveExpire($scope.expire.value);
    }

    $scope.expire = {};
    fileCacheService.getExpire().then(function(expire) {
      $scope.items.forEach(function(item) {
        if (item.value === expire) {
          $scope.expire = {
            value: item.value
          };
        }
      });
    });
  }

  function getItems() {
    var millien = 1000 * 60;

    return [{
      value: millien * 10,
      text: '10分钟'
    }, {
      value: millien * 30,
      text: '30分钟'
    }, {
      value: millien * 60 ,
      text: '1小时'
    }, {
      value: millien * 60 * 24,
      text: '1天'
    }]
  }

}

