= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
  - type_champ = ff.object.object.type_champ

  .form-inline{ class: (type_champ == TypeDeChamp.type_champs.fetch(:header_section) ? 'header-section' : nil) }
    .form-group.libelle
      %h4 Libellé
      = ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'

    .form-group.type
      %h4 Type
      = ff.select :type_champ, tdc_options, {}, { class: 'form-control type-champ' }

    .form-group.description
      %h4 Description
      = ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 3

    .form-group.drop-down-list{ class: (%w(drop_down_list multiple_drop_down_list linked_drop_down_list).include?(type_champ) ? 'show-inline' : nil), style: 'margin-right: 5px;' }
      %h4 Liste déroulante
      = ff.fields_for :drop_down_list_attributes, ff.object.object.drop_down_list do |fff|
        ~ fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne et --valeur-- pour un séparateur.", rows: 3, cols: 30
        = fff.hidden_field :id

    .form-group.pj-template{ class: (type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)) ? 'show-inline' : nil }
      %h4 Modèle
      - if type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative)
        - template = ff.object.object.piece_justificative_template

        - if !template.attached?
          = ff.file_field :piece_justificative_template,
            direct_upload: true
        - else
          = link_to template.filename.to_s, url_for(template), target: '_blank'
          %br
          Modifier :
          = ff.file_field :piece_justificative_template,
            direct_upload: true
      - else
        = ff.file_field :piece_justificative_template,
          direct_upload: true

    .form-group.carte-options{ class: (type_champ == TypeDeChamp.type_champs.fetch(:carte)) ? 'show-inline' : nil }
      %h4 Utilisation de la cartographie
      %label
        = ff.check_box :quartiers_prioritaires
        Quartiers prioritaires
      %br
      %label
        = ff.check_box :cadastres
        Cadastre
      %br
      %label
        = ff.check_box :parcelles_agricoles
        Parcelles Agricoles

    - hide_mandatory = (ff.object.object.private? || type_champ == TypeDeChamp.type_champs.fetch(:explication))
    .form-group.mandatory{ style: hide_mandatory ? 'visibility: hidden;' : nil }
      %h4 Obligatoire ?
      .center
        = ff.check_box :mandatory, placeholder: 'Obligatoire ?'

    .form-group
      = ff.hidden_field :order_place, value: ff.index
      = ff.hidden_field :id

    - if ff.object.id.present?
      .form-group
        %br &nbsp;
        = ff.object.button_up(index: ff.index, url: @types_de_champ_facade.move_up_url(ff), private: @types_de_champ_facade.private)
        = ff.object.button_down(index: ff.index, url: @types_de_champ_facade.move_down_url(ff), private: @types_de_champ_facade.private)

    .form-group
      %h4 position
      = ff.number_field :custom_order_place, value: (ff.index + 1), length: 999, class: 'form-control', style: 'width: 100px;'

    .form-group
      %br &nbsp;
      - if ff.object.id.nil?
        = f.button 'Ajouter le champ',
          id: @types_de_champ_facade.add_button_id,
          class: 'btn btn-success',
          data: { disable: true }
      - else
        = link_to("", @types_de_champ_facade.delete_url(ff), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )

    %div{ style: 'background-color: rgb(204, 204, 204); height: 1px; margin: 30px auto;' }
