from BaseModels.admin_utils import Admin_GenericBaseIconStackedInline, Admin_BaseIconModel
from copy import deepcopy

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

class Admin_BaseModel(Admin_BaseIconModel):
    # def get_fieldsets(self, request, obj=None):
    #     fieldsets = [
    #         [None, {
    #             'classes': ['wide'],
    #             'fields': [
    #                 'name', 'enable',
    #             ]
    #         }]
    #     ]
    #
    #     if request.user.is_superuser:
    #         add_block = [
    #             'Служебная инфа', {
    #                 'classes': ['wide'],
    #                 'fields': [
    #                     'json_data'
    #                 ]
    #             }]
    #         fieldsets.append(add_block)
    #     return fieldsets

    save_on_top = True
    list_display = ['id', 'name', 'enable', 'order',
                    'modifiedDT', 'createDT']
    # list_editable = ['order']
    list_display_links = ('id', 'name')


class Admin_BaseBlock(Admin_BaseIconModel):
    pass
    def get_fieldsets(self, request, obj=None):
        fieldsets = super(Admin_BaseBlock, self).get_fieldsets(request, obj)
        return fieldsets

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]





from modeltranslation.admin import TranslationAdmin
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_BaseModel, AdminTranslationBase):
    pass
#
# class Admin_Trans_BaseModelViewPage(AdminTranslation_BaseIconModel):
#     pass

class Admin_Trans_BaseModelViewPage(Admin_BaseModelViewPage, AdminTranslationBase):
    pass