# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _


import django_tables2 as tables


from . import models


class MailboxTable(tables.Table):
    class Meta:
        model = models.Mailbox
        attrs = {"class": "paleblue"}

# FIXEM: translation in inline templates are ignored
_('self')

class OutboxCsvTable(tables.Table):
    official_sender = tables.Column(accessor='document.sender.get_full_name',
            verbose_name=_('official_sender_header'))
    recipients = tables.Column(accessor='document.recipients',
            verbose_name=_('recipients_header'))
    real_sender = tables.TemplateColumn(
            '{% load i18n %}{% if record.document.real_sender %}{{ record.document.real_sender }}{% else %}{% trans "self" %}{% endif %}',
            verbose_name=_('real_sender_header'))
    filetype = tables.Column(accessor='document.filetype',
            verbose_name=_('type_header'))
    filenames = tables.Column(accessor='document.filenames',
            verbose_name=_('filename_header'), orderable=False)
    date = tables.Column(accessor='document.date',
            verbose_name=_('date_header'))


    class Meta:
        model = models.Mailbox
        fields = ('official_sender',)
        sequence = ('recipients', 'official_sender', 'real_sender', 'filetype', 'filenames', '...')
        attrs = {"class": "paleblue mailbox-table"}
        empty_text = _('No message')

class OutboxTable(tables.Table):
    official_sender = tables.Column(accessor='document.sender.get_full_name',
            order_by=('document__sender__last_name',
                'document__sender__first_name',
                'document__sender__username'),
            verbose_name=_('official_sender_header'))
    recipients = tables.Column(accessor='document.recipients',
            verbose_name=_('recipients_header'))
    real_sender = tables.TemplateColumn(
            '{% load i18n %}{% if record.document.real_sender %}{{ record.document.real_sender }}{% else %}{% trans "self" %}{% endif %}',
            order_by=('document__real_sender',),
            verbose_name=_('real_sender_header'))
    filetype = tables.Column(accessor='document.filetype',
            verbose_name=_('type_header'))
    filenames = tables.Column(accessor='document.filenames',
            verbose_name=_('filename_header'), orderable=False)
    date = tables.Column(accessor='document.date',
            verbose_name=_('date_header'))
    delete = tables.TemplateColumn(template_name='docbow/outbox_delete_column.html',
            orderable=False,
            verbose_name=' ')


    class Meta:
        model = models.Mailbox
        fields = ('official_sender',)
        sequence = ('recipients', 'official_sender', 'real_sender', 'filetype', 'filenames', '...')
        attrs = {"class": "paleblue mailbox-table"}
        empty_text = _('No message')


class InboxCsvTable(tables.Table):
    official_recipient = tables.Column(
            accessor='owner.get_full_name',
            verbose_name=_('official_recipient_header'))
    filetype = tables.Column(
            accessor='document.filetype',
            verbose_name=_('type_header'))
    filenames = tables.Column(
            accessor='document.filenames', verbose_name=_('filename_header'),
            orderable=False)
    sender = tables.Column(
            accessor='document.sender', verbose_name=_('sender_header'))
    date = tables.Column(
            accessor='document.date', verbose_name=_('date_header'))


    class Meta:
        model = models.Mailbox
        fields = ('official_recipient',)
        attrs = {"class": "paleblue mailbox-table"}
        empty_text = _('No message')


class InboxTable(tables.Table):
    seen = tables.BooleanColumn(accessor='seen', yesno=u' ,✔',  verbose_name=' ')
    official_recipient = tables.Column(
            accessor='owner.get_full_name',
            order_by=('owner__last_name', 'owner__first_name', 'owner__username'),
            verbose_name=_('official_recipient_header'))
    filetype = tables.Column(
            accessor='document.filetype',
            verbose_name=_('type_header'))
    filenames = tables.Column(
            accessor='document.filenames', verbose_name=_('filename_header'),
            orderable=False)
    sender = tables.Column(
            accessor='document.sender', verbose_name=_('sender_header'))
    date = tables.Column(
            accessor='document.date', verbose_name=_('date_header'))
    delete = tables.TemplateColumn(template_name='docbow/inbox_delete_column.html',
            orderable=False, verbose_name=' ')


    class Meta:
        model = models.Mailbox
        fields = ('seen',)
        attrs = {"class": "paleblue mailbox-table"}
        empty_text = _('No message')
