<template>
  <fs-page class="fs-page-custom">
    <fs-crud ref="crudRef" v-bind="crudBinding">
      <template #header-middle>
        <el-tabs v-model="tabActiveName" class="chart-tabs" type="border-card">
          <el-tab-pane label="数据趋势" name="dataTendency">
            <DataTendencyChart
                v-if="tabActiveName === 'dataTendency'"
                :query="queryParams"
                :fetchCard="getCardData"
                :fetchLine="getLineData">
            </DataTendencyChart>
          </el-tab-pane>
          <el-tab-pane label="广告结构" name="adStruct">
            <AdStructChart v-if="tabActiveName === 'adStruct'"/>
          </el-tab-pane>
          <el-tab-pane label="散点视图" name="scatterView"></el-tab-pane>
        </el-tabs>
      </template>
    </fs-crud>
  </fs-page>
</template>

<script lang="ts" setup>
import {onMounted, ref, watch} from 'vue'
import {FsPage, useFs} from '@fast-crud/fast-crud'
import {createCrudOptions} from './crud'
import DataTendencyChart from '/@/views/adManage/sp/chartComponents/dataTendency.vue'
import {useShopInfo} from '/@/stores/shopInfo'
import AdStructChart from './chartComponents/adStruct.vue'
import {getCardData, getLineData} from './api'
import {usePublicData} from '/@/stores/publicData'
import {storeToRefs} from 'pinia'


const tabActiveName = ref('dataTendency')
const shopInfo = useShopInfo()
const publicData = usePublicData()
const {dateRange} = storeToRefs(publicData)
const {profile} = storeToRefs(shopInfo)
const queryParams = ref({
  profileId: profile.value.profile_id,
  dateRange
})
const {crudBinding, crudRef, crudExpose} = useFs({createCrudOptions, context: queryParams})

onMounted(async () => {
  crudExpose.doRefresh()
})

watch(queryParams, async () => {
  crudExpose.doRefresh()
}, { deep: true })

</script>

<style lang="scss">
.chart-tabs {
  margin: 5px 0;

  .el-tabs__nav {
    padding-left: 0 !important;
  }
}
</style>
