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); }
import { observable, action, makeAutoObservable } from 'mobx';
import services from "../../services";
import { Log } from "../../utils";
import appStore from '../AppStore';
class QuickMessageStore {
  constructor() {
    _defineProperty(this, "isLoading", false);
    _defineProperty(this, "showModal", false);
    _defineProperty(this, "isError", false);
    _defineProperty(this, "currentMessage", {});
    _defineProperty(this, "data", []);
    makeAutoObservable(this);
  }
  async getData(params, onSuccess, onError) {
    try {
      this.isLoading = true;
      const response = await services.create().listQuickMessage(params);
      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));
      }
      Log(error);
    }
  }
  async create(params, onSuccess, onError) {
    const response = await services.create().createQuickMessage(params);
    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.create().updateQuickMessage(params);
    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.create().updateQuickMessage(params);
    Log(response);
    if (response.status === 200) {
      if (response.data.status === 200) {
        onSuccess();
        this.getData({});
      }
    }
  }
}
const quickMessageStore = new QuickMessageStore();
export default quickMessageStore;
//# sourceMappingURL=QuickMessageStore.js.map