from __future__ import annotations
import numpy as np
from PIL import Image

from pyWebLayout.core.base import Renderable, Queriable
from pyWebLayout.core import Geometric
from pyWebLayout.style import Alignment


class Box(Geometric, Renderable, Queriable):
    """
    A box with geometric properties (origin and size).

    Uses Geometric mixin for origin and size management.
    """

    def __init__(
            self,
            origin,
            size,
            callback=None,
            sheet: Image = None,
            mode: bool = None,
            halign=Alignment.CENTER,
            valign=Alignment.CENTER):
        super().__init__(origin=origin, size=size)
        self._end = self._origin + self._size
        self._callback = callback
        self._sheet: Image = sheet
        if self._sheet is None:
            self._mode = mode
        else:
            self._mode = sheet.mode
        self._halign = halign
        self._valign = valign

    # origin and size properties are provided by Geometric mixin

    def in_shape(self, point):
        return np.all((point >= self._origin) & (point < self._end), axis=-1)
