<template>
  <span>
    <a href="#" @click="show = true"><img class="icon" src="/img/bash/app_icon.webp" width="50" height="50" alt="ロリ端末" /></a>
    <span v-if="show">
      <label :for="`konsoleinput-${output.length-1}`">
      <vue-draggable-resizable style="border: 0px solid #232629;" :drag-handle="'.drag-handle'" class-name-handle="resize-handle" class="konsoleuser" :x="-50" :y="-100" :z="99999999">
        <div style="width: 100%; position: relative;">
          <div class="drag-handle-left"></div>
          <div class="drag-handle">ロリ端末</div>
          <div class="drag-handle-min"></div>
          <div class="drag-handle-max"></div>
          <div class="drag-handle-right" @click="show = false"></div>
        </div>
        <div class="konsole_left"></div>
        <div style="padding: 5px;">
          <div v-for="(o, i) in output" :key="`output-${i}`">
            <div v-html="o"></div>
            <div class="row">
              <div class="col-auto" style="padding-right: 6px;">shiken@technicalsuwako.jp:/$</div>
              <div class="col" style="padding-left: 0px;">
                <input :ref="`konsoleinput-${i}`" :id="`konsoleinput-${i}`" class="konsole_input" type="text" :disabled="i !== output.length-1" v-model="cmd[i]" @keyup.enter="exec(i)" />
              </div>
            </div>
          </div>
        </div>
        <div class="konsole_right"></div>
        <div class="konsole_bottom_left"></div>
        <div class="konsole_bottom"></div>
        <div class="konsole_bottom_right"></div>
      </vue-draggable-resizable>
      </label>
    </span>
  </span>
</template>

<script>
  import VueDraggableResizable from 'vue-draggable-resizable';
  import 'vue-draggable-resizable/dist/VueDraggableResizable.css';

  Vue.component('vue-draggable-resizable', VueDraggableResizable);

  export default {
    data: function () {
      return {
        cmd: [''],
        output: ['ロリコマンドラインですね〜♡'],
        show: false,
        width: 0,
        height: 0,
        x: 0,
        y: 0
      }
    },
    methods: {
      onResize: function (x, y, width, height) {
        this.x = x
        this.y = y
        this.width = width
        this.height = height
      },
      onDrag: function (x, y) {
        this.x = x
        this.y = y
      },
      exec (i) {
        axios.post('/api/rpc/bash/exec', { args: this.cmd[i] }).then(res => {
          this.output.push(res.data);
          this.cmd.push('');
        });
      }
    }
  }
</script>

<style scoped>
  .konsole {
    width: 600px;
    height: 358px;
    margin: auto;
    color: #fcfcfc;
  }

  .drag-handle-left {
    height: 30px;
    width: 30px;
    background: url('/img/bash/top_left.png') no-repeat;
    position: absolute;
    top: 0;
    left: 0;
  }

  .drag-handle {
    cursor: default;
    height: 30px;
    background: url('/img/bash/top_bg.png') repeat-x;
    width: auto;
    margin-left: 30px;
    margin-right: 74px;
    padding-top: 7px;
    padding-left: 32px;
    text-align: center;
    font-weight: bold;
  }

  .drag-handle-right {
    height: 30px;
    width: 28px;
    background: url('/img/bash/top_right.png') no-repeat;
    position: absolute;
    top: 0;
    right: 0;
  }

  .drag-handle-right:hover {
    background: url('/img/bash/top_right_hover.png') no-repeat;
    cursor: default;
  }

  .drag-handle-max {
    height: 30px;
    width: 23px;
    background: url('/img/bash/top_max.png') no-repeat;
    position: absolute;
    top: 0;
    right: 28px;
  }

  .drag-handle-max:hover { 
    background: url('/img/bash/top_max_hover.png') no-repeat;
    cursor: default;
  }

  .drag-handle-min {
    height: 30px;
    width: 23px;
    background: url('/img/bash/top_min.png') no-repeat;
    position: absolute;
    top: 0;
    right: 51px;
  }

  .drag-handle-min:hover { 
    background: url('/img/bash/top_min_hover.png') no-repeat;
    cursor: default;
  }

  .konsole_left {
    width: 2px;
    background: url('/img/bash/left_bg.png') repeat-y;
    position: absolute;
    top: 30px;
    left: 0;
    height: 325px;
  }

  .konsole_right {
    width: 2px;
    background: url('/img/bash/right_bg.png') repeat-y;
    position: absolute;
    height: 325px;
    top: 30px;
    right: 0;
  }

  .konsoleuser { background: url('/img/bash/user_bg.png') repeat; cursor: text; }
  .konsoleroot { background: url('/img/bash/root_bg.png') repeat; cursor: text; }

  .vdr {
    background-size: cover;
    backdrop-filter: blur(17px);
    font-family: "Lucida Console", Monospace, "DejaVu Sans Mono", "Courier New", MiscFixed;
    font-size: 12px;
    /* white-space: pre; */
    color: #fcfcfc;
    overflow: hidden;
    position: absolute;
    top: 30px;
    left: 2px;
    height: 316px !important;
    width: 586px !important;
    padding: 0;
  }

  .resize-handle-mr {
    width: 2px;
    background: url('/img/bash/right_bg.png') repeat-y;
    position: absolute;
    height: 325px;
    top: 30px;
    right: 0;
  }

  .konsole_bottom_left {
    width: 3px;
    height: 3px;
    background: url('/img/bash/bottom_left.png') no-repeat;
    position: absolute;
    bottom: 0;
    left: 0;
  }

  .konsole_bottom {
    height: 2px;
    background: url('/img/bash/bottom_bg.png') repeat-x;
    position: absolute;
    bottom: 0;
    left: 2px;
    width: 595px;
  }

  .konsole_bottom_right {
    height: 3px;
    width: 3px;
    background: url('/img/bash/bottom_right.png') no-repeat;
    position: absolute;
    right: 0;
    bottom: 0;
  }

  .konsole_input, .konsole_input:focus, .konsole_input:disabled {
    width: 100%;
    background: transparent;
    border-color: transparent;
    outline: none;
    caret-color: #fcfcfc;
    color: #fcfcfc;
    line-height: 14px;
  }

  .icon {
    transition: background 0.3s;
  }

  .icon:hover {
    background-color:#eff0f180;
  }
</style>
