- if use_billing
  .field{style: "position: absolute;margin-top: -15px;right: 0;"}
    %span
      = check_box_tag 'order[use_billing]', '1', (!(@order.bill_address.empty? && @order.ship_address.empty?) && @order.bill_address.same_as?(@order.ship_address))
      = label_tag 'order[use_billing]', Spree.t(:use_billing_address)

- is_shipping_address = name == Spree.t(:shipping_address)
- s_or_b = is_shipping_address ? 's' : 'b'
- address_type = is_shipping_address ? 'shipping' : 'billing'

- display_style = (use_billing && (!(@order.bill_address.empty? && @order.ship_address.empty?) && @order.bill_address == @order.ship_address)) ? 'none' : 'block'

%div{id: "#{is_shipping_address ? 'shipping' : 'billing'}", style: "display: #{display_style}"}
  %div{class: "field"}
    = f.label :firstname, Spree.t(:first_name) + ':'
    = f.text_field :firstname, class: 'fullwidth'
  %div{class: "field"}
    = f.label :lastname, Spree.t(:last_name) + ':'
    = f.text_field :lastname, class: 'fullwidth'
  %div{class: "field"}
    = f.label :address1, Spree.t(:street_address) + ':'
    = f.text_field :address1, class: 'fullwidth'
  %div{class: "field"}
    = f.label :address2, Spree.t(:street_address_2) + ':'
    = f.text_field :address2, class: 'fullwidth'
  %div{class: "field"}
    = f.label :city, Spree.t(:city) + ':'
    = f.text_field :city, class: 'fullwidth'
  %div{class: "field"}
    = f.label :zipcode, Spree.t(:zip) + ':'
    = f.text_field :zipcode, class: 'fullwidth'
  %div{"data-controller": "dependent-select", "data-dependent-select-options-value": countries_with_states }
    %div{class: "field"}
      = f.label :country_id, Spree.t(:country) + ':'
      %span{id: "#{s_or_b}country"}
        = f.select :country_id, countries, { selected: @order.send("#{address_type}_address").country_id },
        { "data-controller": "tom-select", "data-dependent-select-target": "source", "data-action": "dependent-select#handleSelectChange", class: "primary" }
    %div{class: "field"}
      = f.label :state_id, Spree.t(:state) + ':'
      %span{id: "#{s_or_b}state"}
        = f.select :state_id, states_for_country(@order.send("#{address_type}_address").country), { selected: @order.send("#{address_type}_address").state_id },
        { "data-controller": "tom-select", "data-dependent-select-target": "select", class: "primary" }

  %div{class: "field"}
    = f.label :phone, Spree.t(:phone) + ':'
    = f.phone_field :phone, class: 'fullwidth'
