import dayjs from 'dayjs';
import { api } from './api';

export type Article = {
  id: string;
  title: string;
  coverImage: string;
  htmlContent: string;
  publishedAt: string; // ISO string
  readCount: number;
};

const demoArticles: Article[] = [
  {
    id: 'intro-pilates-posture',
    title: '新手入门：普拉提核心与体态的关系',
    coverImage: 'https://plates-1251306435.cos.ap-guangzhou.myqcloud.com/images/imagedemo.jpeg',
    publishedAt: dayjs().subtract(2, 'day').toISOString(),
    readCount: 1268,
    htmlContent: `
      <h2>为什么核心很重要？</h2>
      <p>核心是维持良好体态与动作稳定的关键。普拉提通过强调呼吸与深层肌群激活，帮助你在<em>日常站立、坐姿与训练</em>中保持更好的身体对齐。</p>
      <h3>入门建议</h3>
      <ol>
        <li>从呼吸开始：尝试<strong>胸廓外扩</strong>而非耸肩。</li>
        <li>慢而可控：注意动作过程中的连贯与专注。</li>
        <li>记录变化：每周拍照或在应用中记录体态变化。</li>
      </ol>
      <p>更多实操可在本应用的「AI体态评估」中获取个性化建议。</p>
      <img src="https://plates-1251306435.cos.ap-guangzhou.myqcloud.com/images/ImageCheck.jpeg" alt="pilates-illustration" />
    `,
  },
];

export function listRecommendedArticles(): Article[] {
  // 实际项目中可替换为 API 请求
  return demoArticles;
}

export async function getArticleById(id: string): Promise<Article | undefined> {
  return api.get<Article>(`/articles/${id}`);
}


