import { Box, SxProps, Theme, Typography, useMediaQuery, useTheme } from "@mui/material";
import React from "react";

interface Props {
  children?: React.ReactNode;
  isExpanded?: boolean;
  onClick?: () => void;
  sx?: SxProps<Theme>;
  header: string;
}

export default function AccordMy({ children, isExpanded = false, onClick, sx, header }: Props) {
  const theme = useTheme();
  const upMd = useMediaQuery(theme.breakpoints.up("md"));
  const upSm = useMediaQuery(theme.breakpoints.up("sm"));
  return (
    <Box
      sx={{
        width: "100%",
        paddingBottom: "15px",
        overflow: "hidden",
        borderBottom: `1px solid ${theme.palette.grey2.main}`,
        boxShadow: `0px 100px 309px rgba(210, 208, 225, 0.24),
                            0px 41.7776px 129.093px rgba(210, 208, 225, 0.172525), 
                            0px 22.3363px 69.0192px rgba(210, 208, 225, 0.143066),
                            0px 12.5216px 38.6916px rgba(210, 208, 225, 0.12),
                            0px 6.6501px 20.5488px rgba(210, 208, 225, 0.0969343), 
                            0px 2.76726px 8.55082px rgba(210, 208, 225, 0.067
                              4749)`,
      }}
    >
      <Box
        sx={{
          width: "100%",
          backgroundColor: "transparent",
        }}
      >
        <Box
          onClick={onClick}
          sx={{
            paddingTop: "15px",
            paddingRight: "20px",
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            cursor: "pointer",
            userSelect: "none",
          }}
        >
          <Typography
            sx={{
              fontSize: upMd ? "18px" : "16px",
              lineHeight: upMd ? undefined : "19px",
              px: 0,
            }}
          >
            {header}
          </Typography>

          <Box
            sx={{
              display: "flex",
              justifyContent: "flex-end",
              height: "100%",
              alignItems: "center",
              gap: upSm ? "111px" : "17px",
            }}
          >
            <Box
              sx={{
                height: "100%",
                display: "flex",
                justifyContent: "center",
                alignItems: "center",
              }}
            >
              <svg
                style={{ transform: isExpanded ? "rotate(180deg)" : undefined }}
                xmlns="http://www.w3.org/2000/svg"
                width="32"
                height="33"
                viewBox="0 0 32 33"
                fill="none"
              >
                <path
                  d="M20.5 15.2949L16 20.2949L11.5 15.2949"
                  stroke="#757575"
                  strokeWidth="2"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                />
              </svg>
            </Box>
          </Box>
        </Box>
        {isExpanded && (
          <Box
            sx={{
              backgroundColor: "transparent",
              gap: "15px",
              paddingTop: "15px",
              ...sx,
            }}
          >
            {children}
          </Box>
        )}
      </Box>
    </Box>
  );
}
