- method_on_demand, method_on_hand = variant.new_record? ? [:on_demand_desired, :on_hand_desired ]: [:on_demand, :on_hand]
%td.col-image
  -# empty
%td.col-name.field.naked_inputs
  = f.hidden_field :id
  = f.text_field :display_name, 'aria-label': t('admin.products_page.columns.name'), placeholder: variant.product.name
  = error_message_on variant, :display_name
%td.col-sku.field.naked_inputs
  = f.text_field :sku, 'aria-label': t('admin.products_page.columns.sku')
  = error_message_on variant, :sku
%td.col-unir_scale.field.naked_inputs{ 'data-controller': 'toggle-control', 'data-toggle-control-match-value': 'items' }
  = f.hidden_field :variant_unit
  = f.hidden_field :variant_unit_scale
  = f.select :variant_unit_with_scale,
      options_for_select(WeightsAndMeasures.variant_unit_options, variant.variant_unit_with_scale),
      { include_blank: t('.select_unit_scale') },
      { class: "fullwidth no-input", 'aria-label': t('admin.products_page.columns.unit_scale'), data: { "controller": "tom-select", "tom-select-options-value": '{ "plugins": [] }', action: "change->toggle-control#displayIfMatch" }, required: true }
  = error_message_on variant, :variant_unit, 'data-toggle-control-target': 'control'
  .field
    = f.text_field :variant_unit_name, 'aria-label': t('items'), 'data-toggle-control-target': 'control', style: (variant.variant_unit == "items" ? "" : "display: none")
    = error_message_on variant, :variant_unit_name, 'data-toggle-control-target': 'control'
%td.col-unit.field.popout{'data-controller': "popout", 'data-popout-update-display-value': "false"}
  = f.button :unit_to_display, class: "popout__button", 'aria-label': t('admin.products_page.columns.unit'), 'data-popout-target': "button" do
    = variant.unit_to_display # Show the generated summary of unit values
  .popout__container{ style: 'display: none;', 'data-controller': 'toggle-control', 'data-popout-target': "dialog" }
    .field
      -# Show a composite field for unit_value and unit_description
      = f.hidden_field :unit_value
      = f.hidden_field :unit_description
      = f.text_field :unit_value_with_description,
          value: unit_value_with_description(variant), 'aria-label': t('admin.products_page.columns.unit_value'), required: true
    .field
      = f.label :display_as, t('admin.products_page.columns.display_as')
      = f.text_field :display_as, placeholder: VariantUnits::OptionValueNamer.new(variant).name
  = error_message_on variant, :unit_value
%td.col-price.field.naked_inputs
  = f.text_field :price, 'aria-label': t('admin.products_page.columns.price'), value: number_to_currency(variant.price, unit: '')&.strip # TODO: add a spec to prove that this formatting is necessary. If so, it should be in a shared form helper for currency inputs
  = error_message_on variant, :price
%td.col-on_hand.field.popout{'data-controller': "popout"}
  %button.popout__button{'data-popout-target': "button", 'aria-label': t('admin.products_page.columns.on_hand')}
    = variant.on_demand_desired_or_current ? t(:on_demand) : variant.on_hand_desired_or_current
  .popout__container{ style: 'display: none;', 'data-controller': 'toggle-control', 'data-popout-target': "dialog" }
    .field
      = f.number_field method_on_hand, min: 0, 'aria-label': t('admin.products_page.columns.on_hand'), 'data-toggle-control-target': 'control', disabled: f.object.on_demand_desired_or_current
      = error_message_on variant, method_on_hand
    .field.checkbox
      = f.label method_on_demand do
        = f.check_box method_on_demand, 'data-action': 'change->toggle-control#disableIfPresent change->popout#closeIfChecked'
        = t(:on_demand)
%td.col-producer.field.naked_inputs
  = render(SearchableDropdownComponent.new(form: f,
      name: :supplier_id,
      aria_label: t('.producer_field_name'),
      options: producer_options,
      selected_option: variant.supplier_id,
      include_blank: t('admin.products_v3.filters.select_producer'),
      placeholder_value: t('admin.products_v3.filters.select_producer')))
  = error_message_on variant, :supplier
%td.col-category.field.naked_inputs
  = render(SearchableDropdownComponent.new(form: f,
      name: :primary_taxon_id,
      options: category_options,
      selected_option: variant.primary_taxon_id,
      aria_label: t('.category_field_name'),
      include_blank: t('admin.products_v3.filters.select_category'),
      placeholder_value: t('admin.products_v3.filters.select_category')))
  = error_message_on variant, :primary_taxon
%td.col-tax_category.field.naked_inputs
  = render(SearchableDropdownComponent.new(form: f,
      name: :tax_category_id,
      options: tax_category_options,
      selected_option: variant.tax_category_id,
      include_blank: t('.none_tax_category'),
      aria_label: t('.tax_category_field_name'),
      placeholder_value: t('.search_for_tax_categories')))
  = error_message_on variant, :tax_category
%td.col-inherits_properties.align-left
  -# empty
%td.align-right
  = render(VerticalEllipsisMenu::Component.new) do
    - if variant.persisted?
      = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(variant.product, variant)
      - if variant.product.variants.size > 1
        %a{ "data-controller": "modal-link", "data-action": "click->modal-link#setModalDataSetOnConfirm click->modal-link#open",
            "data-modal-link-target-value": "variant-delete-modal", "class": "delete",
            "data-modal-link-modal-dataset-value": {'data-delete-path': admin_destroy_variant_path(variant)}.to_json }
          = t('admin.products_page.actions.delete')
    - else
      %a{ 'data-action': "nested-form#remove", class: 'delete' }
        = t('admin.products_page.actions.remove')
