from utils import center, double_line_separator
from utils.report_formatters import translate_pos_label

DATE_TIME_FMT = "%d/%m/%Y %H:%M:%S"


def report_default_header(title, pos_list, operator_id, period, current_datetime, store_id=None):
    title = center(title)
    separator = double_line_separator()
    pos_list = [pos_list] if type(pos_list) != list else pos_list
    selected_pos = "Todos" if type(pos_list) == list and len(pos_list) > 1 else pos_list[0]
    pos = translate_pos_label(pos_id=selected_pos)

    header = separator
    header += title
    if store_id:
        header += "Loja..........: {}".format(store_id.upper()) + "\n"
    header += "Data/hora.....: {}".format(current_datetime) + "\n"

    if period is not None:
        fiscal_date = "%02d/%02d/%04d" % (int(period[6:8]), int(period[4:6]), int(period[:4]))
        header += "Data fiscal...: {}".format(fiscal_date) + "\n"

    if operator_id is not None and selected_pos is not None:
        operator = operator_id if len(operator_id) > 0 else "Todos"
        header += "ID Operador ..: {} ({} # {})".format(operator, pos, selected_pos) + "\n"

    header += separator

    return header
