"""Small matplotlib replacement for the MATLAB arrowhead helper."""

from __future__ import annotations

from typing import Sequence

import matplotlib.pyplot as plt
from matplotlib.axes import Axes
from matplotlib.patches import FancyArrowPatch


def arrowhead(
    x: Sequence[float],
    y: Sequence[float],
    color: str = "k",
    scale: Sequence[float] | None = None,
    linewidth: float = 1.0,
    ax: Axes | None = None,
) -> FancyArrowPatch:
    ax = ax or plt.gca()
    mutation_scale = 13.0 * (float(scale[0]) if scale else 1.0)
    patch = FancyArrowPatch(
        (x[-2], y[-2]),
        (x[-1], y[-1]),
        arrowstyle="-|>",
        mutation_scale=mutation_scale,
        color=color,
        linewidth=linewidth,
        shrinkA=0,
        shrinkB=0,
    )
    ax.add_patch(patch)
    return patch
