from BaseModels.admin_utils import (Admin_GenericBaseIconStackedInline,
                                    Admin_BaseIconModel,
                                    Admin_BaseIconStackedInline,
                                    Admin_BaseIconTabularModel)
from modeltranslation.admin import (TranslationAdmin,
                                    TranslationGenericStackedInline,
                                    TranslationGenericTabularInline,
                                    TranslationTabularInline,
                                    TranslationStackedInline)
from copy import deepcopy
from django.forms import widgets


def sets_for_formfield_for_dbfield(field, db_field):
    if db_field.name in ['url', 'name', 'title', 'name_plural', 'but1_url', 'but2_url']:
        field.widget = widgets.TextInput(attrs={'style': 'width: 30%; height: 20px;'})
    if db_field.name in ['description', 'text', 'video_url', 'bg_video_url']:
        field.widget = widgets.Textarea(attrs={'style': 'width: 30%; height: 100px;'})
    if db_field.name in ['video_url', 'bg_video_url']:
        field.widget = widgets.TextInput(attrs={'style': 'width: 90%; '})
    return field


class AdminStacked_FAQitem(Admin_GenericBaseIconStackedInline):
    from GeneralApp.models import FAQitem
    model = FAQitem
    extra = 0
    fields = ['order', 'question', 'answer']

class Admin_BaseModel(Admin_BaseIconModel):
    pass
    # def get_fieldsets(self, request, obj=None):
    #     from BaseModels.inter import get_fieldsNames_of_model
    #     fields_names = get_fieldsNames_of_model(self.model)
    #
    #     fields = []
    #     if 'name' in fields_names:
    #         fields.append('name')
    #     if 'enable'in fields_names:
    #         fields.append('enable')
    #
    #     fieldsets = [
    #         [None, {
    #             'classes': ['wide'],
    #             'fields': fields
    #         }]
    #     ]
    #
    #     if request.user.is_superuser:
    #
    #         fields = []
    #         if 'json_data' in fields:
    #             fields.append('json_data')
    #
    #         if fields:
    #             add_block = [
    #                 'Служебная инфа', {
    #                     'classes': ['wide'],
    #                     'fields': fields
    #                 }]
    #             fieldsets.append(add_block)
    #     return fieldsets
    #
    # save_on_top = True
    #
    # def get_list_display(self, request, obj):
    #     list_display = ['id']
    #     if getattr(obj, 'name', None):
    #         list_display.append('name')
    #     if getattr(obj, 'enable', None):
    #         list_display.append('enable')
    #     if getattr(obj, 'order', None):
    #         list_display.append('order')
    #     if getattr(obj, 'modifiedDT', None):
    #         list_display.append('modifiedDT')
    #     if getattr(obj, 'createDT', None):
    #         list_display.append('createDT')
    #
    #     return list_display
    #
    # # list_editable = ['order']
    # list_display_links = ('id', 'name')



class Admin_BaseModelViewPage(Admin_BaseIconModel):
    pass
    # def get_fieldsets(self, request, obj=None):
    #     fieldsets = super(Admin_BaseModelViewPage, self).get_fieldsets(request, obj)
    #     # fieldsets = deepcopy(self.fieldsets)
    #     seo_block = (
    #         'SEO', {
    #             'classes': ['wide', 'collapse'],
    #             'fields': (
    #                 'seo_title', 'seo_description',
    #                 'seo_keywords',
    #                 'seo_text'
    #             )
    #         })
    #     # fieldsets[0][1]['fields'].append('url')
    #     fieldsets.append(seo_block)
    #     return fieldsets

    # def get_prepopulated_fields(self, request, obj=None):
    #     if 'url' in self.get_fieldsets(request, obj):
    #         return {"url": ("name",)}
    #     else:
    #         return {}
    #
    # inlines = [AdminStacked_FAQitem]






class AdminTranslationBase(TranslationAdmin):

    # def formfield_for_dbfield(self, db_field, **kwargs):
    #     field = super(AdminTranslation_BaseIconModel, self).formfield_for_dbfield(db_field, **kwargs)
    #     self.patch_translation_field(db_field, field, **kwargs)
    #     return field

    class Media:

        js = (
            'modeltranslation/js/force_jquery.js',
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
            'modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
        }


class Admin_Trans_BaseModel(Admin_BaseIconModel, AdminTranslationBase):
    pass
#
# class Admin_Trans_BaseModelViewPage(AdminTranslation_BaseIconModel):
#     pass

class Admin_Trans_BaseModelViewPage(Admin_BaseModelViewPage, AdminTranslationBase):
    pass

class Admin_Trans_GenericBaseIconStackedInline(TranslationGenericStackedInline, Admin_GenericBaseIconStackedInline):
    class Media:
        js = (
            'modeltranslation/js/force_jquery.js',
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
            'modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
        }

class Admin_Trans_GenericBaseIconTabularInline(TranslationGenericTabularInline, Admin_GenericBaseIconStackedInline):
    class Media:
        js = (
            'modeltranslation/js/force_jquery.js',
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
            'modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
        }


class Admin_Trans_BaseIconTabularInline(TranslationTabularInline, Admin_BaseIconTabularModel):
    class Media:
        js = (
            'modeltranslation/js/force_jquery.js',
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
            'modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
        }


class Admin_Trans_BaseIconStackedInline(TranslationStackedInline, Admin_BaseIconStackedInline):
    class Media:
        js = (
            'modeltranslation/js/force_jquery.js',
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
            'modeltranslation/js/tabbed_translation_fields.js',
        )
        css = {
            'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
        }