import { jsx as A } from "react/jsx-runtime";
import { pubSubService as n, PUB_SUB_EVENTS as a } from "./index-pub-sub.js";
import { ActionBar as l } from "./index-ActionBar.js";
import { useState as f, useEffect as p } from "react";
const R = () => {
  const [o, s] = f({}), [u, m] = f(!1), [c, B] = f();
  return p(() => {
    n.$sub(a.reactActionBarAddMessage, ({
      id: t,
      priority: r,
      props: e
    }) => {
      const i = {
        ...o
      };
      i[t] = {
        priority: r,
        active: !0,
        actionBarProps: {
          template: "message",
          ...e
        }
      }, s(i);
    }), n.$sub(a.reactActionBarRemoveMessage, ({
      id: t
    }) => {
      if (o[t] !== void 0) {
        const e = o;
        e[t] = {
          ...e[t],
          active: !1
        }, s(e);
      }
    }), n.$sub(a.reactActionBarSetFooter, ({
      actionBarProps: t,
      priority: r
    }) => {
      const e = {
        ...o
      };
      e.ACTION_BAR_FOOTER = {
        priority: r || 100,
        active: !0,
        actionBarProps: {
          template: "footer",
          ...t
        }
      }, s(e);
    }), n.$sub(a.reactActionBarHideFooter, () => {
      const t = {
        ...o
      };
      delete t.ACTION_BAR_FOOTER, s(t);
    });
  }, []), p(() => {
    if (o) {
      let t = !1, r;
      for (const e in o) {
        const i = o[e];
        i !== void 0 && i.active && (t = !0, (r === void 0 || i.priority <= r.priority) && (r = i));
      }
      B(r), m(!!t);
    }
  }, [o]), A(l, {
    show: u,
    templateProps: c == null ? void 0 : c.actionBarProps
  });
};
export {
  R as ActionBarRoot
};
