<div class="container">
  <div class="delete-confirmation">
    <h1>Delete Field: <%= @field.name %></h1>

    <div class="warning-box">
      <h2>⚠️ Warning</h2>
      <p>You are about to delete the field "<strong><%= @field.name %></strong>" from the schema "<strong><%= @schema.name %></strong>".</p>

      <%= if @field.field_type == "reference" && @field.referenced_schema do %>
        <p>This is a reference field pointing to: <strong><%= @field.referenced_schema.name %></strong></p>
      <% end %>
    </div>

    <%= if Enum.empty?(@affected_contents) do %>
      <div class="info-box">
        <h3>Impact</h3>
        <p>No content instances have data in this field. It's safe to delete.</p>
      </div>
    <% else %>
      <div class="danger-box">
        <h3>Impact: <%= length(@affected_contents) %> content instance(s) affected</h3>
        <p>The following content instances have data in this field that will be permanently deleted:</p>

        <ul class="affected-content-list">
          <%= for content <- @affected_contents do %>
            <li>
              <a href={"/content/#{content.id}"} target="_blank">
                <%= @schema.name %> #<%= content.id %>
              </a>
              <span class="field-value-preview">
                Current value:
                <strong>
                  <%= if @field.field_type == "text" do %>
                    "<%= Map.get(content.field_values, to_string(@field.id)) %>"
                  <% else %>
                    Content #<%= Map.get(content.field_values, to_string(@field.id)) %>
                  <% end %>
                </strong>
              </span>
            </li>
          <% end %>
        </ul>
      </div>
    <% end %>

    <div class="confirmation-actions">
      <form action={"/schemas/#{@schema.id}/fields/#{@field.id}/delete"} method="post">
        <button type="submit" class="btn-danger">
          <%= if Enum.empty?(@affected_contents) do %>
            Delete Field
          <% else %>
            Delete Field and Remove Data from <%= length(@affected_contents) %> Content Instance(s)
          <% end %>
        </button>
      </form>
      <a href={"/schemas/#{@schema.id}"} class="btn-secondary">Cancel</a>
    </div>
  </div>
</div>
