<template>
  <div>
    <!-- 浮动表单侧边栏（覆盖在地图上） -->
    <transition name="slide-right">
      <el-card 
        v-show="!collapsed" 
        shadow="always" 
        class="form-sidebar-overlay"
      >
        <div slot="header" class="card-header">
          <span>接警录入</span>
          <div>
            <el-button type="text" size="mini" icon="el-icon-arrow-right" @click="handleCollapse">收起</el-button>
          </div>
        </div>
        <slot></slot>
      </el-card>
    </transition>

    <!-- 浮动展开按钮（当侧边栏折叠时显示） -->
    <transition name="fade">
      <el-button
        v-if="collapsed"
        class="expand-form-btn"
        type="primary"
        icon="el-icon-arrow-left"
        circle
        @click="handleExpand"
      ></el-button>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'MapFormSidebar',
  props: {
    collapsed: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleCollapse() {
      this.$emit('update:collapsed', true)
    },
    handleExpand() {
      this.$emit('update:collapsed', false)
    }
  }
}
</script>

<style lang="scss" scoped>
/* 浮动表单侧边栏（覆盖在地图上） */
.form-sidebar-overlay {
  position: absolute;
  top: 80px;
  right: 24px;
  width: 380px;
  max-height: calc(100vh - 200px);
  z-index: 200;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.form-sidebar-overlay .el-card__body {
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
}

.form-sidebar-overlay .el-card__header {
  padding: 16px 20px;
  border-bottom: 1px solid #ebeef5;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 14px;
}

/* 侧边栏展开/收起动画（从右侧滑入） */
.slide-right-enter-active {
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.slide-right-leave-active {
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.slide-right-enter, .slide-right-leave-to {
  transform: translateX(100%);
  opacity: 0;
}

/* 浮动展开按钮 */
.expand-form-btn {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter, .fade-leave-to {
  opacity: 0;
}

@media screen and (max-width: 768px) {
  /* 移动端：表单侧边栏全宽 */
  .form-sidebar-overlay {
    top: 60px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: calc(100vh - 120px);
  }
  
  .expand-form-btn {
    right: 16px;
    bottom: 80px;
    top: auto;
    transform: none;
  }
}

@media screen and (max-width: 1200px) {
  /* 中等屏幕：调整侧边栏宽度 */
  .form-sidebar-overlay {
    width: 340px;
  }
}
</style>