<template>
  <fs-page class="fs-page-custom">
    <fs-crud ref="crudRef" v-bind="crudBinding">
      <template #search-left>
        <DateRangePicker v-model="dateRange"></DateRangePicker>
      </template>

      <template #cell_query="scope">
        <el-tooltip effect="dark" :content="scope.row.query" placement="top">
          <div class="en-text">{{ scope.row.query }}</div>
        </el-tooltip>
      </template>
      <template #cell_keywordText="scope">
        <el-tooltip effect="dark" :content="scope.row.keywordText" placement="top">
            <div class="en-text">{{ scope.row.keywordText }}</div>
        </el-tooltip>
      </template>
      <template v-for="field of Object.keys(BaseColumn)" #[`cell_${field}`]="scope">
        <DataCompare
          :field="field"
          :value="scope.row[field]"
          :prev-val="scope.row[`prev${field}`]"
          :gap-val="scope.row[`gap${field}`]"
          :date-range="dateRange"
          :show-compare="showCompare"
        />
      </template>
      <template #toolbar-left>
        <div class="campare-switch">
          <span>数据对比 </span>
          <el-switch v-model="showCompare" size="small" />
        </div>
      </template>
    </fs-crud>
  </fs-page>
</template>

<script lang="ts" setup>
import { ref, onMounted, computed, watch, onBeforeMount } from 'vue'
import { useFs, FsPage } from '@fast-crud/fast-crud'
import { createCrudOptions } from './crud'
// import { useShopInfo } from '/@/stores/shopInfo'
import { usePublicData } from '/@/stores/publicData'
import { storeToRefs } from 'pinia'
import { LocationQueryValue } from 'vue-router'
import { BaseColumn } from '/@/views/adManage/utils/commonTabColumn.js'
import DataCompare from '/@/components/dataCompare/index.vue'
import DateRangePicker from '/@/components/DateRangePicker/index.vue'

interface Props {
  adGroupId: LocationQueryValue | LocationQueryValue[]
}
const props = defineProps<Props>()
// const shopInfo = useShopInfo()
const publicData = usePublicData()
const { dateRange } = storeToRefs(publicData)
// const { profile } = storeToRefs(shopInfo)
const queryParams = ref({
  adGroupId: props.adGroupId,
  dateRange,
})
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: queryParams })
const showCompare = ref(false)

onMounted(async () => {
  crudExpose.doRefresh()
})
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>
