<script setup lang="ts">
import { computed, ref, defineExpose } from 'vue'
import type { AnyChartInput } from '@/types/chart'
import { buildOption } from '@/lib/chartFactory'
import BaseEChart from './BaseEChart.vue'

const props = defineProps<{ data: AnyChartInput | null; overlayControls?: boolean }>()
const option = computed(() => (props.data ? buildOption(props.data) : null))
const base = ref<InstanceType<typeof BaseEChart> | null>(null)

defineExpose({
  saveImage: () => base.value?.saveImage?.(),
  restore: () => base.value?.restore?.(),
  resize: () => base.value?.resize?.(),
})
</script>

<template>
  <BaseEChart v-if="option" ref="base" :option="option" />
</template>
