import {
  z
} from "./chunk-55OQPFLF.js";

// src/components/LightboxImage.tsx
import styled from "@emotion/styled";
import {
  useEffect,
  useRef,
  useState
} from "react";
import { Fragment, jsx, jsxs } from "@emotion/react/jsx-runtime";
var LightboxImage = ({ children }) => {
  const [isOpen, setIsOpen] = useState(false);
  const [boundingRect, setBoundingRect] = useState({
    x: 0,
    y: 0,
    width: 0,
    height: 0
  });
  const imageRef = useRef(null);
  const handleMouseUp = () => {
    setIsOpen(!isOpen);
  };
  const handleSetBoundingRect = (ref) => {
    var _a;
    const rect = (_a = ref.current) == null ? void 0 : _a.getBoundingClientRect();
    if (rect) {
      setBoundingRect({
        x: rect.x,
        y: rect.y,
        width: rect.width,
        height: rect.height
      });
    }
  };
  useEffect(() => {
    handleSetBoundingRect(imageRef);
  }, [imageRef]);
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(DummyImage, { isOpen, boundingRect }),
    /* @__PURE__ */ jsx(
      StyledImage,
      {
        isOpen,
        ref: imageRef,
        boundingRect,
        onMouseDown: () => handleSetBoundingRect(imageRef),
        onMouseUp: handleMouseUp,
        children
      }
    ),
    /* @__PURE__ */ jsx(Lightbox, { isOpen, onClick: handleMouseUp })
  ] });
};
var DummyImage = styled.div`
  ${(props) => props.isOpen ? `height: ${props.boundingRect.height}px; width: ${props.boundingRect.width}px;` : ``}
`;
var StyledImage = styled.div`
  display: flex;
  justify-content: start;
  align-items: center;
  z-index: ${z.modalContainer};

  animation-duration: 0.4s;
  animation-fill-mode: forwards;
  transition: all 0.2s ease-out;

  ${(props) => props.isOpen ? `
    animation-direction: normal;
    position: fixed;
    animation-name: zoomIn;
    pointer-events: none;
  ` : `
    &:hover {
      cursor: zoom-in;
    }
  `}

  img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  @keyframes zoomIn {
    from {
      ${(props) => {
  const { x, y, width, height } = props.boundingRect;
  return `
          top: ${y}px;
          left: ${x}px;
          width: ${width}px;
          height: ${height}px;
        `;
}}
    }
    to {
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      padding: 24px;
    }
  }
`;
var Lightbox = styled.div`
  transition: opacity 0.2s ease-out;
  position: fixed;
  opacity: 0;
  z-index: ${z.modalOverlay};
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  ${({ theme, isOpen }) => isOpen ? `
    opacity: 1;
    background: ${theme.bg};

    &:hover {
      cursor: zoom-out;
    }
  ` : `
    pointer-events: none;
  `}
`;

export {
  LightboxImage
};
