import { Outlet } from "@remix-run/react";
import { redirect, type LoaderFunctionArgs, type MetaFunction } from "@remix-run/node";

export const meta: MetaFunction = () => {
  return [
    { title: "文档列表 - 中国烟草AI合同及卷宗审核系统" },
    { name: "documents", content: "文档列表,新增,修改" }
  ];
};

export const handle = {
  breadcrumb: "文档列表"
};

export async function loader({ request }: LoaderFunctionArgs) {
  const url = new URL(request.url);

  if (url.pathname === '/documents') {
    const query = url.searchParams.toString();
    throw redirect(query ? `/documents/list?${query}` : '/documents/list');
  }

  return null;
}

/**
 * 文档列表路由布局
 */
export default function DocumentsLayout() {
  return <Outlet />;
}
