import { useDrag } from 'react-dnd';
import React from 'react';

const ItemTypes = {
  TEACHER: 'teacher',
};

const TeacherItem = ({ teacher, isDraggable = true }) => {
  const [{ isDragging }, drag] = useDrag(
    () => ({
      type: ItemTypes.TEACHER,
      item: {
        id: teacher.id,
        name: `${teacher.last_name} ${teacher.first_name}`,
      },
      collect: (monitor) => ({
        isDragging: !!monitor.isDragging(),
      }),
      canDrag: () => isDraggable,
    }),
    [isDraggable]
  );

  return (
    <div
      ref={isDraggable ? drag : null}
      className={`inline-block px-4 py-2 rounded-full font-medium text-sm text-center transition-transform duration-200 ease-in-out ${
        isDragging ? 'opacity-50' : 'opacity-100'
      } ${
        isDraggable ? 'cursor-grabbing hover:shadow-md hover:scale-105' : ''
      } ${
        isDragging
          ? 'bg-gradient-to-r from-primary/10 to-primary/20 border border-primary/20'
          : isDraggable
            ? 'bg-gradient-to-r from-tertiary to-primary/30 border border-tertiary'
            : 'bg-gradient-to-r from-primary/20 to-primary/30 border border-primary/30'
      } text-white`}
    >
      {teacher.last_name} {teacher.first_name}
    </div>
  );
};

export default TeacherItem;
