from typing import Optional

from flet.controls.base_control import control
from flet.controls.border_radius import BorderRadiusValue
from flet.controls.control import Control
from flet.controls.gradients import Gradient
from flet.controls.layout_control import LayoutControl
from flet.controls.types import BlendMode

__all__ = ["ShaderMask"]


@control("ShaderMask")
class ShaderMask(LayoutControl):
    """
    Applies a mask generated by a shader to its :attr:`content`.

    For example, it can be used to gradually fade out the edge of a control by
    using a :class:`~flet.LinearGradient` mask.

    ```python
    ft.ShaderMask(
        blend_mode=ft.BlendMode.MULTIPLY,
        shader=ft.LinearGradient(
            begin=ft.Alignment.CENTER_LEFT,
            end=ft.Alignment.CENTER_RIGHT,
            colors=[ft.Colors.WHITE, ft.Colors.BLACK],
            tile_mode=ft.GradientTileMode.CLAMP,
        ),
        content=ft.Image(
            src="https://picsum.photos/id/288/300/300",
            height=300,
            fit=ft.BoxFit.FILL,
        )
    ```
    """

    shader: Gradient
    """
    Use gradient as a shader.
    """

    content: Optional[Control] = None
    """
    The Control to which the :attr:`shader` is applied.
    """

    blend_mode: BlendMode = BlendMode.MODULATE
    """
    The blend mode to use when applying the shader to the :attr:`content`.
    """

    border_radius: Optional[BorderRadiusValue] = None
    """
    The radius of the mask.
    """
