<template>
  <div class="editor-page">
    <div class="workspace">
      <!-- 左侧预览区 -->
      <div class="preview-area col" ref="previewAreaRef">
        <div class="preview-scroll">
          <slot name="preview">
            <!-- <PhoneMockup>
              <StatusBar />
            </PhoneMockup> -->
            <BalancePreview> </BalancePreview>
          </slot>
        </div>
      </div>
      <!-- 右侧配置区 -->
      <div class="panel-area col">
        <div class="panel-header">
          <div class="tabs-container">
            <div v-for="tab in tabs" :key="tab.value" class="tab-item" :class="{ active: activeTab === tab.value }"
              @click="handleTabClick(tab)">
              {{ tab.label }}
            </div>
          </div>
          <div>
            <slot name="actions">
              <div class="btn-box">
                <img src="@/public/simulator/save-btn.png" alt="" class="save-btn btn" @click="$emit('save')">
                <img src="@/public/simulator/export-btn.png" alt="" class="export-btn btn" @click="$emit('export')">
              </div>
            </slot>
          </div>
        </div>
        <div class="panel-scroll">
          <div class="setting-list">
            <slot name="config"></slot>
          </div>
        </div>
      </div>
    </div>
  </div>
  <WarningFooter />
</template>

<script setup>
import { ref } from 'vue'
import { FolderAdd, Download } from '@element-plus/icons-vue'
import WarningFooter from '@/components/common/WarningFooter.vue'
import PhoneMockup from '@/components/simulator/PhoneMockup.vue'
import StatusBar from '@/components/simulator/StatusBar.vue'

defineProps({
  tabs: {
    type: Array,
    default: () => [{ label: '编辑设置', value: 'edit' }]
  },
  activeTab: {
    type: String,
    default: 'edit'
  }
})

const emit = defineEmits(['save', 'export', 'update:activeTab', 'tab-click'])

function handleTabClick(tab) {
  emit('update:activeTab', tab.value)
  emit('tab-click', tab)
}

const previewAreaRef = ref()
// 将 ref 暴露出去，供外部水印或导出截图逻辑使用
defineExpose({ previewAreaRef })
</script>

<style lang="scss" scoped>
.editor-page {
  height: calc(100vh - 166px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: #FAFAFB;
}

.workspace {
  display: flex;
  gap: 16px;
  flex: 1;
  padding: 40px 10px 80px;
  min-width: 1400px;
  max-width: 1440px;
  margin: 0 auto;
  overflow: hidden;
}

.preview-area {
  flex: 0 0 350px;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;

  .preview-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 24px;
  }
}

/* ===== 列统一样式 ===== */
.col {
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 0 18px;
    padding-left: 56px;
    height: 49px;
    background: rgba(255, 255, 255, .85);
    border-bottom: 1px solid #D8D8D8;

    .tabs-container {
      display: flex;
      align-items: center;
      height: 100%;
      gap: 30px;

      .tab-item {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 18px;
        color: #1A1A1A;
        line-height: 20px;
        padding: 0 14px;
        cursor: pointer;
        position: relative;
        transition: color 0.2s;

        &:hover {
          color: #666;
        }

        &.active {
          color: #333;
          font-weight: bold;

          &::after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            right: 0;
            height: 3px;
            background-color: #5AC878;
            border-radius: 3px 3px 0 0;
          }
        }
      }
    }

    .btn-box {
      gap: 16px;
      display: flex;
      align-items: center;

      .btn {
        height: 30px;
        cursor: pointer;
        transition: opacity 0.2s;

        &:hover {
          opacity: 0.85;
        }
      }
    }
  }

  .panel-scroll {
    flex: 1;
    overflow-y: auto;
    max-height: 100%;
    padding: 18px 68px 0;

    .setting-list {
      height: 100%
    }
  }
}

/* 编辑设置面板 - 浅紫主题 */
.panel-area {
  flex: 1;
  width: 1000px;
  background-color: #ffffff;
  box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  border-radius: 18px !important;
  /* 浅紫 */

  /* 穿透样式让插槽内部也能复用相同的配置项样式 */
  :deep(.setting-list) {
    .section-label {
      font-weight: bold;
      font-size: 16px;
      color: #1A1A1A;
    }

    .status-row {
      display: flex;
      gap: 10px;

      .setting-item {
        margin-bottom: 0;
        margin-right: 40px;
      }
    }

    .section-divider {
      height: 1px;
      background: rgba(94, 53, 177, .12);
      margin: 18px 0 14px;
    }

    .setting-item {
      margin-bottom: 14px;

      label {
        display: block;
        font-weight: 400;
        font-size: 14px;
        color: #767676;
        line-height: 20px;
        margin-top: 16px;
        margin-bottom: 8px;
      }

      .el-input__wrapper,
      .el-radio-group,
      .el-input-number,
      .el-select__wrapper,
      .rich-editor {
        width: 100%;
        height: 30px;
        border-radius: 4px;
        // box-shadow: 0 1px 3px #D8D8D880, 0 0 0 1px #D8D8D8;
        transition: box-shadow .2s;

        &:hover {
          box-shadow: 0 2px 6px rgba(94, 53, 177, .12), 0 0 0 1px rgba(94, 53, 177, .1) inset;
        }

        &.is-focus,
        &.is-focused,
        &:focus {
          box-shadow: 0 0 0 1px rgba(103, 58, 183, .4) inset;
          outline: none;
        }
      }

      .is-checked {
        .el-switch__core {
          background: linear-gradient(215deg, #A679F4 7.14%, #778CF5 100%);
          border: none;
        }
      }

      .el-select {
        width: 100%;
      }

      .el-time-picker {
        width: 100%;
      }

      .el-input-number {
        .el-input__inner {
          text-align: left;
        }
      }

      .el-checkbox__label {
        color: #555;
        font-size: 13px;
      }

      .el-slider {
        .el-slider__bar {
          background: linear-gradient(215deg, #A679F4 7.14%, #778CF5 100%);
        }

        .el-slider__button {
          width: 14px;
          height: 14px;
          background: linear-gradient(215deg, #A679F4 7.14%, #778CF5 100%);
          border: none;
        }

        span {
          font-weight: 400;
          font-size: 14px !important;
          color: #1A1A1A !important;
          line-height: 20px !important;
        }
      }

    }

    .switch-item {
      display: flex;
      align-items: center;
      justify-content: space-between;

      label {
        margin-bottom: 0;
      }
    }
  }
}
</style>
