import { jsx as o, jsxs as i, Fragment as L } from "react/jsx-runtime";
import R, { useState as x, useEffect as v } from "react";
import { Container as u, Grid as T, Label as M } from "semantic-ui-react";
import { PostProvider as _, PostConsumer as S, MediaProvider as j, MediaConsumer as B, PostIcon as H, utils as N } from "@devgateway/wp-react-lib";
import E from "../connected-templates/PostIntro.js";
import { useParams as V } from "react-router";
import k from "../connected-templates/PostContent.js";
const q = (f) => {
  const { posts: c, showIcons: w, showContentToggle: s, contentToggleHPosition: P, locale: C, readMoreLabel: d, readLessLabel: b } = f, [n, p] = x({}), l = R.createRef(), a = (t, e = "Read More") => t && t.trim() !== "" ? t : e;
  v(() => {
    window.setTimeout(
      () => {
        if (window.location.hash) {
          const t = document.getElementById(window.location.hash.substr(1));
          t && t.scrollIntoView({ behavior: "auto", block: "start" });
        }
      },
      0
    );
  }, [c]);
  const h = (t) => {
    const e = t.content ? t.content.rendered.split("<!--more-->") : [];
    return e.length > 1 ? e[1] : e[0];
  }, m = (t) => {
    const e = n[t] || !1, r = e ? a(b, "Read less") : a(d, "Read more");
    return /* @__PURE__ */ o("div", { children: /* @__PURE__ */ o("div", { style: {
      display: "flex",
      justifyContent: P < 33 ? "flex-start" : P < 66 ? "center" : "flex-end"
    }, children: /* @__PURE__ */ o("a", { className: "link", onClick: () => {
      l.current && e && (l.current.scrollIntoView({ behavior: "smooth", block: "start" }), l.current.scrollTop = 0), p({ ...n, [t]: !e });
    }, children: r }) }) });
  }, g = (t) => {
    const e = t.content ? t.content.rendered.split("<!--more-->") : [], r = e.length > 1 ? e[0] : null;
    return r ? r.trim() : null;
  }, y = (t) => {
    const e = t.content ? t.content.rendered.split("<!--more-->") : [];
    return e.length > 1 && e[1].trim().length > 0;
  };
  return /* @__PURE__ */ o(u, { fluid: !0, className: "inline list", children: c && c.map((t) => /* @__PURE__ */ i(T, { children: [
    w && /* @__PURE__ */ i(T.Column, { textAlign: "center", width: 1, children: [
      /* @__PURE__ */ o("a", { id: t.slug }),
      /* @__PURE__ */ o(
        j,
        {
          id: t.meta_fields && t.meta_fields.icon ? t.meta_fields.icon[0] : null,
          children: /* @__PURE__ */ o(B, { children: /* @__PURE__ */ o(H, { as: M }) })
        }
      )
    ] }),
    /* @__PURE__ */ i(T.Column, { width: w ? 15 : 16, children: [
      g(t) && /* @__PURE__ */ o(E, { as: u, fluid: !0, post: t, ref: l }),
      !g(t) && /* @__PURE__ */ o(
        k,
        {
          post: { content: { rendered: h(t) } },
          style: { clear: "both", display: "block" }
        }
      ),
      y(t) && /* @__PURE__ */ i(u, { children: [
        s && /* @__PURE__ */ i(L, { children: [
          !n[t.slug] && m(t.slug),
          /* @__PURE__ */ o(
            k,
            {
              post: { content: { rendered: h(t) } },
              style: {
                clear: "both",
                display: n[t.slug] ? "block" : "none"
              }
            }
          ),
          n[t.slug] && m(t.slug)
        ] }),
        !s && /* @__PURE__ */ o("a", { href: N.replaceLink(t.link, C), className: "link", children: a(d) })
      ] })
    ] })
  ] })) });
}, K = (f) => {
  const [c, w] = x(Math.random() * 99998 + 1), { locale: s } = V(), {
    "data-width": P,
    "data-height": C,
    "data-type": d,
    "data-taxonomy": b,
    "data-categories": n,
    "data-items": p,
    "data-color": l,
    "data-show-post-icons": a,
    "data-show-content-toggle": h,
    "data-content-toggle-h-position": m,
    //horizontal position
    "data-read-more-label": g,
    "data-read-less-label": y,
    parent: t,
    editing: e,
    component: r,
    unique: I
  } = f;
  return /* @__PURE__ */ o(u, { fluid: !0, children: /* @__PURE__ */ o(
    _,
    {
      type: d,
      locale: s,
      taxonomy: b,
      categories: n,
      store: "inline_list_" + t + "_" + I,
      page: 1,
      perPage: p,
      children: /* @__PURE__ */ o(S, { children: /* @__PURE__ */ o(
        q,
        {
          locale: s ?? "en",
          showIcons: a === "true",
          showContentToggle: h === "true",
          contentToggleHPosition: parseInt(m || "50", 10),
          readMoreLabel: g,
          readLessLabel: y
        }
      ) })
    }
  ) });
};
export {
  K as default
};
