// Generated by CoffeeScript 1.12.7
var ExportTransportWordpress,
  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;

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

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

  ExportTransportWordpress.prototype.getType = function() {
    if (ez5.version("6")) {
      return "easydb-wordpress-plugin:transport_wp";
    } else {
      return "wordpress";
    }
  };

  ExportTransportWordpress.prototype.isAllowed = function() {
    return ez5.session.hasSystemRight("root", "plugin.easydb-wordpress-plugin.wordpress");
  };

  ExportTransportWordpress.prototype.getDisplayType = function() {
    return $$("export.transport.wordpress.type|text");
  };

  ExportTransportWordpress.prototype.getDisplayIcon = function() {
    return $$("export.transport.wordpress.type|icon");
  };

  ExportTransportWordpress.prototype.getOptionsDisplay = function(data) {
    var baseConfig, i, len, ref, ref1, ref2, wp_inst, wp_inst_auth;
    if (!((ref = data.options) != null ? ref.wp_inst_uuid : void 0)) {
      return;
    }
    baseConfig = ez5.session.getBaseConfig("plugin", "easydb-wordpress-plugin");
    ref2 = ((ref1 = baseConfig.wordpress) != null ? ref1.wp_instances : void 0) || [];
    for (i = 0, len = ref2.length; i < len; i++) {
      wp_inst = ref2[i];
      wp_inst_auth = JSON.parse(wp_inst.auth);
      if (wp_inst_auth.uuid === data.options.wp_inst_uuid) {
        return [wp_inst.name];
      }
    }
  };

  ExportTransportWordpress.prototype.getOptions = function() {
    var baseConfig, fields, i, len, ref, ref1, wp_inst, wp_inst_auth, wp_inst_opts;
    fields = [];
    wp_inst_opts = [
      {
        text: $$("export.transport.wordpress.options.none"),
        value: null
      }
    ];
    baseConfig = ez5.session.getBaseConfig("plugin", "easydb-wordpress-plugin");
    ref1 = ((ref = baseConfig.wordpress) != null ? ref.wp_instances : void 0) || [];
    for (i = 0, len = ref1.length; i < len; i++) {
      wp_inst = ref1[i];
      wp_inst_auth = JSON.parse(wp_inst.auth);
      wp_inst_opts.push({
        text: wp_inst.name + " / " + wp_inst.url,
        value: wp_inst_auth.uuid
      });
    }
    if (wp_inst_opts.length === 0) {
      fields.push({
        type: CUI.Output,
        undo_and_changed_support: false,
        placeholder: $$("export.transport.wordpress.base_config_missing")
      });
    } else {
      fields.push({
        type: CUI.Select,
        undo_and_changed_support: false,
        name: "wp_inst_uuid",
        options: wp_inst_opts
      });
    }
    return fields;
  };

  ExportTransportWordpress.prototype.getSaveData = function(data) {
    var ref;
    console.debug("getSaveData", CUI.util.dump(data));
    if (!((ref = data.options) != null ? ref.wp_inst_uuid : void 0)) {
      throw new InvalidSaveDataException();
    }
    data.options.user_generated_displayname = ez5.session.user.getDisplayText();
  };

  return ExportTransportWordpress;

})(ExportTransportPlugin);

CUI.ready((function(_this) {
  return function() {
    return TransportsEditor.registerPlugin(new ExportTransportWordpress());
  };
})(this));
