import api from '../api';

export type MediaLibraryItem = {
  id: string;
  filename: string;
  url: string;
  mimeType: string;
  category?: string;
};

/** 媒体库图片（默认全部分类，供「从媒体库选择」使用） */
export async function fetchMediaLibraryImages(opts?: {
  category?: string;
  pageSize?: number;
}): Promise<MediaLibraryItem[]> {
  const params: Record<string, string | number> = {
    pageSize: opts?.pageSize ?? 200,
    imagesOnly: '1',
  };
  if (opts?.category?.trim()) {
    params.category = opts.category.trim();
  }
  const { data } = await api.get('/admin/files', { params });
  return (data.data?.items ?? []) as MediaLibraryItem[];
}
