import React, { useState } from 'react';
import { ChevronDown, ChevronUp } from 'lucide-react';

interface ExpandableTextProps {
  text: string;
  maxLength?: number;
}

export const ExpandableText: React.FC<ExpandableTextProps> = ({
  text,
  maxLength = 300,
}) => {
  const [isExpanded, setIsExpanded] = useState(false);
  const shouldTruncate = text.length > maxLength;

  if (!shouldTruncate) {
    return <p className="text-body-sm text-[#d0d0d0] font-mono leading-7">{text}</p>;
  }

  return (
    <div className="relative">
      <p className={`text-body-sm text-[#d0d0d0] font-mono leading-7 ${
        !isExpanded ? 'line-clamp-3' : ''
      }`}>
        {text}
      </p>
      <button
        onClick={() => setIsExpanded(!isExpanded)}
        className="mt-2 text-xs font-mono text-[#58a6ff] hover:text-[#79b8ff] transition-colors flex items-center gap-1"
      >
        {isExpanded ? (
          <>
            <span>Show less</span>
            <ChevronUp className="h-3 w-3" />
          </>
        ) : (
          <>
            <span>Read more</span>
            <ChevronDown className="h-3 w-3" />
          </>
        )}
      </button>
    </div>
  );
};
