;; Market navigation components

(defcomp ~market-category-link (&key href hx-select active select-colours label)
  (div :class "relative nav-group"
    (a :href href :sx-get href :sx-target "#main-panel"
       :sx-select hx-select :sx-swap "outerHTML" :sx-push-url "true"
       :aria-selected (if active "true" "false")
       :class (str "block px-2 py-1 rounded text-center whitespace-normal break-words leading-snug bg-stone-200 text-black " select-colours)
       label)))

(defcomp ~market-desktop-category-nav (&key links admin)
  (nav :class "hidden md:flex gap-4 text-sm ml-2 w-full justify-end items-center"
    links admin))

(defcomp ~market-mobile-nav-wrapper (&key items)
  (div :class "px-4 py-2" (div :class "divide-y" items)))

(defcomp ~market-mobile-all-link (&key href hx-select active select-colours)
  (a :role "option" :href href :sx-get href :sx-target "#main-panel"
     :sx-select hx-select :sx-swap "outerHTML" :sx-push-url "true"
     :aria-selected (if active "true" "false")
     :class (str "block rounded-lg px-3 py-3 text-base hover:bg-stone-50 " select-colours)
     (div :class "prose prose-stone max-w-none" "All")))

(defcomp ~market-mobile-chevron ()
  (svg :class "w-4 h-4 shrink-0 transition-transform group-open/cat:rotate-180"
       :viewBox "0 0 20 20" :fill "currentColor"
    (path :fill-rule "evenodd" :clip-rule "evenodd"
          :d "M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z")))

(defcomp ~market-mobile-cat-summary (&key bg-cls href hx-select select-colours cat-name count-label count-str chevron)
  (summary :class (str "flex items-center justify-between cursor-pointer select-none block rounded-lg px-3 py-3 text-base hover:bg-stone-50" bg-cls)
    (a :href href :sx-get href :sx-target "#main-panel"
       :sx-select hx-select :sx-swap "outerHTML" :sx-push-url "true"
       :class (str "font-medium " select-colours " flex flex-row gap-2")
      (div cat-name)
      (div :aria-label count-label count-str))
    chevron))

(defcomp ~market-mobile-sub-link (&key select-colours active href hx-select label count-label count-str)
  (a :class (str "snap-start px-2 py-3 rounded " select-colours " flex flex-row gap-2")
     :aria-selected (if active "true" "false")
     :href href :sx-get href :sx-target "#main-panel"
     :sx-select hx-select :sx-swap "outerHTML" :sx-push-url "true"
    (div label)
    (div :aria-label count-label count-str)))

(defcomp ~market-mobile-subs-panel (&key links)
  (div :class "pb-3 pl-2"
    (div :data-peek-viewport "" :data-peek-size-px "18" :data-peek-edge "bottom" :data-peek-mask "true" :class "m-2 bg-stone-100"
      (div :data-peek-inner "" :class "grid grid-cols-1 gap-1 snap-y snap-mandatory pr-1" :aria-label "Subcategories"
        links))))

(defcomp ~market-mobile-view-all (&key href hx-select)
  (div :class "pb-3 pl-2"
    (a :class "px-2 py-1 rounded hover:bg-stone-100 block"
       :href href :sx-get href :sx-target "#main-panel"
       :sx-select hx-select :sx-swap "outerHTML" :sx-push-url "true"
       "View all")))

(defcomp ~market-mobile-cat-details (&key open summary subs)
  (details :class "group/cat py-1" :open open
    summary subs))
