;; Extension — video/audio media block.

(st-bootstrap-classes!)
(content/bootstrap!)
(content-bootstrap-markdown!)
(content-bootstrap-text!)
(content-bootstrap-media!)

(define v (mk-video "v" "/clip.mp4"))
(define a (mk-audio "a" "/song.mp3"))

;; ── identity ──
(content-test "media is block" (block? v) true)
(content-test "media? yes" (media? v) true)
(content-test "video type" (blk-type v) "media")
(content-test "video kind" (media-kind v) "video")
(content-test "audio kind" (media-kind a) "audio")

;; ── render ──
(content-test
  "video html"
  (asHTML v)
  "<video src=\"/clip.mp4\" controls></video>")
(content-test
  "audio html"
  (asHTML a)
  "<audio src=\"/song.mp3\" controls></audio>")
(content-test "video sx" (asSx v) "(video :src \"/clip.mp4\")")
(content-test "video text" (asText v) "")
(content-test "video markdown" (asMarkdown v) "[video](/clip.mp4)")
(content-test "audio markdown" (asMarkdown a) "[audio](/song.mp3)")

;; ── html escapes src ──
(content-test
  "media html escapes"
  (asHTML (mk-video "v" "/a.mp4?x=1&y=2"))
  "<video src=\"/a.mp4?x=1&amp;y=2\" controls></video>")

;; ── in a document ──
(define
  d
  (doc-append
    (doc-append (doc-empty "d") (mk-heading "h" 1 "Watch"))
    v))
(content-test
  "doc with media html"
  (asHTML d)
  "<h1>Watch</h1><video src=\"/clip.mp4\" controls></video>")

;; ── validation ──
(content-test
  "valid media"
  (content/valid? (doc-append (doc-empty "d") v))
  true)
(content-test
  "bad media kind flagged"
  (content/issue-kinds
    (doc-append (doc-empty "d") (mk-media "m" "movie" "/x")))
  (list "field"))
