"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

/* global window, Blob */
const contextTypes = {
  config: _propTypes.default.object.isRequired
};

class ConfigPage extends _react.Component {
  constructor(props, context) {
    super(props, context);
    const {
      config
    } = this.context;
    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; // eslint-disable-next-line no-console

    console.log(config);
  }

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

  render() {
    return _react.default.createElement("div", null, _react.default.createElement("p", null, "UI configuration has been printed to the console."), _react.default.createElement("p", null, _react.default.createElement("a", {
      href: this.state.url,
      download: "cspace-ui-config.json"
    }, "Save configuration as JSON")));
  }

}

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