import Box from "@mui/material/Box";
import type { DocumentLockInfo } from "../../hooks/useDocumentLock";

/**
 * Warning banner shown when another user holds the document edit lock
 * (extracted from OfferDetail; shared by the document detail pages).
 * Renders nothing when the lock is free / held by the current user.
 *
 * `entityWord` is the Czech accusative for the document ("Nabídku" /
 * "Objednávku") — both are feminine, so the rest of the sentence is shared.
 */
export default function LockBanner({
  lockedBy,
  entityWord,
}: {
  lockedBy: DocumentLockInfo | null;
  entityWord: string;
}) {
  if (!lockedBy) return null;
  return (
    <Box
      sx={{
        bgcolor:
          "color-mix(in srgb, var(--mui-palette-warning-main) 15%, transparent)",
        border: 1,
        borderColor: "warning.main",
        borderRadius: 1,
        px: 2,
        py: 1.5,
        display: "flex",
        alignItems: "center",
        gap: 1,
        mb: 2,
        fontSize: "0.875rem",
        color: "warning.main",
      }}
    >
      <svg
        width="18"
        height="18"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        strokeWidth="2"
      >
        <rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
        <path d="M7 11V7a5 5 0 0 1 10 0v4" />
      </svg>
      <span>
        {entityWord} právě upravuje <strong>{lockedBy.full_name}</strong>.
        Můžete ji pouze prohlížet.
      </span>
    </Box>
  );
}
