/**
 *
 * Copyright (c) 2024 Analog Devices, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import type {PinStatus} from '../../../../types/pins';
import styles from './pin.module.scss';

type McuPinProps<T> = {
	readonly label?: T extends true ? never : string;
	readonly status?: T extends true ? never : PinStatus;
	readonly isFocused?: T extends true ? never : boolean;
	readonly onClick?: T extends true ? never : () => void;
	readonly isEmpty?: T;
};

function McuPin({
	label,
	status = 'unassigned',
	isEmpty,
	isFocused,
	onClick
}: McuPinProps<undefined> | McuPinProps<true>) {
	const baseStyles = `${styles.gridUnit} ${styles.basePin}`;
	const statusStyles = isEmpty
		? styles.empty
		: (styles[status] ?? '');
	const focusedStyles = isFocused ? styles.focused : '';

	return (
		<div
			data-test={`pin:${label}`}
			className={`${baseStyles} ${statusStyles} ${focusedStyles}`}
			onClick={onClick}
		>
			<span>{label}</span>
		</div>
	);
}

export default McuPin;
