"use client";

import AddIcon from "@mui/icons-material/Add";
import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";

import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography";
import { alpha, useTheme } from "@mui/material/styles";

import {
  rgcDecisionText,
  type RgcDecisionLanguage,
} from "../data/rgc-decision-i18n";

type RgcDecisionHeaderProps = {
  language: RgcDecisionLanguage;
  onCreateRgc: () => void;
  onExport?: () => void;
};

export function RgcDecisionHeader({
  language,
  onCreateRgc,
  onExport,
}: RgcDecisionHeaderProps) {
  const theme = useTheme();
  const isDark = theme.palette.mode === "dark";

  const text =
    rgcDecisionText[language] ??
    rgcDecisionText.en;

  return (
    <Box
      sx={{
        mb: 3,
        display: "flex",
        alignItems: {
          xs: "stretch",
          md: "flex-start",
        },
        justifyContent: "space-between",
        gap: 2,
        flexDirection: {
          xs: "column",
          md: "row",
        },
      }}
    >
      <Box>
        <Typography
          component="h1"
          sx={{
            fontSize: {
              xs: 26,
              md: 32,
            },
            fontWeight: 700,
            color: theme.palette.text.primary,
            lineHeight: 1.15,
            mb: 0.75,
          }}
        >
          {text.title}
        </Typography>

        <Typography
          sx={{
            color: theme.palette.text.secondary,
            fontSize: 12,
            fontWeight: 500,
          }}
        >
          {text.breadcrumb}
        </Typography>
      </Box>

      <Box
        sx={{
          display: "flex",
          alignItems: "center",
          gap: 1.5,
          flexDirection: {
            xs: "column",
            sm: "row",
          },
        }}
      >
        <Button
          variant="outlined"
          onClick={onExport}
          startIcon={
            <FileDownloadOutlinedIcon
              sx={{ fontSize: 16 }}
            />
          }
          endIcon={
            <KeyboardArrowDownIcon
              sx={{ fontSize: 18 }}
            />
          }
          sx={{
            height: 40,
            px: 1.5,
            minWidth: {
              xs: "100%",
              sm: 116,
            },
            borderRadius: 1.5,
            borderColor: theme.palette.primary.main,
            color: theme.palette.primary.main,
            bgcolor: theme.palette.background.paper,
            fontSize: 13,
            textTransform: "none",
            justifyContent: "space-between",

            "&:hover": {
              bgcolor: isDark
                ? alpha(
                    theme.palette.primary.main,
                    0.12,
                  )
                : "#F0F7FF",
              borderColor:
                theme.palette.primary.main,
            },
          }}
        >
          {text.export}
        </Button>

        <Button
          type="button"
          variant="contained"
          onClick={onCreateRgc}
          startIcon={
            <AddIcon
              sx={{ fontSize: 16 }}
            />
          }
          sx={{
            height: 40,
            px: 2,
            minWidth: {
              xs: "100%",
              sm: 120,
            },
            borderRadius: 1.5,
            bgcolor: theme.palette.primary.main,
            fontSize: 13,
            fontWeight: 600,
            textTransform: "none",
            boxShadow: "none",

            "&:hover": {
              bgcolor: theme.palette.primary.dark,
              boxShadow: "none",
            },
          }}
        >
          {text.createRgc}
        </Button>
      </Box>
    </Box>
  );
}

export default RgcDecisionHeader;