import { jsx as e } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { CONTAINER_CLASS_NAME as b, SIDEBAR_CONTAINER_CLASS_NAME as k, SECONDARY_NAV_CLASS_NAME as V, CONTENT_CONTAINER_CLASS_NAME as x, CONTENT_CONTAINER_MOBILE_CLASS_NAME as B } from "./constants.js";
/* empty css                                  */
import q from "./context/context.js";
import p from "./components/PaymentLinkSettingsContent/PaymentLinkSettingsContent.js";
import w from "./components/SettingsActionButtons/SettingsActionButtons.js";
import { useState as D, useEffect as F, useCallback as A, useMemo as u } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useResponsiveContainer as G, containerQueries as P } from "../../../../../hooks/useResponsiveContainer.js";
import H from "classnames";
import K from "./components/LoadingSkeleton/LoadingSkeleton.js";
import U from "./components/SettingsError/SettingsError.js";
import { ACCOUNT_MISCONFIGURATION as Y, WRONG_STORE_IDS as j } from "./utils/getSettingsErrorMessage.js";
import { Fragment as Q } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import { SecondaryNav as W } from "../../../../internal/SecondaryNav/SecondaryNav.js";
import { StoreSelector as z } from "../../../../internal/StoreSelector/StoreSelector.js";
import { Header as J } from "../../../../internal/Header/Header.js";
const X = "payByLink.settings.errors.couldNotLoadSettings", Ce = ({
  navigateBack: i,
  ...a
}) => {
  const {
    activeMenuItem: C,
    setSelectedMenuItem: g,
    selectedStore: _,
    isLoadingStores: n,
    isShowingRequirements: h,
    storesError: d,
    setSelectedStore: I,
    filteredStores: S,
    menuItems: r,
    isLoadingContent: N,
    allStores: o,
    themeError: L,
    termsAndConditionsError: y
  } = q(), t = G(P.down.xs), [m, l] = D(!1);
  F(() => {
    const s = !!(!t || t && r && r?.length === 1);
    l(s);
  }, [t, r]);
  const O = A(
    (s) => {
      l(s);
    },
    [l]
  ), R = A(() => {
    t && l(!1);
  }, [t]), E = u(() => {
    if (!(!o || o.length > 0 || n))
      return {
        errorCode: Y,
        type: "error",
        requestId: ""
      };
  }, [o, n]), f = u(() => {
    if (!(o && o?.length > 0 && S?.length !== 0 || n))
      return {
        errorCode: j,
        type: "error",
        requestId: ""
      };
  }, [o, S, n]), c = d ?? E ?? f, T = u(() => c ? /* @__PURE__ */ e(U, { error: c, onContactSupport: a.onContactSupport, errorMessage: X }) : null, [a.onContactSupport, c]), M = !!E || !!d || !!f;
  if (!r || r.length === 0) return null;
  const v = m && !L && !d && !y && !h;
  return /* @__PURE__ */ e("div", { className: b, children: [
    (!t || !m) && /* @__PURE__ */ e(J, { hideTitle: a.hideTitle, titleKey: "payByLink.settings.title" }),
    M ? T : /* @__PURE__ */ e(Q, { children: [
      /* @__PURE__ */ e("div", { className: H(x, { [B]: t && m }), children: r.length > 1 ? /* @__PURE__ */ e("div", { className: k, children: /* @__PURE__ */ e(
        W,
        {
          renderHeader: () => /* @__PURE__ */ e(
            z,
            {
              stores: S,
              selectedStoreId: _,
              setSelectedStoreId: I
            }
          ),
          contentVisible: m,
          loading: n,
          className: V,
          items: r,
          activeValue: C,
          onValueChange: g,
          onContentVisibilityChange: O,
          renderContent: (s) => /* @__PURE__ */ e(
            p,
            {
              activeMenuItem: s,
              isLoadingContent: N,
              navigateBack: i
            }
          ),
          renderLoadingContent: () => /* @__PURE__ */ e(K, { rowNumber: 3 })
        }
      ) }) : /* @__PURE__ */ e(
        p,
        {
          activeMenuItem: C,
          isLoadingContent: N,
          navigateBack: i
        }
      ) }),
      v && /* @__PURE__ */ e(
        w,
        {
          navigateBack: i || void 0,
          closeContent: t ? R : void 0
        }
      )
    ] })
  ] });
};
export {
  Ce as default
};
