<template>
  <fs-page class="fs-page-custom">
    <fs-crud ref="crudRef" v-bind="crudBinding">
      <template #search-left>
        <DateRangePicker v-model="dateRange"></DateRangePicker>
      </template>
      <template #header-middle>
        <DataTendencyChart
          :query="queryParams"
          :fetchCard="getCardData"
          :fetchLine="getLineData"
          :fetch-line-month="getLineMonthData"
          :fetch-line-week="getLineWeekData">
        </DataTendencyChart>
      </template>
      <template #cell_adGroupName="scope">
        <el-tooltip effect="dark" :content="scope.row.campaignName" placement="top">
          <el-link type="primary" :underline="false" @click="jumpAds(scope.row)">
            <div class="en-text">{{ scope.row.adGroupName }}</div>
          </el-link>
        </el-tooltip>
      </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 {LocationQueryValue, useRouter} from 'vue-router'
import DateRangePicker from '/@/components/DateRangePicker/index.vue'
import {usePublicData} from '/@/stores/publicData'
import {storeToRefs} from 'pinia'
import DataTendencyChart from '/@/views/adManage/sd/chartComponents/dataTendency.vue'
import {getCardData, getLineData, getLineMonthData, getLineWeekData } from './api'

const publicData = usePublicData()
const router = useRouter()
interface Props {
  campaignId: LocationQueryValue | LocationQueryValue[]
}
const props = defineProps<Props>()
const { dateRange } = storeToRefs(publicData)
const queryParams = ref({
  campaignId: props.campaignId,
  dateRange
})
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: queryParams })

onMounted(() => {
	crudExpose.doRefresh()
})
const jumpAds = (row: any) => {
  router.push({
    name: 'SdAdGroupDetail',
    query: { adGroupId: row.adGroupId, campaignId: row.campaignId, targetingType: row.targetingType, tagsViewName: row.adGroupName }
  })
}
watch(
  queryParams,
  async () => {
    crudExpose.doRefresh()
  },
  { deep: true }
)

</script>

<style scoped>
.en-text {
  max-width: 100%;
  font-size: 13px;
  font-weight: 420;
  word-break: break-word;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

</style>
