import { jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import { Link } from "../../shared/Link";
import { colorToString } from "../../utils/colorToString";
import { SocialLinksOptions } from "./options";
import GutterContainer from "../../shared/GutterContainer";
import SocialLinksPlaceholder from "./components/SocialLinksPlaceholder";
import { cx } from "@emotion/css";
import { useStyle } from "../../../runtimes/react/use-style";
import { useResponsiveStyle } from "../../utils/responsive-style";
const SocialLinks = forwardRef(function SocialLinks2({
  id,
  links: { links, openInNewTab } = { links: [], openInNewTab: false },
  shape,
  size,
  hoverStyle,
  fill,
  backgroundColor,
  alignment,
  gutter,
  width,
  margin
}, ref) {
  return /* @__PURE__ */ jsx(
    "div",
    {
      ref,
      id,
      className: cx(
        useStyle({ display: "flex", flexDirection: "row", flexWrap: "wrap" }),
        width,
        margin,
        useStyle(
          useResponsiveStyle([alignment], ([alignment2 = "center"]) => ({
            justifyContent: alignment2
          }))
        )
      ),
      children: links.length > 0 ? links.map((link, i) => {
        const option = SocialLinksOptions.find((o) => o.type === link.payload.type);
        if (option == null)
          return null;
        return /* @__PURE__ */ jsx(
          GutterContainer,
          {
            gutter,
            first: i === 0,
            last: i === links.length - 1,
            children: /* @__PURE__ */ jsx(
              StyledLink,
              {
                backgroundColor,
                brandColor: option.brandColor,
                fill,
                hoverStyle,
                link: { type: "OPEN_URL", payload: { url: link.payload.url, openInNewTab } },
                shape,
                size,
                children: option.icon
              }
            )
          },
          link.id
        );
      }) : /* @__PURE__ */ jsx(SocialLinksPlaceholder, { gutter })
    }
  );
});
var SocialLinks_default = SocialLinks;
function StyledLink({
  className,
  brandColor,
  shape,
  size,
  hoverStyle,
  fill,
  backgroundColor,
  ...restOfProps
}) {
  return /* @__PURE__ */ jsx(
    Link,
    {
      ...restOfProps,
      className: cx(
        useStyle({
          display: "block",
          color: brandColor,
          transition: "transform, opacity 0.18s",
          svg: { display: "block" }
        }),
        useStyle(
          useResponsiveStyle(
            [shape, size, hoverStyle, fill, backgroundColor],
            ([shape2 = "naked", size2 = "medium", hoverStyle2 = "none", fill2, backgroundColor2]) => ({
              padding: shape2 === "naked" ? 0 : { small: 10, medium: 12, large: 14 }[size2],
              borderRadius: { circle: "50%", rounded: "8px", naked: 0, square: 0 }[shape2],
              background: shape2 === "naked" ? "transparent" : backgroundColor2 == null ? "currentColor" : colorToString(backgroundColor2),
              ":hover": {
                none: {},
                grow: { transform: "scale(1.1)" },
                shrink: { transform: "scale(0.9)" },
                fade: { opacity: 0.65 }
              }[hoverStyle2],
              svg: {
                fill: fill2 == null ? shape2 === "naked" || backgroundColor2 != null ? "currentColor" : "white" : colorToString(fill2),
                width: { small: 16, medium: 20, large: 24 }[size2],
                height: { small: 16, medium: 20, large: 24 }[size2]
              }
            })
          )
        ),
        className
      )
    }
  );
}
export {
  SocialLinks_default as default
};
//# sourceMappingURL=SocialLinks.js.map