;; Cart payments components

(defcomp ~payments/panel (&key update-url csrf merchant-code placeholder input-cls sumup-configured checkout-prefix)
  (section :class "p-4 max-w-lg mx-auto"
    (~shared:misc/sumup-settings-form :update-url update-url :csrf csrf :merchant-code merchant-code
      :placeholder placeholder :input-cls input-cls :sumup-configured sumup-configured
      :checkout-prefix checkout-prefix :sx-select "#payments-panel")))

;; Assembled cart admin overview content
(defcomp ~payments/admin-content ()
  (let* ((payments-href (url-for "defpage_cart_payments")))
    (div :id "main-panel"
      (div :class "flex items-center justify-between p-3 border-b"
        (span :class "font-medium" (i :class "fa fa-credit-card text-purple-600 mr-1") " Payments")
        (a :href payments-href :class "text-sm underline" "configure")))))

;; Assembled cart payments content
(defcomp ~payments/content (&key page-config)
  (let* ((sumup-configured (and page-config (get page-config "sumup_api_key")))
         (merchant-code (or (get page-config "sumup_merchant_code") ""))
         (checkout-prefix (or (get page-config "sumup_checkout_prefix") ""))
         (placeholder (if sumup-configured "--------" "sup_sk_..."))
         (input-cls "w-full px-3 py-1.5 text-sm border border-stone-300 rounded focus:ring-purple-500 focus:border-purple-500"))
    (~payments/panel
      :update-url (url-for "page_admin.update_sumup")
      :csrf (csrf-token)
      :merchant-code merchant-code
      :placeholder placeholder
      :input-cls input-cls
      :sumup-configured sumup-configured
      :checkout-prefix checkout-prefix)))
