from django import template
from django.templatetags.static import static

from ..choices import RIDE_CATEGORIES

register = template.Library()


@register.simple_tag
def get_ride_placeholder_image(category):
    """Return placeholder image based on ride category"""
    category_images = {
        "RC": "images/placeholders/roller-coaster.jpg",
        "DR": "images/placeholders/dark-ride.jpg",
        "FR": "images/placeholders/flat-ride.jpg",
        "WR": "images/placeholders/water-ride.jpg",
        "TR": "images/placeholders/transport.jpg",
        "OT": "images/placeholders/other-ride.jpg",
    }
    if category in category_images:
        return static(category_images[category])
    else:
        raise ValueError(f"Unknown ride category: {category}")


@register.simple_tag
def get_park_placeholder_image():
    """Return placeholder image for parks"""
    return static("images/placeholders/default-park.jpg")


@register.filter
def get_category_display(code):
    """Convert category code to display name"""
    choices = {choice.value: choice.label for choice in RIDE_CATEGORIES}
    if code in choices:
        return choices[code]
    else:
        raise ValueError(f"Unknown ride category code: {code}")
