diff --git a/src/components/pages/closing/ClosingProductionDataTabContent.tsx b/src/components/pages/closing/ClosingProductionDataTabContent.tsx new file mode 100644 index 00000000..ba8a12ed --- /dev/null +++ b/src/components/pages/closing/ClosingProductionDataTabContent.tsx @@ -0,0 +1,268 @@ +'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, variance } = 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}} +
+
+ ); + + // Helper for rows with two values (e.g., Deplesi: Ekor & %) + const DoubleDataRow = ({ + label, + value1, + unit1, + value2, + unit2, + value1ClassName = 'font-bold text-gray-800', + value2ClassName = 'font-bold text-blue-500', + }: { + label: string; + value1: string | number; + unit1: string; + value2: string | number; + unit2: string; + value1ClassName?: string; + value2ClassName?: string; + }) => ( +
+ {label} +
+
+ {value1} + {unit1} +
+
+ {value2} + {unit2} +
+
+
+ ); + + return ( +
+

Data Produksi

+ +
+ {/* Left Column */} +
+ {/* Purchase Section */} +
+

+ Pembelian +

+
+ + + + + + +
+
+ + {/* Sales Section */} +
+

+ Penjualan +

+
+ + + + +
+
+
+ + {/* Divider Line (Absolute centered) */} +
+ + {/* Right Column */} +
+ {/* Performance Section */} +
+

+ Performance +

+
+ + + + + + + + + + +
+
+ + {/* Variance Section (Pushed to bottom) */} +
+

Selisih

+
+ + + +
+
+
+
+
+ ); +}; + +export default ClosingProductionDataTabContent;