<head>
  <meta charset="utf-8">
  <script type="module">
    import { Application, Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"
    window.Stimulus = Application.start()

    Stimulus.register("mood", class extends Controller {
      static targets = [ "image" ]

      showMode(event) {
        const image = this.imageTarget
        image.src = event.target.dataset.mode + ".png"
      }

      showCurrent() {
        const image = this.imageTarget
        image.src = "<%= @last_mood.mode %>.png"
      }

    })
  </script>
<style>
body {
  margin: 0px;
  font: 1.8rem "Fira Sans", sans-serif;
}

main {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.mode {
  height: 100vh;
  flex: 1 527px;
}
img {
  height: 100%;
  width:100%;
  // min-width: 527px;
  object-fit: contain;
}
table {
  empty-cells: hide;
  border-collapse: collapse;
}
tbody tr td {
  border: 1px solid black;
  border-spacing: 3px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 50%;
  margin: 5px;
}
.tracker {
  display: flex;
  flex: 1 527px;
  flex-direction: column;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  background-color: lightgoldenrodyellow;
  height: 100vh;
  width: 100%;
}

.info h1 {
  margin-bottom: 40px;
  font-weight: 350;
}
.tracks {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-start;
  margin: 30px;
}
.week {
  display: flex;
  flex-direction: column;
  justify-items: start;
  flex-wrap: wrap;
  margin-bottom: 20px;
  
}

.day {
  border: 1px;
  margin: 4px;
  min-width: 20px;
  min-height: 20px;
}
.creatif {
  background-color: red;
}
.en-charge {
  background-color: orange;
}
.frigo-vide {
  background-color: grey;
}
.croisiere {
  background-color: green;
}
</style>
</head>
<main data-controller="mood">
  <div class="mode">
    <img data-mood-target="image" src="<%= @last_mood.mode %>.png">
  </div>
  <div class="tracker">
    <div class="info">
      <h1>Comment il va le Robi ?</h1>
    </div>
    <div class="tracks">

      <% @mood_log.each do |week| %>
        <div class="week">
          <% week.each do |d| %>
            <% if d[1] %>
              <div data-mode="<%= d[1] %>" data-action="mouseover->mood#showMode mouseleave->mood#showCurrent" title="<%= d[0] %> : <%= d[1] %>" class="day <%= d[1] %>"></div>
            <% else %>
              <div class="day"></div>
            <% end %>
          <% end %>
        </div>
      <% end %>
    </div>
  </div>
</main>
