;; content-on-sx — video/audio media block.
;;
;; CtMedia holds a `kind` (video/audio) and `src`. Self-contained: answers
;; asHTML/asSx/asText/asMarkdown: so it composes with the render boundary with no
;; changes elsewhere. HTML src is htmlEscaped, SX src sxEscaped.
;;
;; Requires (loaded by harness): block.sx, doc.sx, render.sx (escapers);
;; markdown.sx / text.sx for those formats.

(define
  content-bootstrap-media!
  (fn
    ()
    (begin
      (st-class-define! "CtMedia" "CtBlock" (list "kind" "src"))
      (ct-def-method! "CtMedia" "kind" "kind ^ kind")
      (ct-def-method! "CtMedia" "src" "src ^ src")
      (ct-def-method! "CtMedia" "type" "type ^ #media")
      (ct-def-method!
        "CtMedia"
        "asHTML"
        "asHTML ^ '<' , kind , ' src=\"' , src htmlEscaped , '\" controls></' , kind , '>'")
      (ct-def-method!
        "CtMedia"
        "asSx"
        "asSx ^ '(' , kind , ' :src \"' , src sxEscaped , '\")'")
      (ct-def-method! "CtMedia" "asText" "asText ^ ''")
      (ct-def-method!
        "CtMedia"
        "asMarkdown:"
        "asMarkdown: nl ^ '[' , kind , '](' , src , ')'")
      true)))

(define
  mk-media
  (fn
    (id kind src)
    (st-iv-set!
      (st-iv-set!
        (st-iv-set! (st-make-instance "CtMedia") "id" id)
        "kind"
        kind)
      "src"
      src)))

(define
  media?
  (fn (b) (and (st-instance? b) (= (get b :class) "CtMedia"))))
(define media-kind (fn (b) (st-send b "kind" (list))))

(define mk-video (fn (id src) (mk-media id "video" src)))
(define mk-audio (fn (id src) (mk-media id "audio" src)))
