module Project
  class CopyPhysicalProductModal < UniversalPage
    include PageHelpers::ReactHelpers
    include CopyModalCommon

    text_field(:product_code, id: "copy-product-code")
    react_select(:product_type) { label_element(for: "distribution-format-media-id").parent }
    react_select(:format) { label_element(for: "distribution-format-media-format-id").parent }
    text_field(:units_per_set, id: "units-per-set")
    react_select(:value_add) { label_element(text: "VALUE ADD").parent }
    react_select(:packaging, id: "packaging-select")
    react_select(:orchard_pricing) do
      section_element(class: "modal-body").label_element(text: /^ORCHARD PRICING/)
                                          .parent.div_element(class: "Select")
    end
    text_field(:initial_stock, id: "initial-stock")
    text_field(:box_lot, id: "box-lot")

    button(:submit, id: "confirm-submit")
    section(:loader, class: "PhysicalProductCopyModal-loading-body")
    div(:loader_to_dig, class: "LoadingIndicator-dots")
    div(:product_type_buttons, class: "ProductCopyModal-type-buttons")
    button(:digital) { product_type_buttons_element.div_element(text: "Digital").parent }

    def populate_create_product_modal(data)
      self.product_code = data[:product_code]
      select_product_type data[:configuration_product_type]
      select_format data[:format]
      self.units_per_set = data[:units_per_set]
      select_packaging data[:packaging]
      select_orchard_pricing data[:orchard_pricing]
      self.initial_stock = data[:initial_stock]
      self.box_lot = data[:box_lot]
    end
  end
end
