<script lang="ts" setup>
// 导入部分
import type { VbenFormProps } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { ElButton, ElSpace } from 'element-plus';
import { tableColumns, SECURITY_CHECK_MOCK_DATA, queryFormSchema } from './securityCheck-data';
import { useRouter } from 'vue-router';
// 路由实例
const router = useRouter();
// 表单配置
const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: { allowClear: true },
  },
  schema: queryFormSchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4',
};

// 安全检查报表表格配置
const workReportGridOptions: VxeGridProps = {
  columns: tableColumns,
  height: '800px',
  proxyConfig: {
    autoLoad: true,
    ajax: {
      query: async () => ({ items: SECURITY_CHECK_MOCK_DATA, total: SECURITY_CHECK_MOCK_DATA.length })
    },
  },
  rowConfig: { keyField: 'id' },
  pagerConfig: { enabled: true, pageSize: 100, pageSizes: [10, 20, 50, 100] },
};

// 创建表格实例
const [WorkReportTable] = useVbenVxeGrid({ formOptions, gridOptions: workReportGridOptions });

// 查看按钮点击事件
const handleView = (row: any) => {
  console.log('查看详情', row);
  router.push(`/schedule/detail/${row.id}`);
  // TODO: 添加查看详情逻辑
};
</script>

<template>
  <Page :auto-content-height="true">
    <div class="security-check-container">
      <!-- 安全检查报表表格 -->
      <div class="table-container">
        <WorkReportTable table-title="安全检查报表">
          <template #toolbar-tools>
            <ElSpace>
              <ElButton 
                @click="handleExport"
                v-access:code="['system:securityCheck:export']"
              >
                导出
              </ElButton>
            </ElSpace>
          </template>
          <template #action="{ row }">
            <ElSpace>
              <ElButton 
                type="primary"
                size="small"
                @click="handleView(row)"
              >
                查看
              </ElButton>
            </ElSpace>
          </template>
        </WorkReportTable>
      </div>
    </div>
  </Page>
</template>

<style scoped lang="scss">
.security-check-container {
  min-height: calc(100vh - 120px);
  padding: 16px;
  background-color: #fff;
}
</style>
