<%= form_with(model: listing, local: true) do |form| %>
<%= render partial: "form_errors", locals: { listing: listing } %>
<%= form.label "title", class: "crayons-label" %> <%= form.text_field "title", placeholder: t("views.listings.form.title.placeholder"), class: "crayons-textfield" %>
<%= form.label "body_markdown", class: "crayons-field__label" %> <%= form.text_area "body_markdown", placeholder: t("views.listings.form.body_markdown.placeholder"), class: "crayons-textfield" %>

<%= t("views.listings.form.body_markdown.description") %>

<%= t("views.listings.form.category.summary") %>
<%# The following tag_list field is overridden by the Tags JS component from the listingForm. We keep this form field in place to facilitate SSR. By having the form field loaded on the DOM first with this view, we prevent the screen from "jumping" once the deferred JS is loaded and executed. %>
<%= form.label "tag_list", class: "crayons-field__label" %> <%= form.text_field "tag_list", placeholder: t("views.listings.form.tags.placeholder"), class: "crayons-textfield" %>
<% if @organizations.present? && @organizations.size > 0 %>
<%= form.label "organization_id", class: "crayons-field__label" %> <%= form.select :organization_id, { t("views.listings.form.organization.none") => "None" }, {}, { class: "crayons-select m:max-w-50" } %>

<%= t("views.listings.form.organization.description") %>

<% end %>
<% unless @organizations.present? %> <%= javascript_packs_with_chunks_tag "listingForm", defer: true %> <% end %>
<%= form.label "location", t("views.listings.form.location.label"), class: "crayons-field__label" %> <%= form.text_field "location", placeholder: t("views.listings.form.location.placeholder"), class: "crayons-textfield m:max-w-50" %>

<%= t("views.listings.form.location.description") %>

<% unless @credits.size > 0 || (@organizations.present? && @organizations.sum(:unspent_credits_count) > 0) %>
<%= t("views.listings.form.no_credit") %>
<% end %>
<% if @credits.size > 0 || (@organizations.present? && @organizations.sum(:unspent_credits_count) > 0) %> <%= form.submit t("views.listings.form.publish"), class: "crayons-btn mr-2" %> <% else %> <%= t("views.listings.form.purchase") %> <% end %> <%= form.button t("views.listings.form.save"), type: "submit", name: "listing[action]", class: "crayons-btn crayons-btn--secondary", value: "draft" %>

<%= t("views.listings.form.save_notice") %>

<% end %>