import axios from 'axios';

const JINGROW_SERVER_URL = process.env.JINGROW_SERVER_URL;

export async function GET(request) {
  try {
    const { searchParams } = new URL(request.url);
    const pagetype = searchParams.get('pagetype');
    const category = searchParams.get('category');
    const count = searchParams.get('count');
    if (!pagetype) {
      return Response.json({ error: '缺少pagetype参数' }, { status: 400 });
    }
    const response = await axios.get(
      `${JINGROW_SERVER_URL}/api/method/jsite.api.v1.get_listview_data`,
      { params: { pagetype, category, count } }
    );
    const data = response.data.message?.data || [];
    return Response.json({ data });
  } catch (error) {
    return Response.json(
      { error: error.message, detail: error?.response?.data || null },
      { status: 500 }
    );
  }
}
