'use client';
import useSWR from 'swr';
import { ClosingApi } from '@/services/api/closing';
import { isResponseSuccess } from '@/lib/api-helper';
import { formatNumber } from '@/lib/helper';
interface ClosingProductionDataTabContentProps {
projectFlockId: number;
}
const ClosingProductionDataTabContent = ({
projectFlockId,
}: ClosingProductionDataTabContentProps) => {
const { data: productionData, isLoading } = useSWR(
`${ClosingApi.basePath}/${projectFlockId}/production-data`,
() => ClosingApi.getProductionData(projectFlockId)
);
if (isLoading) {
return (
);
}
if (!productionData || !isResponseSuccess(productionData)) {
return (
Gagal memuat data produksi.
);
}
const { purchase, sales, performance } = productionData.data;
// Helper for consistent row styling
const DataRow = ({
label,
value,
unit = '',
valueClassName = 'font-bold text-gray-800',
unitClassName = 'text-gray-500 w-12 text-right',
}: {
label: string;
value: string | number;
unit?: string;
valueClassName?: string;
unitClassName?: string;
}) => (
{label}
{value}
{unit && {unit}}
);
return (
Data Produksi
{/* Left Column */}
{/* Purchase Section */}
{/* Sales Section */}
Penjualan
{/* Chicken Sales */}
{/* Egg Sales (if available) */}
{sales.egg && (
<>
>
)}
{/* Divider Line (Absolute centered) */}
{/* Right Column */}
{/* Performance Section */}
Performance
{/* Laying Specific Fields */}
{performance.hen_day_act !== undefined && (
<>
>
)}
{performance.egg_mass !== undefined && (
<>
>
)}
{performance.egg_weight !== undefined && (
<>
>
)}
{performance.hen_housed_act !== undefined && (
<>
>
)}
);
};
export default ClosingProductionDataTabContent;