'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _reactIntl = require('react-intl');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

exports.default = function (pluginContext) {
  var _ns2Role;

  var _pluginContext$inputC = pluginContext.inputComponents,
      CompoundInput = _pluginContext$inputC.CompoundInput,
      PermissionsInput = _pluginContext$inputC.PermissionsInput,
      TextInput = _pluginContext$inputC.TextInput;
  var config = pluginContext.configHelpers.configKey;


  return {
    'ns2:role': (_ns2Role = {}, _defineProperty(_ns2Role, config, {
      service: {
        ns: 'http://collectionspace.org/services/authorization'
      },
      view: {
        type: CompoundInput
      }
    }), _defineProperty(_ns2Role, '@csid', _defineProperty({}, config, {
      cloneable: false
    })), _defineProperty(_ns2Role, 'createdAt', _defineProperty({}, config, {
      cloneable: false
    })), _defineProperty(_ns2Role, 'updatedAt', _defineProperty({}, config, {
      cloneable: false
    })), _defineProperty(_ns2Role, 'metadataProtection', _defineProperty({}, config, {
      cloneable: false
    })), _defineProperty(_ns2Role, 'permsProtection', _defineProperty({}, config, {
      cloneable: false
    })), _defineProperty(_ns2Role, 'displayName', _defineProperty({}, config, {
      cloneable: false,
      messages: (0, _reactIntl.defineMessages)({
        name: {
          'id': 'field.authrole.displayName.name',
          'defaultMessage': 'Name'
        }
      }),
      required: true,
      view: {
        type: TextInput
      }
    })), _defineProperty(_ns2Role, 'description', _defineProperty({}, config, {
      messages: (0, _reactIntl.defineMessages)({
        name: {
          'id': 'field.authrole.description.name',
          'defaultMessage': 'Description'
        }
      }),
      view: {
        type: TextInput,
        props: {
          multiline: true
        }
      }
    })), _defineProperty(_ns2Role, 'roleName', _defineProperty({}, config, {
      compute: function compute(value, path, data) {
        // What should this do? REST API requires this field, but it seems like it just needs
        // to be something unique.

        var displayName = data.getIn(['ns2:role', 'displayName']);

        return displayName.toUpperCase().replace(/ /g, '_').replace(/[^A-Z0-9_]/g, '').replace(/__+/g, '_');
      }
    })), _defineProperty(_ns2Role, 'permission', _defineProperty({}, config, {
      defaultValue: _immutable2.default.List(),
      messages: (0, _reactIntl.defineMessages)({
        name: {
          'id': 'field.authrole.permission.name',
          'defaultMessage': 'Permissions'
        }
      }),
      view: {
        type: PermissionsInput
      }
    })), _ns2Role)
  };
};