<%= turbo_frame_tag "activity_graph" do %>
  <%= cache ["activity_graph", current_user&.id, current_user&.timezone], expires_in: 1.minute do %>
    <div class="w-full overflow-x-auto mt-6 pb-2.5">
      <div class="grid grid-rows-7 grid-flow-col gap-1 w-full lg:w-1/2">
        <% (365.days.ago.to_date..Time.current.to_date).to_a.each do |date| %>
          <% duration = daily_durations[date] || 0 %>
          <% if duration < 1.minute %>
            <% bg_class = "activity-cell--0" %>
          <% else %>
            <% ratio = duration.to_f / length_of_busiest_day %>
            <%
              bg_class =
                if ratio >= 0.8
                  "activity-cell--4"
                elsif ratio >= 0.5
                  "activity-cell--3"
                elsif ratio >= 0.2
                  "activity-cell--2"
                else
                  "activity-cell--1"
                end
            %>
          <% end %>
          <a class="day activity-cell transition-all duration-75 w-3 h-3 rounded-sm hover:scale-110 hover:z-10 hover:shadow-md <%= bg_class %>" href="?date=<%= date %>" data-turbo-frame="_top" data-date="<%= date %>" data-duration="<%= distance_of_time_in_words(duration) %>" title="you hacked for <%= distance_of_time_in_words(duration) %> on <%= date %>"> </a>
        <% end %>
      </div>
      <p class="super">
        <% if current_user %>
          Calculated in <%= link_to ActiveSupport::TimeZone[current_user.timezone].to_s, my_settings_path(anchor: 'user_timezone'), data: { turbo_frame: '_top' } %>
        <% else %>
          Calculated in <%= ActiveSupport::TimeZone[local_assigns.fetch(:user_tz, 'UTC')].to_s %>
        <% end %>
      </p>
    </div>
  <% end %>
<% end %>
