"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Trust/Trust.tsx
var Trust_exports = {};
__export(Trust_exports, {
  Trust: () => Trust
});
module.exports = __toCommonJS(Trust_exports);
var import_dedupe = __toESM(require("classnames/dedupe"));
var import_react = require("react");

// src/utils/mergeRefs.ts
function mergeRefs(refs) {
  return (value) => {
    refs.forEach((ref) => {
      if (typeof ref === "function") {
        ref(value);
      } else if (ref != null) {
        ref.current = value;
      }
    });
  };
}

// src/components/Trust/constants.ts
var REQUIRED_TRUSTPILOT_CLASS_NAME = "trustpilot-widget";
var SIMPLYBUSINESS_UNIT_ID = "5ca35a3da72b330001954cef";
var SIMPLYBUSINESS_UNIT_IDS = {
  "en-US": "5ca35a3da72b330001954cef",
  // US business unit ID
  "en-GB": "56b1db010000ff0005887125"
  // UK business unit ID
};
var TRUSTPILOT_LINKS = {
  "en-US": "https://www.trustpilot.com/review/simplybusiness.com",
  "en-GB": "https://www.trustpilot.com/review/simplybusiness.co.uk"
};
var TRUSTPILOT_TEMPLATE_IDS = {
  "micro-combo": "5419b6ffb0d04a076446a9af",
  mini: "53aa8807dec7e10d38f59f32",
  carousel: "53aa8912dec7e10d38f59f36",
  horizontal: "5406e65db0d04a09e042d5fc",
  "micro-star": "5419b732fbfb950b10de65e5"
};
var TRUSTPILOT_WIDGET = {
  // Keys based on actual widget names
  // https://support.trustpilot.com/hc/en-us/articles/360019826379-TrustBox-widget-overview
  "micro-combo": {
    templateId: TRUSTPILOT_TEMPLATE_IDS["micro-combo"],
    className: "--is-variant-micro-combo",
    styles: {
      height: "25px"
    }
  },
  mini: {
    templateId: TRUSTPILOT_TEMPLATE_IDS["mini"],
    className: "--is-variant-mini",
    styles: {
      width: "300px",
      height: "150px"
    }
  },
  carousel: {
    templateId: TRUSTPILOT_TEMPLATE_IDS["carousel"],
    className: "--is-variant-carousel",
    styles: {
      height: "150px"
    }
  },
  horizontal: {
    templateId: TRUSTPILOT_TEMPLATE_IDS["horizontal"],
    className: "--is-variant-horizontal",
    styles: {
      height: "28px"
    }
  },
  "micro-star": {
    templateId: TRUSTPILOT_TEMPLATE_IDS["micro-star"],
    className: "--is-variant-micro-star",
    styles: {
      height: "24px"
    }
  }
};

// src/components/Trust/Trust.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var Trust = ({ ref, ...props }) => {
  const {
    elementType: Element = "div",
    variant,
    theme,
    locale,
    height,
    width,
    stars,
    className
  } = props;
  const [isMounted, setIsMounted] = (0, import_react.useState)(false);
  const trustRef = (0, import_react.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 = (0, import_dedupe.default)(
    "mobius",
    "mobius-trust",
    REQUIRED_TRUSTPILOT_CLASS_NAME,
    {
      [`--is-${theme}`]: theme,
      [variantClassName]: variant
    },
    className
  );
  (0, import_react.useEffect)(() => {
    const hasTrustpilotLoaded = trustRef.current && window?.Trustpilot && window?.Trustpilot.loadFromElement;
    if (isMounted && hasTrustpilotLoaded) {
      window.Trustpilot.loadFromElement(trustRef.current, true);
    }
  }, [isMounted]);
  (0, import_react.useEffect)(() => {
    setIsMounted(true);
  }, []);
  if (!isMounted) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    Element,
    {
      ref: mergeRefs([trustRef, ref]),
      className: classes,
      style: styles,
      ...dataProps,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        "a",
        {
          href: link,
          target: "_blank",
          rel: "noopener noreferrer",
          className: "mobius-trust__link",
          children: "Trustpilot"
        }
      )
    }
  );
};
//# sourceMappingURL=Trust.js.map
