<template>
  <div class="panel">
    <!-- <div :span="4" class="top">
      <el-row class="tabs">
        <el-col
          :span="12"
          :class="['tab-item', item == currentTab ? 'active' : '']"
          @click="handleClickTab(item)"
          v-for="(item, index) in tabs"
          :key="index"
        >
          {{ item }}
        </el-col>
      </el-row>
    </div> -->
    <div :span="20" class="content">
      <div class="title">我的笔记</div>
      <div class="left-content">
        <!-- <AddNewNote
          v-if="currentTab==='新建笔记'"
          ref="AddNote"
        /> -->
        <NoteList
          ref="NoteList"
          :readOnly="readOnly"
          @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,
    },
  },
  data() {
    return {
      visible: false, //面板的可见性，用于控制按钮是否是悬浮
      tabs: ["新建笔记", "我的笔记"],
      currentTab: "新建笔记",
    };
  },
  methods: {
    // 获取笔记
    loadNoteData() {
      this.$refs.NoteList.NoteList();
    },
    //插入文字
    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 {
  // display: flex;
  // justify-content: space-between;
  // padding: 20px 0;
  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 {
    // margin-top: 20px;
    // width: 66px;
    // margin-bottom: 10px;
    .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>
