;; Checkout return page components

(defcomp ~checkout/return-header (&key (status :as string))
  (header :class "mb-1 sm:mb-2 flex flex-col sm:flex-row sm:items-center justify-between gap-3 sm:gap-4"
    (div :class "space-y-1"
      (h1 :class "text-xl sm:text-2xl md:text-3xl font-semibold tracking-tight"
        (cond
          ((= status "paid") "Payment received")
          ((= status "failed") "Payment failed")
          ((= status "missing") "Order not found")
          (t (str "Payment status: " (capitalize status)))))
      (p :class "text-xs sm:text-sm text-stone-600"
        (cond
          ((= status "paid") "Thanks for your order.")
          ((= status "failed") "Something went wrong while processing your payment. You can try again below.")
          ((= status "missing") "We couldn\u2019t find that order \u2013 it may have expired or never been created.")
          (t "We\u2019re still waiting for a final confirmation from SumUp."))))))

(defcomp ~checkout/return-missing ()
  (div :class "max-w-full px-1 py-1"
    (div :class "rounded-2xl border border-dashed border-rose-300 bg-rose-50/80 p-4 sm:p-6 text-sm text-rose-800"
      "We couldn\u2019t find that order. If you reached this page from an old link, please start a new order.")))

(defcomp ~checkout/return-failed (&key (order-id :as string))
  (div :class "rounded-2xl border border-rose-200 bg-rose-50/80 p-4 sm:p-6 text-sm text-rose-900 space-y-2"
    (p :class "font-medium" "Your payment was not completed.")
    (p "You can go back to your cart and try checkout again. If the problem persists, please contact us and mention order "
      (span :class "font-mono" (str "#" order-id)) ".")))

(defcomp ~checkout/return-paid ()
  (div :class "rounded-2xl border border-emerald-200 bg-emerald-50/80 p-4 sm:p-6 text-sm text-emerald-900 space-y-2"
    (p :class "font-medium" "All done!")
    (p "We\u2019ll start processing your order shortly.")))

(defcomp ~checkout/return-ticket (&key (name :as string) (pill :as string) (state :as string) (type-name :as string?) (date-str :as string) (code :as string) (price :as string))
  (li :class "px-4 py-3 flex items-start justify-between text-sm"
    (div
      (div :class "font-medium flex items-center gap-2"
        name (span :class pill state))
      (when type-name (div :class "text-xs text-stone-500" type-name))
      (div :class "text-xs text-stone-500" date-str)
      (div :class "text-xs text-stone-400 font-mono mt-0.5" code))
    (div :class "ml-4 font-medium" price)))

(defcomp ~checkout/return-tickets (&key items)
  (section :class "mt-6 space-y-3"
    (h2 :class "text-base sm:text-lg font-semibold" "Event tickets in this order")
    (ul :class "divide-y divide-stone-200 rounded-2xl border border-stone-200 bg-white/80" items)))

;; Data-driven ticket items (replaces Python loop)
(defcomp ~checkout/return-tickets-from-data (&key (tickets :as list))
  (~checkout/return-tickets
    :items (<> (map (lambda (tk)
      (~checkout/return-ticket
        :name (get tk "name") :pill (get tk "pill")
        :state (get tk "state") :type-name (get tk "type_name")
        :date-str (get tk "date_str") :code (get tk "code")
        :price (get tk "price")))
      (or tickets (list))))))

(defcomp ~checkout/return-content (&key summary items calendar tickets status-message)
  (div :class "max-w-full px-1 py-1"
    (when summary
      (div :class "rounded-2xl border border-stone-200 bg-white/80 p-4 sm:p-6 space-y-2" summary))
    items calendar tickets status-message))
