;; Events day components

(defcomp ~events-day-entry-link (&key href name time-str)
  (a :href href :class "flex items-center gap-2 px-3 py-2 hover:bg-stone-100 rounded transition text-sm border sm:whitespace-nowrap sm:flex-shrink-0"
    (div :class "flex-1 min-w-0"
      (div :class "font-medium truncate" name)
      (div :class "text-xs text-stone-600 truncate" time-str))))

(defcomp ~events-day-entries-nav (&key inner)
  (div :class "flex flex-col sm:flex-row sm:items-center gap-2 border-r border-stone-200 mr-2 sm:max-w-2xl"
       :id "day-entries-nav-wrapper"
    (div :class "flex overflow-x-auto gap-1 scrollbar-thin"
      inner)))

(defcomp ~events-day-table (&key list-container rows pre-action add-url)
  (section :id "day-entries" :class list-container
    (table :class "w-full text-sm border table-fixed"
      (thead :class "bg-stone-100"
        (tr
          (th :class "p-2 text-left w-2/6" "Name")
          (th :class "text-left p-2 w-1/6" "Slot/Time")
          (th :class "text-left p-2 w-1/6" "State")
          (th :class "text-left p-2 w-1/6" "Cost")
          (th :class "text-left p-2 w-1/6" "Tickets")
          (th :class "text-left p-2 w-1/6" "Actions")))
      (tbody rows))
    (div :id "entry-add-container" :class "mt-4"
      (button :type "button" :class pre-action
              :sx-get add-url :sx-target "#entry-add-container" :sx-swap "innerHTML"
        "+ Add entry"))))

(defcomp ~events-day-empty-row ()
  (tr (td :colspan "6" :class "p-3 text-stone-500" "No entries yet.")))

(defcomp ~events-day-row-name (&key href pill-cls name)
  (td :class "p-2 align-top w-2/6" (div :class "font-medium"
    (a :href href :class pill-cls :sx-get href :sx-target "#main-panel" :sx-select "#main-panel"
       :sx-swap "outerHTML" :sx-push-url "true" name))))

(defcomp ~events-day-row-slot (&key href pill-cls slot-name time-str)
  (td :class "p-2 align-top w-1/6" (div :class "text-xs font-medium"
    (a :href href :class pill-cls :sx-get href :sx-target "#main-panel" :sx-select "#main-panel"
       :sx-swap "outerHTML" :sx-push-url "true" slot-name)
    (span :class "text-stone-600 font-normal" time-str))))

(defcomp ~events-day-row-time (&key start end)
  (td :class "p-2 align-top w-1/6" (div :class "text-xs text-stone-600" (str start end))))

(defcomp ~events-day-row-state (&key state-id badge)
  (td :class "p-2 align-top w-1/6" (div :id state-id badge)))

(defcomp ~events-day-row-cost (&key cost-str)
  (td :class "p-2 align-top w-1/6" (span :class "font-medium text-green-600" cost-str)))

(defcomp ~events-day-row-tickets (&key price-str count-str)
  (td :class "p-2 align-top w-1/6" (div :class "text-xs space-y-1"
    (div :class "font-medium text-green-600" price-str)
    (div :class "text-stone-600" count-str))))

(defcomp ~events-day-row-no-tickets ()
  (td :class "p-2 align-top w-1/6" (span :class "text-xs text-stone-400" "No tickets")))

(defcomp ~events-day-row-actions ()
  (td :class "p-2 align-top w-1/6"))

(defcomp ~events-day-row (&key tr-cls name slot state cost tickets actions)
  (tr :class tr-cls name slot state cost tickets actions))

(defcomp ~events-day-admin-panel ()
  (div :class "p-4 text-sm text-stone-500" "Admin options"))

(defcomp ~events-day-entries-nav-oob-empty ()
  (div :id "day-entries-nav-wrapper" :sx-swap-oob "true"))

(defcomp ~events-day-entries-nav-oob (&key items)
  (div :class "flex flex-col sm:flex-row sm:items-center gap-2 border-r border-stone-200 mr-2 sm:max-w-2xl"
       :id "day-entries-nav-wrapper" :sx-swap-oob "true"
    (div :class "flex overflow-x-auto gap-1 scrollbar-thin" items)))

(defcomp ~events-day-nav-entry (&key href nav-btn name time-str)
  (a :href href :class nav-btn
    (div :class "flex-1 min-w-0"
      (div :class "font-medium truncate" name)
      (div :class "text-xs text-stone-600 truncate" time-str))))
