// Generated by CoffeeScript 1.12.7
var FalconIOFilepicker,
  extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  hasProp = {}.hasOwnProperty;

FalconIOFilepicker = (function(superClass) {
  extend(FalconIOFilepicker, superClass);

  function FalconIOFilepicker() {
    return FalconIOFilepicker.__super__.constructor.apply(this, arguments);
  }

  FalconIOFilepicker.prototype.type = function() {
    return 'falconio';
  };

  FalconIOFilepicker.prototype.readOpts = function() {
    FalconIOFilepicker.__super__.readOpts.call(this);
    return this.setDownloadManagerClass(FalconIODownloadManager);
  };

  FalconIOFilepicker.prototype.getCurrentTools = function(col) {
    var baseConfig, base_conf, bool, count, i, inst, j, len, len1, ref, ref1, that, tool, tools;
    baseConfig = ez5.session.getBaseConfig("plugin", "easydb-falconio-plugin");
    baseConfig = baseConfig.system || baseConfig;
    base_conf = baseConfig[this.type()] || {};
    bool = false;
    ref = base_conf.fio_instances || [];
    for (i = 0, len = ref.length; i < len; i++) {
      inst = ref[i];
      if (inst.active && inst.auth !== "") {
        bool = true;
      }
    }
    if (!ez5.session.hasSystemRight("root", "plugin.easydb-falconio-plugin.falconio")) {
      return;
    }
    if (!bool) {
      return;
    }
    if (!(col instanceof CollectionSelection)) {
      return tools;
    }
    count = col.getCount();
    if (count === 0) {
      return tools;
    }
    base_conf.send_files = true;
    base_conf.falconio_url = "https://api.falcon.io/publish/publishing/template?apikey=";
    tools = [];
    tool = [];
    count = col.getCount();
    that = this;
    ref1 = base_conf.fio_instances;
    for (j = 0, len1 = ref1.length; j < len1; j++) {
      inst = ref1[j];
      if (inst.active && inst.auth !== "") {
        tool.push(new ToolboxTool({
          group: col.getToolGroup(),
          name: col.getToolNamePrefix() + '.' + this.__type + '.download.' + inst.name,
          text: inst.name,
          run: function() {
            var k, len2, ref2, x;
            ref2 = base_conf.fio_instances;
            for (k = 0, len2 = ref2.length; k < len2; k++) {
              x = ref2[k];
              if (x.name === this.opts.text) {
                col.auth = x.auth;
              }
            }
            new that.__downloadManagerCls({
              collection: col
            }).startExport();
          }
        }));
      }
    }
    tools.push(new ToolboxTool({
      group: col.getToolGroup(),
      name: col.getToolNamePrefix() + '.' + this.__type + '.download',
      sort: "D:3",
      loca_key: "tool." + col.getToolNamePrefix() + '.' + this.__type + '.download',
      tools: tool,
      loca_key_attrs: {
        count: count
      },
      favorite: true
    }));
    return tools;
  };

  return FalconIOFilepicker;

})(Filepicker);

ez5.session_ready(function() {
  return Collection.registerPlugin(new FalconIOFilepicker());
});
