from django.contrib import admin
from models import *


class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}


admin.site.register(Category, CategoryAdmin)


class SubcategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("title",)}


admin.site.register(Subcategory, SubcategoryAdmin)


class HoursInline(admin.TabularInline):
    "Easy editing of hours relations from the business entry page"
    extra = 1
    model = Hours


class DiningHoursInline(admin.TabularInline):
    "Easy editing of hours relations from the business entry page"
    extra = 2
    model = DiningHours


class BusinessPhotoInline(admin.TabularInline):
    "Easy editing of hours relations from the business entry page"
    extra = 6
    model = BusinessPhoto


class BusinessAdmin(admin.ModelAdmin):
    raw_id_fields = (
        "point",
        "post_office",
    )
    list_display = (
        "name",
        "point",
        "status",
    )
    list_filter = ("status", "categories", "subcategories")
    search_fields = (
        "name",
        "description",
    )
    prepopulated_fields = {"slug": ("name",)}
    inlines = [
        BusinessPhotoInline,
        HoursInline,
        DiningHoursInline,
    ]
    filter_horizontal = ("payment_accepted",)


admin.site.register(Business, BusinessAdmin)


class GuideAdmin(admin.ModelAdmin):
    list_display = (
        "title",
        "pub_date",
        "published",
        "featured",
    )
    list_filter = ("published", "featured")
    search_fields = (
        "title",
        "description",
    )
    prepopulated_fields = {"slug": ("title",)}
    filter_horizontal = ("businesses",)


admin.site.register(Guide, GuideAdmin)


class BranchAdmin(admin.ModelAdmin):
    raw_id_fields = ("point",)
    list_display = (
        "business",
        "name",
        "point",
    )
    search_fields = (
        "business",
        "name",
        "description",
    )
    prepopulated_fields = {"slug": ("name",)}
    inlines = [
        BusinessPhotoInline,
        HoursInline,
        DiningHoursInline,
    ]


admin.site.register(Branch, BranchAdmin)

admin.site.register(PaymentMethod)
admin.site.register(BusinessPhoto)
admin.site.register(Hours)
admin.site.register(Meal)
admin.site.register(Menu)
admin.site.register(DiningHours)
admin.site.register(Feature)
# admin.site.register(Link)
# admin.site.register(Reference)
# admin.site.register(Ad)
