import _createClass from "@babel/runtime/helpers/createClass";
import { makeAutoObservable } from 'mobx';
import Designer from './designer';
import DocumentModel from './documentModel';
var defaultPageSchema = {
  componentName: 'Page',
  packageName: 'Page',
  containerType: 'Page',
  isContainer: true,
  children: [],
  props: {
    style: ''
  },
  extraProps: {
    id: {
      type: 'JSRunFunction',
      value: 'node => node.id'
    },
    dataSource: {
      type: 'DataSource',
      value: {
        url: '',
        method: 'GET',
        requestHandler: {
          type: 'JSFunction',
          value: 'function requestHandler(params){return params}'
        },
        responseHandler: {
          type: 'JSFunction',
          value: 'function responseHandler(response) { return response.data }'
        }
      }
    }
  },
  lifeCycles: {},
  // 网络请求拦截器
  interceptors: {
    response: {
      type: 'JSFunction',
      value: "\n            /**\n             * axios \u54CD\u5E94\u62E6\u622A\u5668\n             * @responseData\uFF1A AxiosResponse['data']\n            */\n             function responseInterceptor(responseData){ \n                if (responseData.code !== '0') {\n                    return Promise.reject(responseData.msg)\n                } else {\n                    if (responseData.data.token) {\n                        localStorage.setItem('token', responseData.data.token)\n                    }\n                    return responseData.data\n                }\n            }"
    },
    request: {
      type: "JSFunction",
      value: "\n            function requestInterceptor(config) {\n                const token = localStorage.getItem('token')\n                if (token) {\n                    if (!config.headers) {\n                        config.headers = {}\n                    }\n                    config.headers.authorization = token;\n                }\n                return config;\n            }\n            "
    }
  }
};
var Project = /*#__PURE__*/function () {
  function Project(schema) {
    var _this = this;
    if (schema === void 0) {
      schema = defaultPageSchema;
    }
    this.designer = new Designer(this);
    this.documentModel = void 0;
    this.updateLifeCycles = function (name, value) {
      _this.documentModel.updateLifeCycles(name, value);
    };
    this.getLifeCycles = function () {
      return _this.documentModel.lifeCycles;
    };
    this.updateInterceptors = function (name, value) {
      _this.documentModel.updateInterceptors(name, value);
    };
    this.getInterceptors = function () {
      return _this.documentModel.interceptors;
    };
    makeAutoObservable(this, {
      designer: false,
      documentModel: false
    });
    this.documentModel = new DocumentModel(this, schema);
  }
  var _proto = Project.prototype;
  _proto.setSchema = function setSchema(schema) {
    this.documentModel.open(schema);
  };
  _createClass(Project, [{
    key: "schema",
    get: function get() {
      return this.documentModel.schema;
    }
  }, {
    key: "componentsMap",
    get: function get() {
      return {};
    }
  }]);
  return Project;
}();
export { Project as default };