<template>
  <div class="toolbar">
    <template v-if="props.isEdit">
      <ToolbarIcon :src="deleteIcon" :active="false" @click="emits('remove')" tip="删除电子围栏" />
      <ToolbarIcon :src="saveIcon" :active="false" @click="emits('save')" tip="保存电子围栏" />
    </template>

    <ElButton type="primary" size="small" @click="toggleEdit">{{
      props.isEdit ? '退出编辑' : '编辑电子围栏'
    }}</ElButton>
    <div class="fenceDrawingTip" v-if="isEdit"
      >{{ cameraAlgoStore.selectedAlgoDetail?.algoInfo?.name }}算法绘制中</div
    >
  </div>
</template>
<script setup lang="ts">
  import { defineEmits } from 'vue';
  import { ElButton } from 'element-plus';
  import ToolbarIcon from '../ToolbarIcon/ToolbarIcon.vue';
  import saveIcon from '@/assets/images/camera/save.png';
  import deleteIcon from '@/assets/images/camera/delete.png';
  import useCameraAlgoStore from '../../store/useCameraAlgoStore';

  const cameraAlgoStore = useCameraAlgoStore();

  const props = defineProps<{ isEdit: boolean }>();

  const emits = defineEmits<{
    (e: 'toggleEditable', editState: boolean): unknown;
    (e: 'remove'): unknown;
    (e: 'save'): unknown;
  }>();

  const toggleEdit = () => {
    emits('toggleEditable', !props.isEdit);
  };
</script>

<style scoped>
  .toolbar {
    display: flex;

    align-items: center;
    z-index: 10;
    padding: 5px 30px;
    border-radius: 50px;
  }
  .fenceDrawingTip {
    background: #e6f4ff;
    border-radius: 6px;
    border: 1px solid #bae0ff;
    text-align: center;
    font-size: 12px;
    padding: 2px 40px;
    margin-left: 50px;
  }
</style>
