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