import React from "react";
import { Paper, Box, CircularProgress } from "@mui/material";

interface IframeDisplayProps {
  iframeUrl: string;
  iframeLoading: boolean;
  onIframeLoad: () => void;
}

export const IframeDisplay: React.FC<IframeDisplayProps> = ({
  iframeUrl,
  iframeLoading,
  onIframeLoad,
}) => {
  if (!iframeUrl) return null;

  return (
    <Paper
      elevation={1}
      sx={{ height: "calc(100vh - 280px)", position: "relative", p: 1 }}
    >
      {iframeLoading && (
        <Box
          sx={{
            position: "absolute",
            top: "50%",
            left: "50%",
            transform: "translate(-50%, -50%)",
            zIndex: 1,
          }}
        >
          <CircularProgress />
        </Box>
      )}
      <iframe
        src={iframeUrl}
        style={{
          width: "100%",
          height: "100%",
          border: "none",
          borderRadius: 8,
        }}
        onLoad={onIframeLoad}
        title="Demo Application"
      />
    </Paper>
  );
};
