<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 { ElTabs, ElTabPane, ElButton, ElSpace } from 'element-plus';
import { ref } from 'vue';
import {
  inflowLossRecordColumns,
  inflowLossStatisticsColumns,
  inflowLossRecordQuerySchema,
  inflowLossStatisticsQuerySchema,
  mockInflowLossRecordData,
  mockInflowLossStatisticsData
} from './oilInflowReport-data';

// Tab切换
const activeTab = ref('record'); // 默认激活“进油损溢记录”Tab

// 通用表单配置
const commonFormOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: { allowClear: true },
  },
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4',
};

// 通用表格配置
const commonGridOptions: Omit<VxeGridProps, 'columns' | 'proxyConfig'> = {
  height: '800px',
  rowConfig: { keyField: 'id' },
  pagerConfig: { enabled: true, pageSize: 100, pageSizes: [10, 20, 50, 100] },
};

// 创建表格实例
const [InflowLossRecordTable] = useVbenVxeGrid({ 
  formOptions: {
    ...commonFormOptions,
    schema: inflowLossRecordQuerySchema(),
  },
  gridOptions: {
    ...commonGridOptions,
    columns: inflowLossRecordColumns,
    proxyConfig: {
      autoLoad: true,
      ajax: {
        query: async () => ({ items: mockInflowLossRecordData, total: mockInflowLossRecordData.length }),
      },
    },
  },
});

const [InflowLossStatisticsTable] = useVbenVxeGrid({ 
  formOptions: {
    ...commonFormOptions,
    schema: inflowLossStatisticsQuerySchema(),
  },
  gridOptions: {
    ...commonGridOptions,
    columns: inflowLossStatisticsColumns,
    proxyConfig: {
      autoLoad: true,
      ajax: {
        query: async () => ({ items: mockInflowLossStatisticsData, total: mockInflowLossStatisticsData.length }),
      },
    },
  },
});

// 导出按钮点击事件
const handleExport = () => {
  console.log('导出数据');
  // TODO: 添加导出逻辑
};
</script>

<template>
  <Page :auto-content-height="true">
    <div class="oil-inflow-report-container">
      <!-- Tab切换 -->
      <ElTabs v-model="activeTab" class="mb-4">
        <ElTabPane label="进油损溢记录" name="record">
          <InflowLossRecordTable table-title="进油损溢记录列表">
            <template #toolbar-tools>
              <ElSpace>
                <ElButton @click="handleExport">
                  导出
                </ElButton>
              </ElSpace>
            </template>
          </InflowLossRecordTable>
        </ElTabPane>
        <ElTabPane label="进油损溢统计" name="statistics">
          <InflowLossStatisticsTable table-title="进油损溢统计列表">
            <template #toolbar-tools>
              <ElSpace>
                <ElButton @click="handleExport">
                  导出
                </ElButton>
              </ElSpace>
            </template>
          </InflowLossStatisticsTable>
        </ElTabPane>
      </ElTabs>
    </div>
  </Page>
</template>

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