import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";

var _dec, _dec2, _class, _class2, _temp;

import React from 'react';
import PropTypes from 'prop-types';
import withFiles from '../store/withFiles';
import { connect } from 'react-redux';
import { actions } from '../store/asset';
import convertAsset from '../utils/convertAsset';
var MigrateAsset = (_dec = withFiles({
  watch: 'feeles/*.asset.yml'
}), _dec2 = connect(function (store) {
  return {
    isCompatibleMode: store.asset.isCompatibleMode
  };
}, actions), _dec(_class = _dec2(_class = (_temp = _class2 =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(MigrateAsset, _React$PureComponent);

  function MigrateAsset() {
    _classCallCheck(this, MigrateAsset);

    return _possibleConstructorReturn(this, _getPrototypeOf(MigrateAsset).apply(this, arguments));
  }

  _createClass(MigrateAsset, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.updateAssetDefinition();
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      this.updateAssetDefinition();
    }
    /**
     * 現行: アセット定義を setState する
     * 互換: 旧アセット定義を変換して使用する
     */

  }, {
    key: "updateAssetDefinition",
    value: function updateAssetDefinition() {
      var isCompatibleMode = this.props.isCompatibleMode;
      if (!isCompatibleMode) return; // 互換モード

      var configs = this.props.files.map(function (file) {
        return file.text + '';
      });
      var compatibleAsset = convertAsset(configs);
      this.props.setPackage(compatibleAsset);
    }
  }, {
    key: "render",
    value: function render() {
      return null;
    }
  }]);

  return MigrateAsset;
}(React.PureComponent), _defineProperty(_class2, "propTypes", {
  files: PropTypes.array.isRequired,
  isCompatibleMode: PropTypes.bool.isRequired,
  setPackage: PropTypes.func.isRequired
}), _temp)) || _class) || _class);
export { MigrateAsset as default };