import { m as b, u, l as v, n as w, o as $ } from "./app-Bpb4394e.js";
import { u as S } from "./feature-Cz6F0_cm.js";
import { useCoreStore as c } from "@feedmepos/mf-common";
import { defineStore as f } from "pinia";
import { ref as l, computed as d } from "vue";
const a = b((n, s) => {
  function i() {
    var o;
    const t = c(), r = u(), p = S().businessSupplierOnly, m = `business_${((o = t.currentBusiness.value) == null ? void 0 : o._id) ?? ""}`, y = r.currentLocation.dbName;
    return p ? m : y;
  }
  return {
    async readSuppliers() {
      const t = i(), r = `${n.inventoryBackendUrl}/${t}/supplier`;
      return await s.get(r);
    },
    async readLocationSuppliers() {
      const r = u().currentLocation.dbName, e = `${n.inventoryBackendUrl}/${r}/supplier`;
      return await s.get(e);
    },
    async readBusinessSuppliers() {
      var p;
      const r = `business_${((p = c().currentBusiness.value) == null ? void 0 : p._id) ?? ""}`, e = `${n.inventoryBackendUrl}/${r}/supplier`;
      return await s.get(e);
    },
    async createSupplier(t) {
      const r = i(), e = `${n.inventoryBackendUrl}/${r}/supplier`;
      return await s.post(e, t);
    },
    async importSuppliers(t) {
      const r = i(), e = `${n.inventoryBackendUrl}/${r}/supplier/import`;
      return await s.post(e, t);
    },
    async updateSupplier(t) {
      const r = i(), e = `${n.inventoryBackendUrl}/${r}/supplier`;
      return await s.put(e, t);
    },
    async deleteSupplier(t) {
      const r = i(), e = `${n.inventoryBackendUrl}/${r}/supplier`;
      return await s.delete(e, t);
    }
  };
}), L = f("supplier", () => {
  const n = S(), s = l(new Array()), i = l(new Array()), t = d(() => n.businessSupplierOnly ? i.value : [...s.value, ...i.value]), r = d(() => v(t.value, "_id"));
  return {
    async readSuppliers() {
      const e = a();
      s.value = await e.readLocationSuppliers(), i.value = await e.readBusinessSuppliers();
    },
    async createSupplier(e) {
      await a().createSupplier(e);
    },
    async updateSupplier(e) {
      await a().updateSupplier(e);
    },
    async deleteSupplier(e) {
      await a().deleteSupplier(e);
    },
    async importSuppliers(e) {
      await a().importSuppliers(e);
    },
    async init() {
      const e = w();
      try {
        await this.readSuppliers();
      } catch (p) {
        throw p instanceof $ || e.error("Error at reading suppliers"), p;
      }
    },
    suppliers: t,
    locationSuppliers: s,
    businessSuppliers: i,
    supplierById: r
  };
});
export {
  L as u
};
