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

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

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

  CustomDataTypeLinkColumnCSVImporterDestinationField.wikipediaLinkRegex = /\[\[(?!.+?:)([^\|\]\[]+)\|([^\|\]\[]+)\]\]|\[\[([^\|\]\[]+)\]\]/;

  CustomDataTypeLinkColumnCSVImporterDestinationField.prototype.initOpts = function() {
    CustomDataTypeLinkColumnCSVImporterDestinationField.__super__.initOpts.call(this);
    return this.mergeOpt("field", {
      check: CustomDataTypeLink
    });
  };

  CustomDataTypeLinkColumnCSVImporterDestinationField.prototype.supportsHierarchy = function() {
    return false;
  };

  CustomDataTypeLinkColumnCSVImporterDestinationField.prototype.formatValues = function(values) {
    var cdata, content, data, groups, i, language, len, value;
    data = [];
    for (i = 0, len = values.length; i < len; i++) {
      value = values[i];
      try {
        data.push(JSON.parse(value));
      } catch (error) {
        if (CUI.isString(value)) {
          cdata = {
            url: value
          };
          if (groups = CustomDataTypeLinkColumnCSVImporterDestinationField.wikipediaLinkRegex.exec(value)) {
            if (groups[3]) {
              cdata = {
                url: groups[3]
              };
            } else {
              cdata = {
                url: groups[1]
              };
              content = groups[2];
              switch (this._field.getTitleType()) {
                case "text-l10n":
                  language = ez5.loca.getLanguage();
                  cdata.text = {};
                  cdata.text[language] = content;
                  break;
                case "text":
                  cdata.text_plain = content;
              }
            }
          }
          if (CUI.parseLocation(cdata.url)) {
            data.push(this._field.__buildData(cdata));
          }
        }
      }
    }
    if (data.length === 0) {
      return void 0;
    } else if (data.length === 1) {
      return data[0];
    } else {
      return data;
    }
  };

  return CustomDataTypeLinkColumnCSVImporterDestinationField;

})(ObjecttypeCSVImporterDestinationField);
