import { Component, input, inject } from '@angular/core'
import { DashboardTable } from '../../types'
import { DashboardStore } from '../../dashboard.store'
import { TABLE_CONSTANTS } from '../../../../core'
import { TableResponse } from '@api-client/angular'
import { isLateReservation } from '../../utils'
import { NgStyle, NgClass, DatePipe } from '@angular/common'
import { SettingsStore } from '../../../../+state'
import { LucideUser } from '@lucide/angular'

@Component({
	selector: 'kadi-room-plan-table',
	templateUrl: './room-plan-table.component.html',
	styleUrl: './room-plan-table.component.scss',
	imports: [NgStyle, NgClass, DatePipe, LucideUser],
})
export class RoomPlanTableComponent {
	private readonly _store = inject(DashboardStore)
	readonly _settingsStore = inject(SettingsStore)

	table = input.required<DashboardTable>()

	POINT_LENGTH = TABLE_CONSTANTS.TABLE_POINT_LENGTH
	TableShape = TableResponse.ShapeEnum

	selectTable(table: DashboardTable): void {
		this._store.selectTable(table)
	}

	getTableClasses(table: DashboardTable) {
		return {
			selected: this._store.state().selectedTable?.tableRef.id === table.tableRef.id,
			'rounded-xl': table.tableRef.shape === TableResponse.ShapeEnum.rectangle,
			'rounded-full': table.tableRef.shape === TableResponse.ShapeEnum.round,
			late: table.reservation ? isLateReservation(table.reservation) : false,
		}
	}
}
