<script>
	import { files } from './modfiles.js';
</script>

<style>
  .title {
    font-size: xx-large;
    line-height: 0.8;
    margin-bottom: 35px;
    padding-top: 20px;
  }
  .title small {
    display: inline-block;
  }
  .file {
    margin-left: -20px;
    padding-left: 20px;
    margin-right: -20px;
    padding-right: 20px;
    animation-duration: 1s;
    animation-name: fadein;
    animation-fill-mode: backwards;
    flex: auto 1 1;
  }
  .dark.file {
    color: #111;
    background-color: #eee;
  }
  .buttons {
    position: relative;
    background-color: var(--fg, white);
    width: calc(100% + 20px);
    left: -20px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 10px;
    padding-right: 10px;
    color: #000;
  }
  .difficulties {
    flex: auto 1 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }
  .buttonsreal {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  .buttonsreal a {
    font-size: 34px;
    height: 38px;
    display: block;
    line-height: 1;
    color: #000;
    background: linear-gradient(180deg, var(--fg, white) 0%, black 0% 100%);
    background-repeat: no-repeat;
    background-position: 0px -38px;
    transition: 0.1s color, 0.1s background-position;
    text-align: center;
    width: 38px;
  }
  .buttonsreal a:hover {
    color: #fff;
    background-position: 0px 0px;
  }
  .difficulty {
    border-right: 2px rgba(0, 0, 0, 0.1) solid;
    margin-right: 5px;
    padding-right: 5px;
    vertical-align: middle;
    white-space: nowrap;
  }

  .difficulty-expert {
	  color: #8200a1;
  }
  .difficulty-challenge {
	  color: #605ace;
  }
  .difficulty-edit {
    color: #b5b8ba;
  }
  .difficultyrating {
    display: inline-block;
    width: 28px;
    height: 28px;
    font-size: 22px;
    /*border: solid 2px #000;
    border-radius: 9px;*/
    text-align: center;
    vertical-align: middle;
    line-height: 1.08; /* css crimes */
  }

  .difficulty .difficultyname {
    white-space: nowrap;
    font-size: medium;
    color: #333;
  }
  .difficultyrating {
    font-weight: bold;
  }
  .difficulty:last-child {
    border-right: none;
  }
  .metadata {
    display: flex;
    align-items: baseline;
    width: 100%;
    gap: 8px;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .pack {
    flex: auto 0 0;
    color: #eee;
    opacity: 0.9;
    align-self: flex-start;
    margin-top: 12px;
  }
  .dark .pack {
    color: #111;
  }
  .collabicon {
    display: block;
    user-select: none;
    color: #000;
    opacity: 0.3;
    font-size: 12px;
    line-height: 0.7;
    width: 38px;
    text-align: center;
  }

  @keyframes fadein {
    from {opacity: 0;}
    to {opacity: 1;}
  }
</style>

<span>
  {#each $files as file, i}
    <div class="file" class:dark={file.flipColors} style="background: center / cover no-repeat url({file.imageUrl}); animation-delay: {i/12}s">
      <div class="metadata">
        <div class="title"><b>{file.name}</b> {#if file.subtitle}<small>{file.subtitle}</small>{/if}</div>
        {#if file.pack}<small class="pack">from {file.pack}</small>{/if}
      </div><br>
      <div class="buttons">
        <div class="difficulties">
          {#each file.difficulties as difficulty}
          <div class="difficulty">
            <span class:intended={difficulty.intended} class="difficultyrating difficulty-{difficulty.type}">
              {difficulty.rating}
            </span>
            <span class="difficultyname">
              {#if difficulty.intended}{difficulty.name}{/if}
            </span>
          </div>
          {/each}
        </div>
        <div class="buttonsreal">
          {#if file.collab}
          <div class="collabicon" title="This is a collab{file.collabPartners ? ' with ' + file.collabPartners : ''}"><i class="material-icons">link</i></div>
          {/if}
          {#if file.packUrl}
          <a target="_blank" rel="noopener noreferrer" href={file.packUrl} title="Download {file.pack}">
            <i class="material-icons">unarchive</i>
          </a>
          {/if}
          {#if file.songUrl}
          <a target="_blank" rel="noopener noreferrer" href={file.songUrl} title="Song">
            <i class="material-icons">music_note</i>
          </a>
          {/if}
          {#if file.videoUrl}
          <a target="_blank" rel="noopener noreferrer" href={file.videoUrl} title="Video">
            <i class="material-icons">video_library</i>
          </a>
          {/if}
          {#if file.downloadUrl}
          <a target="_blank" rel="noopener noreferrer" href={file.downloadUrl} title="Download">
            <i class="material-icons">file_download</i>
          </a>
          {/if}
        </div>
      </div>
    </div>
  {/each}
</span>