<template>
  <div class="panel panel-preview">
    <div class="panel-title">小程序预览</div>
    <div class="preview-wrap">
      <EditorPreview
        ref="previewRef"
        :editor-json="editorJson"
        :selected-page="selectedPage"
        :test-detail-id="testDetailId"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import EditorPreview from './EditorPreview.vue';
import type { IHomeCommonCategoryDefine } from '../../CommonCategoryDefine';

defineProps<{
  editorJson: IHomeCommonCategoryDefine;
  selectedPage: (IHomeCommonCategoryDefine['page'][0]) | null;
  testDetailId: number;
}>();

const previewRef = ref<InstanceType<typeof EditorPreview> | null>(null);

defineExpose({
  refresh() {
    previewRef.value?.refresh?.();
  },
});
</script>

<style scoped>
.panel-preview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}
.panel-title {
  padding: 8px 12px;
  font-weight: 600;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}
.preview-wrap {
  width: 100%;
  max-width: 450px;
  aspect-ratio: 9 / 16;
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 0 auto;
}
</style>
