"use strict";

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

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

var _modularityFront = _interopRequireDefault(require("modularity-front"));

var _reactMaterialize = require("react-materialize");

require("./CartPage.css");

var _API = _interopRequireDefault(require("../../Services/API"));

var _Repository = _interopRequireDefault(require("../../Services/Repository"));

var _UserService = _interopRequireDefault(require("../../Services/UserService"));

var _Step = _interopRequireDefault(require("@material-ui/core/Step"));

var _StepLabel = _interopRequireDefault(require("@material-ui/core/StepLabel"));

var _Button = _interopRequireDefault(require("@material-ui/core/Button"));

var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));

var _CustomTable = _interopRequireDefault(require("../../Modules/CustomTable"));

var _ViewOrder = _interopRequireDefault(require("../../HigherModules/ViewOrder"));

var _TonersalesInfo = _interopRequireDefault(require("../../Inputs/TonersalesInfo"));

require("./OrderPackage.css");

var _CircularProgress = _interopRequireDefault(require("@material-ui/core/CircularProgress"));

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }

function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var Module = _modularityFront.default.Module;

var OrderPackage =
/*#__PURE__*/
function (_Modularity$Module) {
  _inherits(OrderPackage, _Modularity$Module);

  function OrderPackage(props) {
    var _this;

    _classCallCheck(this, OrderPackage);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(OrderPackage).call(this, props));
    _this.state = {};
    _this.api = new _API.default('/orders', _this.Token.value);
    _this.addressRepo = new _Repository.default('addresses', _this.Token.value);
    _this.accountRepo = new _Repository.default('accounts', _this.Token.value);
    _this.OrdersRepo = new _Repository.default('orders', _this.Token.value);
    _this.userRepo = new _UserService.default({
      Token: function Token(t) {}
    });

    _this.Token.onUpdate(function (token) {
      return _this.handleToken(token);
    });

    console.log("hhh");

    _this.handleToken();

    return _this;
  }

  _createClass(OrderPackage, [{
    key: "getOrder",
    value: function getOrder() {
      var _this2 = this;

      var url = this.RoutingSystem.getRoute().url;
      var id = url.split('/order/')[1];
      this.OrdersRepo.setToken(this.Token.value);
      this.OrdersRepo.get(id).then(function (data) {
        _this2.setState({
          order: data
        });

        _this2.forceUpdate();
      });
    }
  }, {
    key: "routeMatch",
    value: function routeMatch() {
      return this.RoutingSystem.getRoute().url.startsWith(this.baseURL.value);
    }
  }, {
    key: "handleToken",
    value: function handleToken() {
      if (this.Token.value === "missing" && this.RoutingSystem.getRoute().url !== "/login" && this.routeMatch()) {
        this.CoreSystem.go('/login', {
          ref: this.RoutingSystem.getRoute().url
        }, true);
      }

      if (!this.Token.value) {
        return; // this.requestClientToken(this.Token.value);
      }

      this.api.setToken(this.Token.value);
      this.accountRepo.setToken(this.Token.value);
      this.addressRepo.setToken(this.Token.value);
      this.getOrder();
    }
  }, {
    key: "render",
    value: function render() {
      if (!this.state.order) return _react.default.createElement("div", {
        className: "loadin_container"
      }, _react.default.createElement(_reactMaterialize.Row, {
        className: "card"
      }, _react.default.createElement(_reactMaterialize.Col, {
        s: 12,
        className: "card-content"
      }, _react.default.createElement("div", {
        className: "loader"
      }, _react.default.createElement(_CircularProgress.default, null))), _get(_getPrototypeOf(OrderPackage.prototype), "render", this).call(this)));
      return _react.default.createElement("div", {
        className: "order_container"
      }, _react.default.createElement(_ViewOrder.default, {
        Order: this.state.order
      }), _get(_getPrototypeOf(OrderPackage.prototype), "render", this).call(this));
    }
  }]);

  return OrderPackage;
}(_modularityFront.default.Module);

OrderPackage.EditPosition = "center";
OrderPackage.Inputs = {
  Order: {
    type: Module.Types.Object
  },
  Token: {
    type: Module.Types.Text
  },
  baseURL: {
    type: Module.Types.Text,
    defaultValue: "/orders/:id"
  }
};
OrderPackage.Outputs = {};
OrderPackage.Category = "Sxoinas Packages";
var _default = OrderPackage;
exports.default = _default;