from qtpy.QtCore import QPointF, QRectF

from ..box_widget import BoxWidget
from ..init_values import BoxHidding


class MovingBox:
    widget: BoxWidget
    from_pt: QPointF
    to_pt: QPointF
    final_rect: QRectF
    is_joining: bool
    is_wrapping: bool
    hidding_state: BoxHidding
    needs_move: bool

    def __init__(self, widget: BoxWidget):
        self.widget = widget
        self.from_pt = QPointF(*widget.top_left())
        self.to_pt = QPointF(*widget.top_left())
        self.final_rect = widget.after_wrap_rect().translated(self.to_pt)
        self.is_joining = False
        self.is_wrapping = False
        self.hidding_state = BoxHidding.NONE
        self.needs_move = False

    @property
    def is_useful(self) -> bool:
        if self.needs_move or self.is_wrapping:
            return True
        return self.hidding_state is not BoxHidding.NONE
    
    @property
    def max_distance(self) -> float:
        return max(abs(self.to_pt.x() - self.from_pt.x()),
                   abs(self.to_pt.y() - self.from_pt.y()))
