from __future__ import annotations
import numpy as np
from PIL import Image
from typing import Tuple, Union, List, Optional, Dict

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

class Box(Renderable, Queriable):

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

    @property
    def origin(self) -> np.ndarray:
        """Get the origin (top-left corner) of the box"""
        return self._origin
    
    @property
    def size(self) -> np.ndarray:
        """Get the size (width, height) of the box"""
        return self._size
    
    def in_shape(self, point):

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