Files
frontend/apps/dm/app/(with-layout)/status/_components/GreywaterStatusSection.tsx
T

485 lines
16 KiB
TypeScript

/**
* 중수도
*/
"use client";
import React from "react";
import { useEffect } from "react";
// import SubPageHeader from "@/components/SubPageHeader";
import Image from "next/image";
import { useDmStore } from "@/app/store";
import { formatUsage } from "@/app/common/transValueFormat";
import type {
DmStatusLawYearsType,
DmStatusBildTpYearsType,
DmStatusUsgYearsType,
TableHeaderType,
} from "@/app/store/dm-status/type";
import { Col2Name } from "@/app/store/dm-status/type";
function SectionTitle({ children }: { children: React.ReactNode }) {
return (
<div className="flex items-center gap-3">
<span className="h-5 w-[3px] bg-sky-500" />
<h3 className="text-[24px] font-bold text-neutral-900">{children}</h3>
</div>
);
}
function Hr({ className = "" }: { className?: string }) {
return <div className={`h-[2px] w-full bg-black/10 ${className}`} />;
}
function GreywaterIntroSummary() {
const items = [
{
icon: "/images/landing/icon_recycle.png",
title: "지속적인 인프라 확산",
desc: (
<>
전국 중수도 설치 시설은 2018년 대비 약 45% 증가하여,
<br />
현재 1,000여 개소에서 물 재이용이 활발히 이뤄지고 있습니다.)
</>
),
},
{
icon: "/images/landing/icon_factory.png",
title: "조경용수의 핵심 자원",
desc: (
<>
전체 중수도 이용량의 약 96%가 공업용수로 활용되어,
<br />
산업 현장에서의 상수도 의존도를 낮추는 데 크게 기여하고 있습니다.
</>
),
},
{
icon: "/images/landing/icon_faucet.png",
title: "민간·공공의 협력",
desc: (
<>
공업용 외에도 청소·화장실용수로 꾸준히 사용되며
<br />
우리 생활 곳곳에서 물 자원 낭비를 막고 있습니다.
</>
),
},
];
return (
<div className="mb-[70px] px-[160px]">
<div className="grid grid-cols-[1fr_400px] items-center gap-[60px]">
<div>
<h3 className="text-[40px] font-extrabold leading-[1.35] tracking-[-0.06em] text-neutral-900">
건물 안에서 흐르는 또 하나의 자원,
<br />
<span className="inline-block bg-gradient-to-b from-[#6DBB4F] to-[#01ACE5] bg-clip-text text-transparent">
중수도
</span>
가 물 절약을 실천합니다.
</h3>
<p className="mt-5 text-[16px] leading-[1.8] text-neutral-600">
중수도는 개별 건축물이나 단지 내에서 사용한 물을 다시 처리하여
<br />
청소, 조경, 공업용수로 사용하고 있습니다.
</p>
<div className="mt-10 space-y-8">
{items.map((item) => (
<div key={item.title} className="flex gap-3 items-center">
<div className="mt-1 flex h-12 w-12 shrink-0 items-center justify-center">
<Image src={item.icon} alt="" width={48} height={48} />
</div>
<div>
<strong className="block text-[18px] font-extrabold text-neutral-900">
{item.title}
</strong>
<p className="mt-2 text-[16px] leading-[1.7] tracking-tighter text-neutral-600">
{item.desc}
</p>
</div>
</div>
))}
</div>
</div>
<div className="flex items-center justify-center">
<Image
src="/images/landing/greywater_status_img.png"
alt="중수도 재이용 개념도"
width={400}
height={343}
className="h-auto w-full max-w-[400px]"
priority
/>
</div>
</div>
</div>
);
}
const tableStyles = {
container: "w-[1000px] mx-auto overflow-hidden",
table: "w-full table-fixed border-collapse text-center text-[16px]",
th: "border border-[#858F98] py-3 font-bold text-neutral-800",
td: "border border-[#858F98] py-3 text-neutral-700 font-medium break-keep",
headerBg: "bg-[#E3E7EA]",
};
const headerColors6 = [
"bg-[#01ACE5]",
"bg-[#17AFC7]",
"bg-[#2CB2A9]",
"bg-[#42B58B]",
"bg-[#57B86D]",
"bg-[#81C784]",
];
export default function GreywaterStatusSection() {
const getRswtrByLawYears = useDmStore((state) => state.getRswtrByLawYears);
const getRswtrByBildTpYears = useDmStore((state) => state.getRswtrByBildTpYears);
const getRswtrByUsgYears = useDmStore((state) => state.getRswtrByUsgYears);
const rswtrYears = useDmStore((state) => state.rswtr.rswtrYears);
const selectYear = rswtrYears.slice(-1)[0];
const rswtrByLawYearsHeader = useDmStore((state) => state.rswtr.rswtrByLawYearsHeader);
const rswtrByLawYears = useDmStore((state) => state.rswtr.rswtrByLawYears); // 전체 중수도 설치 및 이용 현황 (공장 및 발전시설 제외)
const rswtrByLawYearsFactory = useDmStore((state) => state.rswtr.rswtrByLawYearsFactory); // 공장 및 발전시설 내 중수도 설치 현황
const rswtrByBildTpYearsHeader = useDmStore((state) => state.rswtr.rswtrByBildTpYearsHeader);
const rswtrByBildTpYears = useDmStore((state) => state.rswtr.rswtrByBildTpYears);
const rswtrByUsgYearsHeader = useDmStore((state) => state.rswtr.rswtrByUsgYearsHeader);
const rswtrByUsgYears = useDmStore((state) => state.rswtr.rswtrByUsgYears);
// 출처 텍스트
function SourceText() {
return (
<p className="mt-7 text-center text-[13px] text-neutral-500">
자료: 하수도정보시스템 {selectYear} 하수도 통계
</p>
);
}
useEffect(() => {
void getRswtrByLawYears('nofactory'); // rswtrByLawYears: 전체 중수도 설치 및 이용 현황 (공장 및 발전시설 제외)
void getRswtrByLawYears('factory'); // rswtrByLawYearsFactory: 공장 및 발전시설 내 중수도 설치 현황
void getRswtrByBildTpYears();
void getRswtrByUsgYears();
}, [getRswtrByLawYears, getRswtrByBildTpYears, getRswtrByUsgYears]);
const renderPartHeaders = (headers: string[], headerColors: string[]) => {
return headers.map((header, index) => (
<th
key={header}
className={`${tableStyles.th} ${headerColors[index] ?? "bg-[#81C784]"} text-white`}
>
{header}
</th>
));
};
const renderCells = (
rowIdx: number,
row: DmStatusLawYearsType,
data: DmStatusLawYearsType[],
headers: TableHeaderType[]
) => {
const rowData = row as Record<string, string | number>;
const currentCol1 = String(rowData["COL1"] ?? "");
// 이전 값
const prevCol1 = rowIdx > 0 ? data[rowIdx - 1]?.COL1 : null;
// 현재 그룹의 rowspan 계산
const getRowSpan = () => {
let count = 0;
for (let i = rowIdx; i < data.length; i++) {
if (data[i]?.COL1 === currentCol1) count++;
else break;
}
return count;
};
return headers.map((header, index) => {
const value = rowData[header.id];
// COL1 처리 (rowspan 핵심)
if (header.id === "COL1") {
// 이전과 같으면 렌더링 안함
if (currentCol1 === prevCol1) return null;
return (
<td
key={`${rowIdx}-${header.id}`}
rowSpan={getRowSpan()}
className={`${tableStyles.td} !font-bold !text-neutral-900`}
>
{value}
</td>
);
} else if (header.id === "COL2") {
return (
<td
key={`${rowIdx}-${header.id}`}
className={`${tableStyles.td} !font-bold !text-neutral-900`}
dangerouslySetInnerHTML={{ __html: Col2Name[value as string] ?? "" }}
/>
);
}
return (
<td
key={`${rowIdx}-${header.id}`}
className={`${tableStyles.td} ${[1, 3, 5].includes(index) ? "bg-[#EAF5F5]" : ""}`}
>
{String(rowData["COL2"]).indexOf("CNT") > -1
? Number(value).toLocaleString("ko-KR")
: formatUsage(value as string | number, 10000, 1) }
</td>
);
});
};
const renderBuildingUsageCells = (
row: DmStatusBildTpYearsType|DmStatusUsgYearsType,
headers: TableHeaderType[]
) => {
const rowData = row as Record<string, string | number>;
const firstHeaderId = headers[0]?.id;
const rowKey = firstHeaderId ? String(rowData[firstHeaderId] ?? "") : "";
return headers.map((header, index) => {
const value = rowData[header.id];
return (
<td
key={`${rowKey}-${header.id}`}
className={`${tableStyles.td} ${index === 0 ? "!font-bold !text-neutral-900" : ""} ${[1, 3, 5].includes(index) ? "bg-[#EAF5F5]" : ""}`}
>
{index === 0 ? value : formatUsage(value as string | number, 10000, 1)}
</td>
);
});
};
const title = "중수도(현황)";
return (
<div className="bg-white">
{/* 상단 타이틀 */}
<div className="inline-block">
<h2 className="relative inline-block px-2 text-[28px] font-extrabold tracking-tight leading-none text-slate-900">
<span className="relative z-10">{title}</span>
<span className="absolute left-0 bottom-[-4px] z-0 h-3 w-full bg-gradient-to-r from-sky-300 to-green-300" />
</h2>
</div>
<div className="mt-[70px] pb-[120px]">
{/* 1) 전체 중수도 설치 및 이용 현황 (공장 및 발전시설 제외) */}
<section>
{/* 인트로 영역 */}
<GreywaterIntroSummary />
<div id="status-greywater-overall" className="mt-10 scroll-mt-[120px]">
<SectionTitle>전체 중수도 설치 및 이용 현황 (공장 및 발전시설 제외)</SectionTitle>
<div className="mt-10">
<div className={tableStyles.container}>
<table className={tableStyles.table}>
<colgroup>
<col style={{ width: "130px" }} />
<col style={{ width: "160px" }} />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th
colSpan={2}
className={`${tableStyles.th} ${tableStyles.headerBg}`}
>
구분
</th>
{renderPartHeaders(rswtrYears, headerColors6)}
</tr>
</thead>
<tbody>
{rswtrByLawYears.map((row, idx, arr) => (
<tr key={idx}>
{renderCells(idx, row, arr, rswtrByLawYearsHeader)}
</tr>
))}
</tbody>
</table>
</div>
<SourceText />
</div>
</div>
</section>
<Hr className="my-11" />
{/* 2) 공장 및 발전시설 내 중수도 설치 현황 */}
<section
id="status-greywater-factory"
className="scroll-mt-[120px]"
>
<SectionTitle>공장 및 발전시설 내 중수도 설치 현황</SectionTitle>
<div className="mt-8">
<div className={tableStyles.container}>
<table className={tableStyles.table}>
<colgroup>
<col style={{ width: "130px" }} />
<col style={{ width: "160px" }} />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th
colSpan={2}
className={`${tableStyles.th} ${tableStyles.headerBg}`}
>
구분
</th>
{renderPartHeaders(rswtrYears, headerColors6)}
</tr>
</thead>
<tbody>
{rswtrByLawYearsFactory.map((row, idx, arr) => (
<tr key={idx}>
{renderCells(idx, row, arr, rswtrByLawYearsHeader)}
</tr>
))}
</tbody>
</table>
</div>
<SourceText />
</div>
</section>
<Hr className="my-11" />
{/* 3) 중수도 건축물별 이용량 현황 */}
<section
id="status-greywater-building"
className="scroll-mt-[120px]"
>
<SectionTitle>중수도 건축물별 이용량 현황</SectionTitle>
<div className="mt-8">
<div className={tableStyles.container}>
<table className={tableStyles.table}>
<colgroup>
<col style={{ width: "160px" }} />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th
rowSpan={2}
className={`${tableStyles.th} ${tableStyles.headerBg}`}
>
구분
</th>
<th
colSpan={6}
className={`${tableStyles.th} ${tableStyles.headerBg} py-2`}
>
이용량 (만m³/년)
</th>
</tr>
<tr>
{renderPartHeaders(rswtrYears, headerColors6)}
</tr>
</thead>
<tbody>
{rswtrByBildTpYears.map((row, idx) => (
<tr key={idx} className="bg-white">
{renderBuildingUsageCells(row, rswtrByBildTpYearsHeader)}
</tr>
))}
</tbody>
</table>
</div>
<SourceText />
</div>
</section>
<Hr className="my-11" />
{/* 4) 중수도 용도별 이용량 현황 */}
<section
id="status-greywater-usage"
className="scroll-mt-[120px]"
>
<SectionTitle>중수도 용도별 이용량 현황</SectionTitle>
<div className="mt-8">
<div className={tableStyles.container}>
<table className={tableStyles.table}>
<colgroup>
<col style={{ width: "160px" }} />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th
rowSpan={2}
className={`${tableStyles.th} ${tableStyles.headerBg}`}
>
구분
</th>
<th
colSpan={6}
className={`${tableStyles.th} ${tableStyles.headerBg} py-2`}
>
이용량 (만m³/년)
</th>
</tr>
<tr>
{renderPartHeaders(rswtrYears, headerColors6)}
</tr>
</thead>
<tbody>
{rswtrByUsgYears.map((row, idx) => (
<tr key={idx} className="bg-white">
{renderBuildingUsageCells(row, rswtrByUsgYearsHeader)}
</tr>
))}
</tbody>
</table>
</div>
<SourceText />
</div>
</section>
</div>
</div>
);
}