import { computed as u } from "vue";
import { S as c, n as i, u as f } from "./vue-i18n-pKrrGi-M.js";
import { useSnackbar as d } from "@feedmepos/ui-library";
import { useCoreStore as l } from "@feedmepos/mf-common";
function g(t) {
  return Array.isArray(t) ? t : [];
}
function R(t) {
  const { rules: n, action: a, restaurantId: e } = t;
  if (!n.length) return !1;
  const s = {
    action: a,
    subject: c.restaurant
  };
  return e ? i(s, n, { restaurantId: e }).granted : i([s], n).granted;
}
function h(t) {
  const { integrationRestaurantIds: n, rules: a, action: e } = t;
  if (!Array.isArray(n) || n.length === 0)
    return [];
  const s = [];
  for (const o of n)
    typeof o == "string" && (R({ rules: a, action: e, restaurantId: o }) || s.push(o));
  return s;
}
function m(t) {
  return h({
    integrationRestaurantIds: t.integrationRestaurantIds,
    rules: t.rules,
    action: t.action
  }).length > 0;
}
function A() {
  const t = d(), { t: n } = f(), { sessionUser: a } = l(), e = u(
    () => {
      var r;
      return g((r = a.value) == null ? void 0 : r.permissions);
    }
  );
  function s(r) {
    t.open({
      type: "error",
      message: n("report.integration.error.containsUnauthorizedRestaurant", {
        action: n(`report.integration.permissionAction.${r}`)
      })
    });
  }
  function o(r) {
    return m({
      integrationRestaurantIds: r.integrationRestaurantIds,
      rules: e.value,
      action: r.action
    });
  }
  return {
    rules: e,
    notifyUnauthorized: s,
    isRestricted: o
  };
}
export {
  m as h,
  A as u
};
