import dayjs from "dayjs";
import { createColumnHelper } from "@tanstack/react-table";
import { type Link } from "@/entities/link";
import QuickStartButton from "../ui/QuickStartButton";
const columnHelper = createColumnHelper();
const convertMinutesToPeriod = (minutes: number): string => {
if (!minutes) return '';
const year = Math.floor(minutes / (525600)); // 365일 * 24시간 * 60분
minutes = minutes % 525600;
const month = Math.floor(minutes / (43200)); // 30일 * 24시간 * 60분
minutes = minutes % 43200;
const day = Math.floor(minutes / 1440); // 24시간 * 60분
minutes = minutes % 1440;
const hour = Math.floor(minutes / 60);
const minute = minutes % 60;
const parts = [];
if (year > 0) parts.push(`${year}년`);
if (month > 0) parts.push(`${month}개월`);
if (day > 0) parts.push(`${day}일`);
if (hour > 0) parts.push(`${hour}시간`);
if (minute > 0) parts.push(`${minute}분`);
return parts.join(' ');
};
const columns = [
columnHelper.accessor((_, index) => index + 1, {
id: 'no',
header: 'NO',
}),
columnHelper.accessor('link_sn', {
id: 'link_sn',
header: '연계일련번호',
}),
columnHelper.accessor('link_nm', {
id: 'link_nm',
header: '연계 명',
}),
columnHelper.accessor('link_url', {
id: 'link_url',
header: '연계 URL',
cell: (info) => (info.getValue() ? info.getValue() : '-'),
}),
columnHelper.accessor('link_srvr_ip', {
id: 'link_srvr_ip',
header: '연계서버 IP',
cell: (info) => (info.getValue() ? info.getValue() : '-'),
}),
columnHelper.accessor('link_cycle_mi', {
id: 'link_cycle_mi',
header: '연계 주기',
cell: (info) => convertMinutesToPeriod(Number(info.getValue())),
}),
columnHelper.accessor('srvc_usg', {
id: 'srvc_usg',
header: '서비스용도',
cell: (info) => (info.getValue() ? info.getValue() : '-'),
}),
columnHelper.display({
id: 'last_link_rslt_cd',
header: '연계상태',
cell: (info) => {
const resultCd = info.row.original.last_link_rslt_cd;
return {resultCd === 'SUCC' ? '성공' : (resultCd === 'FAIL' ? '실패' : (resultCd === 'RUNN' ? '진행중' : '대기'))}
},
}),
columnHelper.accessor('last_link_excn_dt', {
id: 'last_link_excn_dt',
header: '최종연계일',
cell: (info) => (info.getValue() ? dayjs(info.getValue()).format('YYYY-MM-DD HH:mm') : '-'),
}),
columnHelper.display({
id: 'quick_start_btn',
header: '즉시 실행',
cell: (info) => {
return
}
})
];
export { columns };