import {
  REQUIRED_TRUSTPILOT_CLASS_NAME,
  SIMPLYBUSINESS_UNIT_ID,
  SIMPLYBUSINESS_UNIT_IDS,
  TRUSTPILOT_LINKS,
  TRUSTPILOT_WIDGET
} from "./chunk-PM56R4PU.js";
import {
  mergeRefs
} from "./chunk-QGGILW3D.js";

// src/components/Trust/Trust.tsx
import classNames from "classnames/dedupe";
import { useEffect, useRef, useState } from "react";
import { jsx } from "react/jsx-runtime";
var Trust = ({ ref, ...props }) => {
  const {
    elementType: Element = "div",
    variant,
    theme,
    locale,
    height,
    width,
    stars,
    className
  } = props;
  const [isMounted, setIsMounted] = useState(false);
  const trustRef = useRef(null);
  const {
    templateId,
    className: variantClassName,
    styles
  } = TRUSTPILOT_WIDGET[variant];
  const link = TRUSTPILOT_LINKS[locale];
  const businessUnitId = SIMPLYBUSINESS_UNIT_IDS[locale] || SIMPLYBUSINESS_UNIT_ID;
  const dataProps = {
    "data-businessunit-id": businessUnitId,
    "data-locale": locale,
    "data-template-id": templateId,
    "data-theme": theme,
    "data-style-width": width || "100%",
    "data-style-height": height,
    "data-stars": stars
  };
  const classes = classNames(
    "mobius",
    "mobius-trust",
    REQUIRED_TRUSTPILOT_CLASS_NAME,
    {
      [`--is-${theme}`]: theme,
      [variantClassName]: variant
    },
    className
  );
  useEffect(() => {
    const hasTrustpilotLoaded = trustRef.current && window?.Trustpilot && window?.Trustpilot.loadFromElement;
    if (isMounted && hasTrustpilotLoaded) {
      window.Trustpilot.loadFromElement(trustRef.current, true);
    }
  }, [isMounted]);
  useEffect(() => {
    setIsMounted(true);
  }, []);
  if (!isMounted) return /* @__PURE__ */ jsx("div", { style: styles });
  return /* @__PURE__ */ jsx(
    Element,
    {
      ref: mergeRefs([trustRef, ref]),
      className: classes,
      style: styles,
      ...dataProps,
      children: /* @__PURE__ */ jsx(
        "a",
        {
          href: link,
          target: "_blank",
          rel: "noopener noreferrer",
          className: "mobius-trust__link",
          children: "Trustpilot"
        }
      )
    }
  );
};

export {
  Trust
};
//# sourceMappingURL=chunk-Y7HCLRAD.js.map
