import { ref, computed } from "vue";

// 模拟节目单数据（TODO: 实际从 EPG 获取）
const MOCK_PROGRAMS = [
  { id: 1, time: "08:00", title: "朝闻天下", isCurrent: false },
  { id: 2, time: "09:00", title: "今日说法", isCurrent: false },
  { id: 3, time: "10:00", title: "电视剧:繁花", isCurrent: true },
  { id: 4, time: "12:00", title: "新闻30分", isCurrent: false },
  { id: 5, time: "13:00", title: "电视剧:西游记", isCurrent: false },
  { id: 6, time: "15:00", title: "动画剧场", isCurrent: false },
  { id: 7, time: "19:00", title: "新闻联播", isCurrent: false },
];

export function usePrograms() {
  const selectedProgram = ref(null);
  const programs = ref([...MOCK_PROGRAMS]);

  // 选择节目
  function selectProgram(program) {
    selectedProgram.value = program;
    return program;
  }

  // 加载指定日期的节目（TODO: 实际从 EPG 获取）
  function loadProgramsByDate(dateValue) {
    // TODO: 根据日期加载节目单
    console.log("加载节目单:", dateValue);
  }

  // 更新节目单
  function setPrograms(newPrograms) {
    programs.value = newPrograms;
  }

  return {
    selectedProgram,
    programs,
    selectProgram,
    loadProgramsByDate,
    setPrograms,
  };
}
