import React from "react";
import PrinterSearch from "./PrinterSearch";
import PrinterSearchLoading from "./PrinterSearchLoading";
import { PrinterResult, fetchPrinters } from "@/app/api/settings/printer";

interface SubComponents {
  Loading: typeof PrinterSearchLoading;
}

const PrinterSearchWrapper: React.FC & SubComponents = async () => {
  let printers: PrinterResult[] = [];
  try {
    printers = await fetchPrinters();
    console.log("Printers fetched:", printers);
  } catch (error) {
    console.error("Error fetching printers:", error);
    printers = [];
  }

  return <PrinterSearch printers={printers} />;
};

PrinterSearchWrapper.Loading = PrinterSearchLoading;

export default PrinterSearchWrapper;
