# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'form.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QGridLayout, QPushButton


class MapCell(object):

    def __init__(self, row, column, name):
        self._row = row
        self._column = column
        self._name = name

        self.set_highlight_colors()

        self._is_source_select = False
        self._is_destination_select = False
        self._is_path = False

    def set_highlight_colors(self):
        self.focus_in_source_color = "rgb(0, 255, 17)"
        self.focus_in_destination_color = "rgb(215, 238, 16)"
        self.focus_in_path_color = "rgb(178, 102, 255)"
        self.focus_out_color = "rgb(100, 100, 100)"

    def init_highlight(self):
        self._is_source_select = False
        self._is_destination_select = False
        self._is_path = False
        self.frame.setStyleSheet(" border: 1px solid %s" % self.focus_out_color)

    def remove_highlight(self, is_source=False, is_destination=False):
        if self._is_path:
            self.frame.setStyleSheet(" border: 1px solid %s " % self.focus_out_color)
            self._is_path = False
        if self._is_destination_select and is_destination:
            self.frame.setStyleSheet(" border: 1px solid %s " % self.focus_out_color)
            self._is_destination_select = False
        if self._is_source_select and is_source:
            self.frame.setStyleSheet(" border: 1px solid %s " % self.focus_out_color)
            self._is_source_select = False

    def highlight(self, is_source=False, is_destination=False):
        self._is_destination_select = is_destination
        self._is_source_select = is_source
        if self._is_destination_select:
            self.frame.setStyleSheet(" border: 1px solid %s " % self.focus_in_destination_color)
        if self._is_source_select:
            self.frame.setStyleSheet(" border: 1px solid %s " % self.focus_in_source_color)

    def highlight_path(self):
        # The map cell is source/destination do not change color
        if self._is_source_select or self._is_destination_select:
            return
        else:
            self._is_path = True
            self.frame.setStyleSheet(" border: 1px solid %s " % self.focus_in_path_color)


    def getCell(self):

        self.gridLayoutWidget = QtWidgets.QWidget()
        # self.gridLayoutWidget.setGeometry(QtCore.QRect(210, 130, 81, 21))
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.frame = QtWidgets.QFrame(self.gridLayoutWidget)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label = QtWidgets.QLabel(self.frame)
        # self.label.setGeometry(QtCore.QRect(0, 10, 20, 16))
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.frame, 0, 0, 1, 1)

        # _translate = QtCore.QCoreApplication.translate
        self.label.setText(self._name)

        self.init_highlight()

        return self.gridLayoutWidget

    def get_row(self) -> int:
        return self._row

    def get_column(self) -> int:
        return self._column
