

{%- doc -%}
  This block is used to display the accelerated checkout button.
  Intended for product-form.liquid block.

  @param {string} can_add_to_cart - Whether the product can be added to the cart
  @param form_obj - The form object

  @example
  {% content_for 'block', type: 'accelerated-checkout', id: 'accelerated-checkout', can_add_to_cart: can_add_to_cart, form_obj: form %}
{%- enddoc -%}

{% liquid
  assign product = closest.product
  if request.visual_preview_mode and product == blank
    assign product = collections.all.products.first
  endif
%}

{% capture accelerated_checkout_button %}
  {% if product != blank and form_obj != blank %}
    {{ form_obj | payment_button }}
  {% endif %}
{% endcapture %}

{% if accelerated_checkout_button != blank %}
  <div
    class="accelerated-checkout-block"
    ref="acceleratedCheckoutButtonContainer"
    {{ block.shopify_attributes }}
    {% if request.visual_preview_mode %}
      data-shopify-visual-preview
    {% endif %}
    {% unless can_add_to_cart %}
      hidden
    {% endunless %}
  >
    {{ accelerated_checkout_button }}
  </div>
{% endif %}

{% render 'buy-buttons-styles' %}

{% schema %}
{
  "name": "t:names.accelerated_checkout",
  "tag": null
}
{% endschema %}
