from reportlab.lib import colors
from reportlab.lib.pagesizes import A4, landscape
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

PAGE_SIZE = landscape(A4)

styles = getSampleStyleSheet()

TITLE = ParagraphStyle(
    "TITLE",
    fontSize=16,
    alignment=1,
    spaceAfter=10,
    fontName="Helvetica-Bold"
)

HEADER = ParagraphStyle(
    "HEADER",
    fontSize=12,
    spaceAfter=6,
    fontName="Helvetica-Bold"
)

NORMAL = ParagraphStyle(
    "NORMAL",
    fontSize=9,
    spaceAfter=3
)

TABLE_HEADER_BG = colors.HexColor("#cfeefc")
PERMISSION_BG = colors.HexColor("#BEFEF6")
PASS_BG = colors.HexColor("#BEFEF6")
FAIL_COLOR = colors.red


from reportlab.platypus import Flowable
from reportlab.lib.units import mm

class VerticalText(Flowable):
    def __init__(self, text, width=18, height=55, fontSize=7):
        Flowable.__init__(self)
        self.text = text
        self.width = width
        self.height = height
        self.fontSize = fontSize

    def wrap(self, availWidth, availHeight):
        return self.width, self.height

    def draw(self):
        canvas = self.canv
        canvas.saveState()

        # Move origin to top-left of cell
        canvas.translate(0, self.height)

        # Rotate text
        canvas.rotate(-90)

        canvas.setFont("Helvetica", self.fontSize)

        # Draw text INSIDE header cell
        canvas.drawString(2, 2, self.text)

        canvas.restoreState()

from decimal import Decimal, ROUND_HALF_UP

def round_no_decimal(value):
    if value is None or value == "":
        return ""
    return int(Decimal(str(value)).quantize(0, rounding=ROUND_HALF_UP))
