{{/*
canvas-file-extended: Full-featured shortcode for Canvas-protected files.
Supports all parameters — they are all optional.
Named parameters:
path - (required) Hugo-relative path, e.g. "static/slides/lecture1.pdf"
title - Link text (defaults to filename)
description - Accessible description / tooltip
icon - Icon hint: "pdf", "video", "zip", "doc", or "file" (default)
class - Extra CSS classes on the element
canvas_folder - Override the Canvas destination folder (advanced)
Positional fallback (for simple one-liner use):
{{< canvas-file-extended "static/slides/lecture1.pdf" "Title" >}}
*/}}
{{- $path := .Get "path" | default (.Get 0) -}}
{{- $title := .Get "title" | default (.Get 1) | default (path.Base $path) -}}
{{- $description := .Get "description" | default "" -}}
{{- $iconHint := .Get "icon" | default "file" -}}
{{- $extraClass := .Get "class" | default "" -}}
{{- $record := index .Site.Data.canvas_urls $path -}}
{{/* Map icon hint to emoji; instructors can override via CSS */}}
{{- $icons := dict
"pdf" "📄"
"video" "🎥"
"zip" "🗜"
"doc" "📝"
"file" "📁"
-}}
{{- $iconEmoji := index $icons $iconHint | default "📁" -}}
{{- $baseClass := printf "canvas-file canvas-file--extended canvas-file--%s %s" $iconHint $extraClass | strings.TrimRight " " -}}
{{- if $record -}}
{{ $iconEmoji }}
{{- $title -}}
🔒
{{- else if eq hugo.Environment "production" -}}
{{- errorf "hugo-canvas-sync: No Canvas URL for %q. Run `hugo-canvas-sync sync` before building for production." $path -}}
{{- else -}}
{{- $localHref := printf "/%s" $path -}}
{{ $iconEmoji }}
{{- $title -}}
🔓 DEV MODE
{{- end -}}