<%= errors_summary_for talent_release %>
<%= bootstrap_form_with model: model, local: true do |form| %>
  <%= field_set_tag content_tag(:span, t(".talent_details.heading"), class: "h6 text-muted text-uppercase") do %>
    <%= form.form_group :minor do %>
      <%= form.check_box :minor, label: t("helpers.label.talent_release.minor"), data: { target: "[data-ujs-target=guardian-fields]", toggle: "collapse" } %>
    <% end %>

    <div class="form-row">
      <%= form.text_field :person_first_name, required: true, wrapper_class: "col-sm-3" %>
      <%= form.text_field :person_last_name, required: true, wrapper_class: "col-sm-3" %>
      <%= form.phone_field :person_phone, wrapper_class: "col-sm-6" %>
    </div>
    <div class="form-row">
      <%= form.email_field :person_email, wrapper_class: "col-sm-6" %>
    </div>
    <%= render "shared/address_fields", form: form, subject: "person" %>

    <div class="<%= class_string("collapse" => !talent_release.minor?) %>" data-ujs-target="guardian-fields">
      <div class="form-row">
        <%= form.text_field :guardian_first_name, required: talent_release.minor?, wrapper_class: "col-sm-3" %>
        <%= form.text_field :guardian_last_name, required: talent_release.minor?, wrapper_class: "col-sm-3" %>
        <%= form.phone_field :guardian_phone, wrapper_class: "col-sm-6" %>
      </div>
      <div class="form-row">
        <%= form.text_field :guardian_email, wrapper_class: "col-sm-6" %>
      </div>
      <%= render "shared/address_fields", form: form, subject: "guardian" %>
    </div>
  <% end %>

  <hr>

  <%= field_set_tag content_tag(:span, t(".contract_and_rights.heading"), class: "h6 text-muted text-uppercase") do %>
    <%= render "shared/contract_fields", form: form, release: talent_release %>
    <%= render "shared/exploitable_rights_fields", form: form %>
  <% end %>

  <hr>

  <%= field_set_tag content_tag(:span, t(".photos.heading"), class: "h6 text-muted text-uppercase") do %>
    <%= render "shared/photos_dropzone_fields", form: form, release: talent_release %>

    <div class="<%= class_string("collapse" => !talent_release.minor?) %>" data-ujs-target="guardian-fields">
      <br>
      <div class="text-left">
        <p><%= t(".photos.guardian_photo.heading") %></p>
        <div class="d-inline-block mb-2" data-behavior="guardian-photo-preview" data-file-input="[data-ujs-target=guardian-photo-input]">
          <div class="align-items-center d-flex photo-preview img-thumbnail justify-content-center">
            <span>No photo yet</span>
          </div>
        </div>
        <% if talent_release.guardian_photo.attached? %>
          <%= javascript_tag nonce: true do %>
            App.PhotoPreview.set("[data-behavior=guardian-photo-preview]", "<%= url_for(talent_release.guardian_photo.variant(auto_orient: true, resize: '200x200')) %>");
          <% end %>
        <% end %>
        <div class="d-inline-block">
          <%= form.hidden_field :guardian_photo, value: form.object.guardian_photo.signed_id if talent_release.guardian_photo.attached?%>
          <%= form.file_field :guardian_photo, hide_label: true, data: { ujs_target: "guardian-photo-input" }, help: "PNG or JPG only", accept: talent_release.class.face_photo_acceptable_content_types.join(",") %>
        </div>
      </div>
      <hr>
    </div>
  <% end %>

  <div class="row align-items-center text-center mt-4">
    <%= link_to t("shared.cancel"), [talent_release.project, :talent_releases], class: "col-3 text-reset" %>
    <div class="col-9">
      <%= form.button id: "submit_release", class: class_string("btn btn-block", ["btn-success", "btn-primary"] => talent_release.new_record?), data: { disable_with: t("shared.disable_with") } %>
    </div>
  </div>
<% end %>
