2025-01-13 21:36:52 +01:00
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
2024-11-02 11:53:56 +00:00
2024-11-02 12:52:12 +01:00
'use client'
import React , { useState } from "react"
import { TableArrangement } from '@/app/lib/definitions' ;
import { classNames } from "../components/button" ;
2024-11-10 20:52:48 +01:00
import TableOfContents from "../components/table-of-contents" ;
2024-11-17 16:45:42 +01:00
import { loadTableSimulations } from "@/app/api/tableSimulations" ;
2025-01-26 13:05:32 +01:00
import { ArchiveBoxXMarkIcon , CheckBadgeIcon } from "@heroicons/react/24/outline" ;
import { Tooltip } from "primereact/tooltip" ;
2025-01-26 13:09:31 +01:00
import clsx from "clsx" ;
2024-11-02 12:52:12 +01:00
2025-01-26 13:05:32 +01:00
export default function ArrangementsTable ( { onArrangementSelected } : { onArrangementSelected : ( arrangementId : string ) = > void } ) {
const [ arrangements , setArrangements ] = useState < Array < TableArrangement > > ( [ ] ) ;
const [ arrangementsLoaded , setArrangementsLoaded ] = useState ( false ) ;
function refreshSimulations() {
loadTableSimulations ( ( arrangements ) = > {
setArrangements ( arrangements ) ;
setArrangementsLoaded ( true ) ;
} ) ;
}
function arrangementClicked ( e : React.MouseEvent < HTMLElement > ) {
onArrangementSelected ( e . currentTarget . getAttribute ( 'data-arrangement-id' ) || '' ) ;
}
! arrangementsLoaded && refreshSimulations ( ) ;
return (
< TableOfContents
headers = { [ 'Name' , 'Discomfort' , 'Actions' , 'Status' ] }
caption = 'Simulations'
elements = { arrangements }
rowRender = { ( arrangement ) = > (
2025-01-26 13:09:31 +01:00
< tr key = { arrangement . id } className = { clsx ( "bg-white border-b odd:bg-white even:bg-gray-50" , {
"bg-white odd:bg-white even:bg-gray-50" : arrangement . valid ,
"bg-red-50 odd:bg-red-50 even:bg-red-100" : ! arrangement . valid
} ) } >
2025-01-26 13:06:29 +01:00
< th scope = "row" className = "px-6 py-4 font-medium text-gray-900 whitespace-nowrap" >
2025-01-26 13:05:32 +01:00
{ arrangement . name }
< / th >
< td className = "px-6 py-4" >
{ arrangement . discomfort }
< / td >
< td >
< button data-arrangement-id = { arrangement . id } onClick = { arrangementClicked } className = { classNames ( 'primary' ) } > Load < / button >
< / td >
< td >
< Tooltip target = ".tooltip-status" / >
{
arrangement . valid ?
< CheckBadgeIcon className = 'size-6 tooltip-status' data-pr-position = "right" data-pr-tooltip = "Simulation is valid" / > :
< ArchiveBoxXMarkIcon className = 'size-6 tooltip-status' data-pr-position = "right" data-pr-tooltip = "Simulation is expired due to attendance or affinity changes" / >
}
< / td >
< / tr >
) }
/ >
) ;
2024-11-02 12:52:12 +01:00
}