"use client";

import { useState } from "react";
import { useRouter } from "next/navigation";
import { usePopCompanyPath } from "@/hooks/usePopCompanyPath";
import { EtcOutbound } from "../../_components/outbound/EtcOutbound";
import { useCartSync } from "../../_components/common/useCartSync";

export default function EtcOutboundPage() {
  const router = useRouter();
  const companyPath = usePopCompanyPath();
  const cart = useCartSync("outbound");
  const [saving, setSaving] = useState(false);

  const handleCartClick = async () => {
    if (cart.isDirty) {
      setSaving(true);
      const ok = await cart.saveToDb();
      setSaving(false);
      if (!ok) return;
    }
    router.push(`${companyPath("/pop/outbound/cart")}?backUrl=${companyPath("/pop/outbound/etc")}`);
  };

  return (
    <EtcOutbound
      cart={cart}
      onCartClick={handleCartClick}
      saving={saving}
      outboundType="기타출고"
      sourceTable="etc_outbound_detail"
    />
  );
}
