<template>
  <div class="panel">
    <div :span="20" class="content">
      <div class="title">我的笔记</div>
      <div class="left-content">
        <NoteList
          ref="NoteList"
          :readOnly="readOnly"
          :currrentFileOnly="currrentFileOnly"
          @insertText="handleInsertText"
          @handleOpenAddUpdateDialog="handleOpenAddUpdateDialog"
        />
      </div>
    </div>
    <div
      :title="visible ? '收起面板' : '插入笔记'"
      :class="['close', !visible ? 'hidden' : '']"
      @click="handleToggleNotePanel"
    >
      <i :class="visible ? 'el-icon-arrow-right' : 'el-icon-edit'"></i>
    </div>
  </div>
</template>

<script>
import NoteList from "./noteList.vue";

export default {
  name: "rightPanel",
  components: {
    NoteList,
  },
  // props: {
  //   // 是否只读，若只读可以新建笔记和查看笔记列表，若可以编辑则只能查看笔记列表
  //   readOnly: {
  //     type: Boolean,
  //     default: true,
  //   },
  //   // 是否只看当前文件的笔记，创作时可以看全部的笔记，pdf时只看当前文件的笔记
  //   currrentFileOnly: {
  //     type: Boolean,
  //     default: true,
  //   },
  // },
  // 子/孙组件中用inject接收父组件传来的值
  inject: ["readOnly", "currrentFileOnly", "fileId"],
  data() {
    return {
      visible: false, //面板的可见性，用于控制按钮是否是悬浮
      tabs: ["新建笔记", "我的笔记"],
      currentTab: "新建笔记",
    };
  },
  methods: {
    // 获取笔记
    loadNoteData() {
      this.$refs.NoteList.loadNoteList();
    },
    //插入文字
    handleInsertText(value) {
      this.$emit("handleInsertText", value);
    },
    // 打开编辑笔记对话框
    handleOpenAddUpdateDialog(item) {
      this.$emit("handleOpenAddUpdateDialog", item);
    },
    // 关闭笔记弹窗
    handleToggleNotePanel() {
      this.visible = !this.visible;
      this.$emit("handleToggleNotePanel");
    },
    // 点击右侧tab
    handleClickTab(tab) {
      this.currentTab = tab;
    },
  },
};
</script>

<style lang="scss" scoped>
.panel {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  border-left: 1px solid #e6ebf5;
  background-color: #fff;
  .content {
    // width: 100%;
    padding-top: 20px;
    flex: 1;
    .title {
      font-weight: bold;
      display: flex;
      justify-content: center;
      margin-bottom: 16px;
    }
    .left-content {
    }
  }
  .top {
    .tabs {
      display: flex;
      justify-content: center;
      .tab-item {
        text-align: center;
        padding: 14px;
        background-color: #eee;
        color: #666;
        cursor: pointer;
        transition: all ease 0.3s;
        &:hover {
          background-color: $theme-blue;
          color: #fff;
        }
      }
      .active {
        background-color: $theme-blue;
        color: #fff;
      }
    }
  }
  .close {
    position: absolute;
    left: 0;
    top: 45%;
    cursor: pointer;
    background-color: #fff;
    transform: translate(-50%, -50%);
    box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px,
      rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    i {
      font-size: 22px;
      color: #d3d3d3;
      transition: all ease 0.5s;
    }
  }
  // 当面板不可见时会显示
  .hidden {
    left: -100px;
    width: 68px;
    height: 68px;
    i {
      color: $theme-blue;
      font-size: 42px;
    }
  }
}
</style>
