"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _mobx = require("mobx");
var _services = _interopRequireDefault(require("../../services"));
var _utils = require("../../utils");
var _AppStore = _interopRequireDefault(require("../AppStore"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class QuickMessageStore {
  constructor() {
    _defineProperty(this, "isLoading", false);
    _defineProperty(this, "showModal", false);
    _defineProperty(this, "isError", false);
    _defineProperty(this, "currentMessage", {});
    _defineProperty(this, "data", []);
    (0, _mobx.makeAutoObservable)(this);
  }
  async getData(params, onSuccess, onError) {
    try {
      this.isLoading = true;
      const response = await _services.default.create().listQuickMessage(params);
      (0, _utils.Log)(response);
      if (response.status === 200) {
        if (response.data.status === 200) {
          if (response.data.data) {
            this.data = response.data.data;
            this.isLoading = false;
            this.isError = false;
            if (onSuccess) {
              onSuccess(this.data);
            }
          }
        }
      } else {
        this.isLoading = false;
        this.isError = true;
        if (onError) {
          onError('');
        }
      }
    } catch (error) {
      this.isLoading = false;
      this.isError = true;
      if (onError) {
        onError(JSON.stringify(error));
      }
      (0, _utils.Log)(error);
    }
  }
  async create(params, onSuccess, onError) {
    const response = await _services.default.create().createQuickMessage(params);
    (0, _utils.Log)(response);
    if (response.status === 200 || response.status === 201) {
      if (response.data.status === 200 || response.data.status === 201) {
        this.currentMessage = {};
        this.getData({});
        onSuccess();
      }
    }
  }
  async update(params, onSuccess, onError) {
    const response = await _services.default.create().updateQuickMessage(params);
    (0, _utils.Log)(response);
    if (response.status === 200) {
      if (response.data.status === 200) {
        this.currentMessage = {};
        this.getData({});
        onSuccess();
      }
    }
  }
  async delete(params, onSuccess, onError) {
    const response = await _services.default.create().deleteQuickMessage(params);
    (0, _utils.Log)(response);
    if (response.status === 200) {
      if (response.data.status === 200) {
        onSuccess();
        this.getData({});
      }
    }
  }
}
const quickMessageStore = new QuickMessageStore();
var _default = quickMessageStore;
exports.default = _default;
//# sourceMappingURL=QuickMessageStore.js.map