'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

/* global window, Blob */

const contextTypes = {
  config: _propTypes2.default.object.isRequired
};

class ConfigPage extends _react.Component {
  constructor(props, context) {
    super(props, context);

    const config = this.context.config;


    const json = JSON.stringify(config);
    const blob = new Blob([json], { type: 'application/json' });
    const url = window.URL.createObjectURL(blob);

    this.state = {
      url
    };
  }

  componentDidMount() {
    const config = this.context.config;

    // eslint-disable-next-line no-console

    console.log(config);
  }

  componentWillUnmount() {
    window.URL.revokeObjectURL(this.state.url);
  }

  render() {
    return _react2.default.createElement(
      'p',
      null,
      _react2.default.createElement(
        'a',
        { href: this.state.url, download: 'cspace-ui-config.json' },
        'Save configuration'
      )
    );
  }
}

exports.default = ConfigPage;
ConfigPage.contextTypes = contextTypes;