# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _

from shuup.admin.utils.picotable import (
    Column, TextFilter, true_or_false_filter
)
from shuup.admin.utils.views import PicotableListView
from shuup.core.models import CustomerTaxGroup, Tax, TaxClass
from shuup.utils.i18n import format_percent


def _format_rate(tax_rule):
    if tax_rule.rate is None:
        return ""
    return format_percent(tax_rule.rate, digits=3)


class TaxListView(PicotableListView):
    model = Tax

    columns = [
        Column(
            "name", _("Name"), sort_field="translations__name",
            filter_config=TextFilter(
                filter_field="translations__name",
                placeholder=_("Filter by name..."),
            ),
        ),
        Column("code", _(u"Code")),
        Column("rate", _("Rate"), display=_format_rate),
        # Column("amount", _(u"Amount")),
        Column("enabled", _(u"Enabled"), filter_config=true_or_false_filter),
    ]


class CustomerTaxGroupListView(PicotableListView):
    model = CustomerTaxGroup

    columns = [
        Column(
            "name", _("Name"), sort_field="translations__name",
            filter_config=TextFilter(
                filter_field="translations__name",
                placeholder=_("Filter by name..."),
            ),
        ),
    ]


class TaxClassListView(PicotableListView):
    model = TaxClass

    columns = [
        Column(
            "name", _("Name"), sort_field="translations__name",
            filter_config=TextFilter(
                filter_field="translations__name",
                placeholder=_("Filter by name..."),
            ),
        ),
    ]

@@ -770,24 +770,32 @@
  = Tax%0A%0A    
+default_
 columns = %5B%0A
@@ -1343,24 +1343,32 @@
 xGroup%0A%0A    
+default_
 columns = %5B%0A
@@ -1691,16 +1691,24 @@
 ss%0A%0A    
+default_
 columns 

Modify taxes for dynamic columns