<% content_for :title, 'Statistics' %>
<%= number_with_delimiter(current_user.total_distance.round) %> <%= current_user.safe_settings.distance_unit %>
Total distance
<%= number_with_delimiter @points_total %>
Geopoints tracked
<% if DawarichSettings.reverse_geocoding_enabled? %> <%= render 'stats/reverse_geocoding_stats' %> <% end %>
<%= link_to 'Update stats', update_all_stats_path, data: { turbo_method: :put }, class: 'btn btn-primary mt-5' %>
<% @stats.each do |year, stats| %>

<%= link_to year, "/stats/#{year}", class: 'underline hover:no-underline' %> <%= link_to '[Map]', map_url(year_timespan(year)), class: 'underline hover:no-underline' %>
Last updated: <%= human_date(stats.first.updated_at) %> <%= link_to '🔄', update_year_month_stats_path(year, :all), data: { turbo_method: :put }, class: 'text-sm text-gray-500 hover:underline' %>

<% cache [current_user, 'year_distance_stat', year], skip_digest: true do %> <%= number_with_delimiter year_distance_stat(year, current_user) %><%= current_user.safe_settings.distance_unit %> <% end %>

<% if DawarichSettings.reverse_geocoding_enabled? %>
<% location_data = countries_and_cities_stat_for_year(year, stats) %> <%= link_to "#{location_data[:countries_count]} countries, #{location_data[:cities_count]} cities", "##{location_data[:modal_id]}", class: "link link-primary", onclick: "document.getElementById('#{location_data[:modal_id]}').checked = true" %>
<% end %> <%= column_chart( Stat.year_distance(year, current_user).map { |month_name, distance_meters| [month_name, Stat.convert_distance(distance_meters, current_user.safe_settings.distance_unit).round(2)] }, height: '200px', suffix: " #{current_user.safe_settings.distance_unit}", xtitle: 'Days', ytitle: 'Distance' ) %>
<% end %>