(ns auto-ap.ssr.pos.common
  (:require [auto-ap.ssr.components :as com]
            [auto-ap.ssr.components.date-range :as dr]
            [auto-ap.time :as atime]
            [auto-ap.ssr.svg :as svg]))
(defn date-range-field* [request]
  (dr/date-range-field {:value {:start (:start-date (:query-params request))
                             :end (:end-date (:query-params request))}
                     :id "date-range"}))

(defn processor-field* [request]
  (com/field {:label "Processor"}
             (com/radio-card {:size    :small
                         :name    "processor"
                         :value (:processor (:query-params request))
                         :options [{:value   ""
                                    :content "All"}
                                   {:value   "square"
                                    :content [:div.flex.space-x-2 [:img.align-center {:src "/img/square.png" :style {:width "16px" :height "16px"}}] [:div "Square"]]}
                                   {:value   "doordash"
                                    :content [:div.flex.space-x-2 [:img.align-center {:src "/img/doordash.png" :style {:width "16px" :height "16px"}}] [:div "Doordash"]]}
                                   {:value   "uber-eats"
                                    :content [:div.flex.space-x-2 [:img.align-center {:src "/img/ubereats.png" :style {:width "16px" :height "16px"}}] [:div "Uber eats"]]}
                                   {:value   "grubhub"
                                    :content [:div.flex.space-x-2 [:img.align-center {:src "/img/grubhub.png" :style {:width "16px" :height "16px"}}] [:div "Grubhub"]]}
                                   {:value   "koala"
                                    :content [:div.flex.space-x-2 [:img.align-center {:src "/img/koala.png" :style {:width "16px" :height "16px"}}] [:div "Koala"]]}
                                   {:value   "ezcater"
                                    :content [:div.flex.space-x-2 [:img.align-center {:src "/img/ezcater.png" :style {:width "16px" :height "16px"}}] [:div "EZCater"]]}
                                   {:value   "na"
                                    :content "No Processor"}]})))

(defn total-field* [request]
  (com/field {:label "Total"}
             [:div.flex.space-x-4.items-baseline
              (com/money-input {:name        "total-gte"
                                :id          "total-gte"
                                :hx-preserve "true"
                                :class       "hot-filter  w-20"
                                :value       (:total-gte (:query-params request))
                                :placeholder "0.01"
                                :size        :small})
              [:div.align-baseline 
               "to"]
              (com/money-input {:name        "total-lte"
                                :hx-preserve "true"
                                :id          "total-lte"
                                :class       "hot-filter w-20"
                                :value       (:total-lte (:query-params request))
                                :placeholder "9999.34"
                                :size        :small})]))

(defn exact-match-id-field* [request]
  (when-let [exact-match-id  (:exact-match-id (:query-params request))]
    [:div 
     (com/field {:label "Exact match"}
                (com/pill {:color :primary}
                          [:span.inline-flex.gap-2
                           exact-match-id
                           [:a {:href "?exact-match-id="}
                            [:div.h-4.w-4 svg/x]]]))]))
