"use client";

import { createContext, type ReactNode } from "react";
import { useApps, type UseAppsReturn } from "@/hooks/useApps";

export const AppsContext = createContext<UseAppsReturn>({
  hosts: [],
  categories: [],
  apps: [],
  loading: true,
  error: null,
  addHost: () => Promise.reject(new Error("No AppsProvider")),
  updateHost: () => Promise.reject(new Error("No AppsProvider")),
  deleteHost: () => Promise.reject(new Error("No AppsProvider")),
  addCategory: () => Promise.reject(new Error("No AppsProvider")),
  updateCategory: () => Promise.reject(new Error("No AppsProvider")),
  deleteCategory: () => Promise.reject(new Error("No AppsProvider")),
  addApp: () => Promise.reject(new Error("No AppsProvider")),
  updateApp: () => Promise.reject(new Error("No AppsProvider")),
  deleteApp: () => Promise.reject(new Error("No AppsProvider")),
  updateViewOrder: () => Promise.reject(new Error("No AppsProvider")),
  uploadIcon: () => Promise.reject(new Error("No AppsProvider")),
  refresh: () => {},
});

export function AppsProvider({ children }: { children: ReactNode }) {
  const apps = useApps();
  return <AppsContext value={apps}>{children}</AppsContext>;
}
