import {
  bannerTiming
} from "./chunk-E3FGOYEJ.js";
import {
  useResizeObserver
} from "./chunk-ZSWFGISK.js";
import {
  toReactNodes
} from "./chunk-OYIPFTQC.js";
import {
  z
} from "./chunk-55OQPFLF.js";
import {
  Icon
} from "./chunk-DMPXNHDT.js";
import {
  Link
} from "./chunk-SWMGDTQN.js";
import {
  getColor
} from "./chunk-VAH342U2.js";
import {
  bp
} from "./chunk-JSGRNWSB.js";
import {
  colors
} from "./chunk-MIIIUXV6.js";

// src/components/Banner/Banner.tsx
import styled from "@emotion/styled";
import { useEffect, useMemo, useState } from "react";
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
function Banner({
  content,
  to,
  color,
  maxMdContentJustify,
  offsetTop = 0,
  onHeightChange,
  right,
  left,
  fixed,
  bgProgressDuration,
  borderProgress,
  minHeight = 0,
  hPadding = 0,
  vPadding = 0,
  borderColor,
  blurScroll = false
}) {
  const [width, setWidth] = useState(70);
  const resizeProps = useMemo(() => ["height"], []);
  const { ref, rect } = useResizeObserver(resizeProps);
  useEffect(() => {
    if (bgProgressDuration) {
      setTimeout(() => {
        setWidth(100);
      }, 0);
    }
  }, [bgProgressDuration]);
  useEffect(() => {
    if (onHeightChange && typeof (rect == null ? void 0 : rect.height) === "number") {
      onHeightChange(rect.height);
    }
  }, [onHeightChange, rect == null ? void 0 : rect.height]);
  let contentNode = null;
  if (content) {
    const contentNodes = toReactNodes(content);
    if (to) {
      contentNode = /* @__PURE__ */ jsx(Link, { to, children: /* @__PURE__ */ jsxs(BannerFlexInnerContent, { children: [
        contentNodes,
        /* @__PURE__ */ jsx(Icon, { name: "ArrowRight", width: 12, ml: 6 })
      ] }) });
    } else {
      contentNode = contentNodes;
    }
  }
  const innerContent = content ? /* @__PURE__ */ jsx(
    BannerInnerContent,
    {
      isVisible: Boolean(content),
      maxMdContentJustify: maxMdContentJustify || "center",
      children: contentNode
    }
  ) : null;
  return /* @__PURE__ */ jsxs(
    StyledBanner,
    {
      colorProp: color,
      borderColor,
      isVisible: Boolean(content),
      offsetTop,
      hasSideContent: Boolean(right || left),
      ref,
      borderProgress,
      hPadding,
      vPadding,
      minHeight,
      fixed,
      blurScroll,
      children: [
        left,
        innerContent,
        right,
        bgProgressDuration && /* @__PURE__ */ jsx(
          BannerGradientBg,
          {
            duration: bgProgressDuration,
            width,
            isVisible: Boolean(content)
          }
        )
      ]
    }
  );
}
var BannerInnerContent = styled.div`
  z-index: 1;
  padding: ${({ isVisible }) => isVisible ? `0px 17.5px` : "0px"};
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  & > * {
    position: relative;
    z-index: 1;
    width: 100%;

    ${({ maxMdContentJustify }) => bp.maxMd(
  maxMdContentJustify ? `justify-content: ${maxMdContentJustify};` : ""
)};
  }
`;
var StyledBanner = styled.div`
  ${({ fixed }) => fixed ? "position: fixed; left: 0;" : ""};

  width: 100%;
  z-index: ${z.notificationBanner};
  color: ${colors.white};
  font-weight: 500;
  background-color: ${({ colorProp, theme }) => colorProp ? getColor(theme, colorProp) : "none"};
  ${({ blurScroll }) => blurScroll ? `
      background: rgba(249, 249, 249, 0.8);
      backdrop-filter: blur(32px);
      ` : ""}
  display: flex;
  justify-content: ${({ hasSideContent }) => hasSideContent ? "space-between" : "center"};
  align-items: center;
  padding: ${({ hPadding, vPadding }) => `${vPadding}px ${hPadding}px`};
  min-height: ${({ minHeight }) => typeof minHeight === "number" ? `${minHeight}px` : "auto"};
  ${({ borderColor, theme }) => borderColor ? `border-bottom: 1px solid ${getColor(theme, borderColor)};` : ""}

  ${({ borderProgress }) => {
  if (typeof borderProgress === "number") {
    return `
        &:before {
          content: "";
          position: absolute;
          left: 0;
          width: 100%;
          background-color: #C1C5CD;
          top: 0;
          height: 4px;
          ${bp.sm(`
            height: 2px;
            top: initial;
            bottom: 0;
          `)}
        }
        &:after {
          content: "";
          position: absolute;
          bottom: 0;
          left: 0;
          width: ${borderProgress}%;
          background-color: #2B66C2;
          transition: width 0.3s ease-in;
          top: 0;
          height: 4px;
          ${bp.sm(`
            height: 2px;
            top: initial;
            bottom: 0;
          `)}
        }
      `;
  }
  return "";
}}

  ${bp.sm(`
    z-index: ${z.smBanner};
  `)}
`;
var BannerGradientBg = styled.div`
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  width: ${({ width }) => width}%;
  height: 100%;

  background: linear-gradient(
    90deg,
    #000000 -25.9%,
    #1b4077 14.55%,
    #a152c7 82.22%,
    #3f2e7e 115.32%
  );

  transition: all ${bannerTiming};
  height: ${({ isVisible }) => isVisible ? "auto" : "0"}px;

  transition: width ${({ duration }) => duration}s
    cubic-bezier(0.33, 0.54, 0.47, 0.87);
`;
var BannerFlexInnerContent = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
`;

export {
  Banner
};
