import { bp } from "../../styles/breakpoints.js";
import { colors } from "../../styles/colors.js";
import { getColor } from "../../styles/themes.js";
import { Link } from "../../router.js";
import { Icon } from "../Icon/Icon.js";
import { toReactNodes } from "../../utils/toReactNodes/toReactNodes.js";
import { useResizeObserver } from "../../hooks/useResizeObserver.js";
import { z } from "../../styles/z-index.js";
import { bannerTiming } from "./constants.js";
import styled from "@emotion/styled";
import { useEffect, useMemo, useState } from "react";
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
//#region src/components/Banner/Banner.tsx
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 { ref, rect } = useResizeObserver(useMemo(() => ["height"], []));
	useEffect(() => {
		if (bgProgressDuration) setTimeout(() => {
			setWidth(100);
		}, 0);
	}, [bgProgressDuration]);
	useEffect(() => {
		if (onHeightChange && typeof rect?.height === "number") onHeightChange(rect.height);
	}, [onHeightChange, 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;
	}
	return /* @__PURE__ */ jsxs(StyledBanner, {
		colorProp: color,
		borderColor,
		isVisible: Boolean(content),
		offsetTop,
		hasSideContent: Boolean(right || left),
		ref,
		borderProgress,
		hPadding,
		vPadding,
		minHeight,
		fixed,
		blurScroll,
		children: [
			left,
			content ? /* @__PURE__ */ jsx(BannerInnerContent, {
				isVisible: Boolean(content),
				maxMdContentJustify: maxMdContentJustify || "center",
				children: contentNode
			}) : null,
			right,
			bgProgressDuration && /* @__PURE__ */ jsx(BannerGradientBg, {
				duration: bgProgressDuration,
				width,
				isVisible: Boolean(content)
			})
		]
	});
}
const 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};` : "")};
  }
`;
const 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};
  `)}
`;
const 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);
`;
const BannerFlexInnerContent = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
`;
//#endregion
export { Banner };
