import { createDynamicMFStore as y } from "../../../../WindowBase/contexts/DynamicMFParmsContext/store.js";
import { getAreasDictionary as O, AREAS_DICCTIONARY as _ } from "../../../dictionary.js";
import { addLayoutItemToBreakPointIfNoExists as E } from "../../../../GridLayout/subcomponents/Responsive/responsiveUtils.js";
const d = 10, u = 10, h = 500, C = "areas", T = "admin", k = "layoutPros", w = "windows", L = "windowSelected", l = { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 1 }, I = { lg: 64, md: 48, sm: 32, xs: 24, xxs: 1 }, x = { lg: [], md: [], sm: [], xs: [], xxs: [] }, p = { xxs: 32, xs: 32, sm: 32, md: 32, lg: 32 }, D = {
  status: "init",
  moduleActions: [],
  cookies: { moduleCookies: {}, windowCookies: {} },
  loading: !1
}, S = {
  status: "init",
  zPopUpIndex: 0,
  layouts: x,
  // colapsedItems: {},
  // windowsLayoutIds: [],
  layoutItemsIds: [],
  currentLayoutId: "",
  breakpoints: l,
  cols: I,
  loadWindows: !1
}, R = (e) => {
  const t = `area_${(/* @__PURE__ */ new Date()).getTime()}_${(Math.random() * 1e3).toFixed(0)}`, n = e.getLabel(O(_.label_new_area));
  let o, r = `${n} 1`;
  for (let i = 1; i <= e.areasIds.length + 1; i++) {
    r = `${n} ${i + e.areasIds.length}`, o = !0;
    for (let s = 0; s < e.areasIds.length; s++)
      if (e.hashAreas[e.areasIds[s]].name === r) {
        o = !1;
        break;
      }
    if (o)
      break;
  }
  const a = {
    id: t,
    name: r,
    ...S
  };
  return e.areasIds.push(t), e.hashAreas[t] = a, e.currentModuleId = "", e.loadAreasFromNetwork && e.networkOperation({
    method: "POST",
    endPoint: "areas",
    data: { id: t, name: r },
    toastSuccess: !1,
    toastError: !1
  }), t;
}, f = (e, t) => {
  try {
    if (Array.isArray(t)) {
      let n = t.find((o) => o.id === e);
      return n && (n = JSON.parse(n.value)), n;
    }
  } catch {
  }
};
function F(e, t, n) {
  const o = e.layouts;
  for (const r in o) {
    const a = o[r], i = a.findIndex((s) => s.i === t);
    i > -1 && (r !== "xxs" ? a[i].colapsed = n : a[i].freeMove || (a[i].colapsed = n));
  }
}
function b(e, t) {
  const n = e.layouts;
  for (const o in n) {
    const r = n[o];
    for (let a = 0; a < r.length; a++)
      if (r[a].i === t) {
        r.splice(a, 1);
        break;
      }
  }
}
function B(e, t, n) {
  let o = f(k, e);
  const r = f(w, e), a = [], i = [];
  o || (o = {});
  for (const s in l)
    o[s] || (o[s] = []);
  if (r) {
    for (const s in r) {
      const c = r[s];
      if (c && c.moduleCount && // element['layoutProps'] && //Garantizar que venga con los LayoutProps de la venta
      c.mfProps && //Garantizar que venga con los mfProps de la venta
      c.emergeType === "layout" && c.winType === "microfrontend") {
        a.push(s);
        const m = t.areaActions.closeLayout;
        t.hashWindows[s] = {
          ...D,
          ...c,
          windowId: s,
          emergeType: "layout",
          areaId: n,
          dynamicMFStore: y({
            dynamicMFParameters: c.dynamicParams
          }),
          onClose: () => m(n, s)
        }, i.push(s);
        for (const A in l)
          E(
            o,
            A,
            { i: c.windowId, x: 0, y: 0, w: 5, h: 5 },
            I,
            [u, u],
            [d, d],
            p
          );
      }
    }
    for (const s in l)
      o[s] = o[s].filter((c) => a.indexOf(c.i) > -1);
  } else
    for (const s in l)
      o[s] = [];
  return {
    newBreakPointsLayouts: o,
    newHashLayoutItems: i
    // baseResponsiveLayoutItems,
  };
}
function M(e, t) {
  const n = {};
  try {
    if (Array.isArray(e))
      for (let o = 0; o < e.length; o++)
        e[o]?.container_id === t && e[o]?.id && (n[e[o]?.id] = JSON.parse(e[o].value));
  } catch {
  }
  return n;
}
function W(e) {
  return typeof e?.data?.[0]?.value == "string" && JSON.parse(e?.data?.[0]?.value || "{}")?.selectedAreaId;
}
export {
  l as BREAKPOINT_SIZES,
  C as COOKIE_AREAS_ADMIN_CONTAINER_ID,
  T as COOKIE_AREAS_ADMIN_ID,
  k as COOKIE_BREAKPOINT_LAYOUTS,
  w as COOKIE_WINDOWS,
  L as COOKIE_WINDOW_SELECTED,
  h as DEBOUCED_SAVE_TIME,
  S as DEFAULT_AREA,
  x as DEFAULT_LAYOUTS,
  D as DEFAULT_WINDOW,
  u as MARGIN_GRIDLAYOUT,
  I as NORMALIZED_COLS,
  d as PADDING_GRIDLAYOUT,
  p as RESPONSIVE_ROW_HEIGHTS,
  R as addArea,
  b as deleteLayoutFromBreakPoints,
  M as getCookiesContainer,
  B as getDataFromResponse,
  f as getParmsFromValue,
  W as getSelectedAreaIdFromCookies,
  F as setColapsedLayoutBreakPoints
};
