from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
from .models import Hospital, Patient, Bed, PatientLog, Driver, Ambulance, AmbulanceTicket, Place
from django_google_maps import widgets as map_widgets
from django_google_maps import fields as map_fields
from django_json_widget.widgets import JSONEditorWidget
from django.db import models


#@admin.register(Bed)

@admin.register(AmbulanceTicket)
class AmbulanceTicketAdmin(admin.ModelAdmin):
    list_display = ('driver', 'ambulance', 'checkin_at', 'checkout_at', 'status')

@admin.register(Place)
class PlaceAdmin(admin.ModelAdmin):
    formfield_overrides = {
        map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget},
        models.JSONField: {'widget': JSONEditorWidget},
    }
    #pass
    #list_display = ('driver', 'ambulance', 'checkin_at', 'checkout_at', 'status')

@admin.register(Ambulance)
class AmbulanceAdmin(admin.ModelAdmin):
    list_display = ('code', 'license_plate', 'brand', 'status')

@admin.register(Driver)
class DriverAdmin(admin.ModelAdmin):
    pass

class BedAdmin(admin.TabularInline):
    model = Bed


class PatientLogAdmin(admin.StackedInline):
    model = PatientLog
    #fields = ('hospital', 'notes', 'condition_level', 'status')

@admin.register(Hospital)
class HospitalAdmin(OSMGeoAdmin):
    list_display = ('title', 'address', 'geolocation')
    inlines = [BedAdmin,]
    fields = ('title', 'address_text', 'address', 'geolocation',)
    formfield_overrides = {
        map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget},
    }



@admin.register(Patient)
class PatientAdmin(admin.ModelAdmin):
    formfield_overrides = {
        map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget},
    }
    inlines = [PatientLogAdmin,]
