<section>
  <h2 id="wakatime_mirror">WakaTime Mirror</h2>
  <p>Mirror your coding activity to WakaTime.</p>

  <% if current_user.wakatime_mirrors.any? %>
    <div class="mirrors-list">
      <% current_user.wakatime_mirrors.each do |mirror| %>
        <div class="mirror-item">
          <p>
            <strong>Endpoint:</strong> <%= mirror.endpoint_url %><br>
            <strong>Last synced:</strong> <%= mirror.last_synced_at ? time_ago_in_words(mirror.last_synced_at) + " ago" : "Never" %>
          </p>
          <%= button_to "Delete", user_wakatime_mirror_path(current_user, mirror), method: :delete, class: "button", data: { confirm: "Are you sure?" } %>
        </div>
      <% end %>
    </div>
  <% end %>

  <%= form_with(model: [current_user, WakatimeMirror.new], local: true) do |f| %>
    <div class="field">
      <%= f.label :endpoint_url, "WakaTime API Endpoint" %>
      <%= f.text_field :endpoint_url, value: "https://wakatime.com/api/v1", placeholder: "https://wakatime.com/api/v1" %>
    </div>

    <div class="field">
      <%= f.label :encrypted_api_key, "WakaTime API Key" %>
      <%= f.password_field :encrypted_api_key, placeholder: "Enter your WakaTime API key" %>
    </div>

    <%= f.submit "Add Mirror", class: "button" %>
  <% end %>
</section>
