import React from "react";
import QrCodeHandleWarehouseSearch from "./qrCodeHandleWarehouseSearch";
import QrCodeHandleSearchLoading from "./qrCodeHandleSearchLoading";
import { fetchWarehouseList, WarehouseResult } from "@/app/api/warehouse";
import { fetchPrinterCombo, PrinterCombo } from "@/app/api/settings/printer";

interface SubComponents {
  Loading: typeof QrCodeHandleSearchLoading;
}

const QrCodeHandleWarehouseSearchWrapper: React.FC & SubComponents = async () => {
  let warehouses: WarehouseResult[] = [];
  let printerCombo: PrinterCombo[] = [];
  
  try {
    warehouses = await fetchWarehouseList();
  } catch (error) {
    console.error("Error fetching warehouse list:", error);
  }
  
  try {
    printerCombo = await fetchPrinterCombo();
  } catch (error) {
    console.error("Error fetching printer combo:", error);
  }
  
  return <QrCodeHandleWarehouseSearch warehouses={warehouses} printerCombo={printerCombo} />;
};

QrCodeHandleWarehouseSearchWrapper.Loading = QrCodeHandleSearchLoading;

export default QrCodeHandleWarehouseSearchWrapper;