//-/////////////////////////////////////////////////////////////////////////////
//-                                                                           //
//-               This file is part of the Buildbotics firmware.              //
//-                                                                           //
//-      Copyright (c) 2015 - 2021, Buildbotics LLC, All rights reserved.     //
//-                                                                           //
//-       This Source describes Open Hardware and is licensed under the       //
//-                               CERN-OHL-S v2.                              //
//-                                                                           //
//-       You may redistribute and modify this Source and make products       //
//-  using it under the terms of the CERN-OHL-S v2 (https:/cern.ch/cern-ohl). //
//-         This Source is distributed WITHOUT ANY EXPRESS OR IMPLIED         //
//-  WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS //
//-   FOR A PARTICULAR PURPOSE. Please see the CERN-OHL-S v2 for applicable   //
//-                                conditions.                                //
//-                                                                           //
//-              Source location: https://github.com/buildbotics              //
//-                                                                           //
//-    As per CERN-OHL-S v2 section 4, should You produce hardware based on   //
//-  these sources, You must maintain the Source Location clearly visible on  //
//-  the external case of the CNC Controller or other product you make using  //
//-                                this Source.                               //
//-                                                                           //
//-              For more information, email info@buildbotics.com             //
//-                                                                           //
//-/////////////////////////////////////////////////////////////////////////////

script#files-template(type="text/x-template")
  .files(v-if="fs.files")
    .files-name(v-if="mode == 'save'")
      label Name:
      input(v-model="filename", @input="filename_changed", focus)

    .files-body
      .files-locations
        .files-location(v-for="name in locations", @click="open(name)",
          :class="{active: name == location}", :title="location_title(name)")
          .fa.fa-home(v-if="name == 'Home'")
          .fa.fa-eject(v-else, @click.stop="eject(name)",
            title="Eject USB drive")
          | {{name}}

      .files-box
        .files-path-bar
          .files-path
            bbutton(v-for="path in paths", track-by="$index",
              :disabled="$index == paths.length - 1", :text="path",
              :title="path_title($index)", @click="load_path($index)")

          .files-upload(v-if="mode != 'save'")
            bbutton(
              title="Upload a file from this computer to the controller.",
              primary, @click="upload", text="Upload")

          .new-folder
            bbutton(title="Create a new folder.", text="New Folder",
              @click="new_folder", :disabled="10 < paths.length", icon="plus")

        .files-list
          table
            thead
              tr
                th.name Name
                th.size Size
                th.modified Modified

            tbody
              tr(v-for="file in files",
                :class="{selected: $index == selected}",
                @click="select($index)", @dblclick="activate(file)")
                td.name.
                  #[.fa(:class="file.dir ? 'fa-folder' : 'fa-file-o'")]
                  {{file.name}}
                td.size: span(v-if="!file.dir") {{file.size | size}}
                td.modified {{file.modified | ago}}

    dialog.new-folder(v-ref:new-folder, header="Folder Name",
      :buttons="['Cancel', {text: 'Create', disabled: !folder_valid}]")
      p(slot="body")
        input(v-model="folder", @keyup.enter="create_folder", focus)
