= form_with url: bulk_update_admin_products_path, method: :post, id: "products-form",
            builder: BulkFormBuilder,
            html: { data: { 'turbo-frame': "_self",
              controller: "bulk-form",
              'bulk-form-disable-selector-value': "#sort,#filters",
              'bulk-form-error-value': defined?(@error_counts),
              } } do |form|
  = render(partial: "admin/shared/flashes", locals: { flashes: }) if defined? flashes

  = hidden_field_tag :page, @page
  = hidden_field_tag :per_page, @per_page
  = hidden_field_tag :search_term, @search_term
  = hidden_field_tag :producer_id, @producer_id
  = hidden_field_tag :category_id, @category_id

  %table.products{ 'data-column-preferences-target': "table", class: (hide_producer_column?(producer_options) ? 'hide-producer' : '') }
    %colgroup
      -# The `min-width` property works in Chrome but not Firefox so is considered progressive enhancement.
      %col.col-image{ width:"44px" }= # (image size + padding)
      %col.col-name{ style:"min-width: 6em" }= # (grow to fill)
      %col.col-sku{ width:"8%", style:"min-width: 6em" }
      %col.col-unit_scale{ width:"8%" }
      %col.col-unit{ width:"8%" }
      %col.col-price{ width:"10%", style:"min-width: 5em" }
      %col.col-on_hand{ width:"8%" }
      %col.col-producer{ style:"min-width: 6em" }= # (grow to fill)
      %col.col-category{ width:"8%" }
      %col.col-tax_category{ width:"8%" }
      %col.col-inherits_properties{ width:"5%" }
      %col{ width:"5%", style:"min-width: 3em"}= # Actions
    %thead
      %tr
        %td.form-actions-wrapper{ colspan: 12 }
          .form-actions-wrapper2
            %fieldset.form-actions{ class: ("hidden" unless defined?(@error_counts)), 'data-bulk-form-target': "actions" }
              .container
                .status
                  .modified_summary{ 'data-bulk-form-target': "changedSummary", 'data-translation-key': 'admin.products_v3.table.changed_summary'}
                  - if defined?(@error_counts)
                    .error_summary
                      - if @error_counts[:saved] > 0
                        -# X products were saved correctly, but Y products could not be saved correctly. Please review errors and try again
                        = t('.error_summary.saved', count: @error_counts[:saved]) + t('.error_summary.invalid', count: @error_counts[:invalid])
                      - else 
                        -# Y products could not be saved correctly. Please review errors and try again
                        = t('.error_summary.invalid', count: @error_counts[:invalid])
                .form-buttons
                  %a.button.reset.medium{ href: admin_products_path(page: @page, per_page: @per_page, search_term: @search_term, producer_id: @producer_id, category_id: @category_id), 'data-turbo': "false" }
                    = t('.reset')
                  = form.submit t('.save'), { class: "medium", data: { action: "click->bulk-form#popoutEmptyVariantUnit" }}
      %tr
        %th.col-image.align-left= # image
        = render partial: 'spree/admin/shared/stimulus_sortable_header',
            locals: { column: :name, sorted: params.dig(:q, :s), default: 'name asc' }
        %th.align-left.col-sku.with-input= t('admin.products_page.columns.sku')
        %th.align-left.col-unit_scale.with-input= t('admin.products_page.columns.unit_scale')
        %th.align-left.col-unit.with-input= t('admin.products_page.columns.unit')
        %th.align-left.col-price.with-input= t('admin.products_page.columns.price')
        %th.align-left.col-on_hand.with-input= t('admin.products_page.columns.on_hand')
        %th.align-left.col-producer= t('admin.products_page.columns.producer')
        %th.align-left.col-category= t('admin.products_page.columns.category')
        %th.align-left.col-tax_category= t('admin.products_page.columns.tax_category')
        %th.align-left.col-inherits_properties= t('admin.products_page.columns.inherits_properties')
        %th.align-right= t('admin.products_page.columns.actions')
    - products.each_with_index do |product, product_index|
      = render partial: 'product_variant_row', locals: { form:, product:, product_index:, producer_options:, category_options:, tax_category_options: }
