

import { TableColumnCtx } from 'element-plus';
import { ElTag } from 'element-plus';
import { h } from 'vue';
import type { FormSchema } from '@/types/form';
export const columns: Partial<TableColumnCtx<any>>[] = [
  {
    label: '用户名',
    prop: 'username',
    align: 'center',
    width: 120,
  },
  {
    label: '请求ip',
    prop: 'ip',
    align: 'center',
    width: 120,
  },
  {
    label: '对话角色',
    prop: 'role',
    align: 'center',
    width: 100,
    formatter: (row: any) => {
      return h(
        ElTag,
        {
          type: row.role === 'user' ? 'success' : 'danger',
          size: 'small',
        },
        { default: () => row.role }
      );
    },
  },
  {
    label: '模型名称',
    prop: 'model',
    align: 'center',
    width: 100,
  },
  {
    label: 'Token消耗',
    prop: 'tokens',
    align: 'center',
    width: 100,
  },
  {
    label: '提示词Token消耗',
    prop: 'promptTokens',
    align: 'center',
    width: 120,
  },
  {
    label: '消息内容',
    prop: 'message',
    formatter: (row: any) => {
      return String(row.message).replace(/```|\n/g, '');
    },
  },
  {
    label: '会话时间',
    prop: 'createTime',
    width: 180,
    align: 'center',
  },
];

export const searchSchemas: FormSchema[] = [
  {
    field: 'text',
    component: 'Input',
    label: '内容',
    componentProps: {
      placeholder: '请输入内容查询',
    },
  },
  {
    field: 'username',
    component: 'Input',
    label: '用户名',
    componentProps: {
      placeholder: '请输入用户名查询',
    },
  },
  {
    field: 'role',
    component: 'Select',
    label: '对话角色',
    componentProps: {
      placeholder: '请选择对话角色查询',
      style: {
        width: '140px',
      },
      options: [
        {
          label: 'user',
          value: 'user',
        },
        {
          label: 'assistant',
          value: 'assistant',
        },
      ],
    },
  },
];
