'use client';

import { twMerge } from 'tailwind-merge';

import CloseButton from '@/components/button/CloseButton';
import Comments from '@/components/comment/Comments';

interface HookCommentsPanelProps {
  hookId: string;
  numComments: number;
  className?: string;
  onClose?: () => void;
  deeplinkedCommentId?: string;
  isUserContentOwner?: boolean;
  allowComments?: boolean;
}

const HookCommentsPanel: React.FC<HookCommentsPanelProps> = ({
  hookId,
  numComments,
  className,
  onClose,
  deeplinkedCommentId,
  isUserContentOwner = false,
  allowComments = true,
}) => {
  return (
    <div
      className={twMerge(
        'flex h-full flex-col rounded-xl bg-background-secondary',
        className
      )}
    >
      <div className='flex shrink-0 items-center justify-between border-b border-border-primary p-4'>
        <h2 className='text-lg font-semibold text-foreground-primary'>
          Comments
        </h2>
        {onClose && (
          <CloseButton
            onClick={onClose}
            className='text-foreground-secondary hover:text-foreground-primary'
          />
        )}
      </div>
      <Comments
        entityId={hookId}
        entityType='hook'
        numComments={numComments}
        allowComments={allowComments}
        className='h-full overflow-y-auto py-4'
        style={
          {
            '--comment-input-bg': 'var(--color-background-tertiary)',
          } as React.CSSProperties
        }
        deeplinkedCommentId={deeplinkedCommentId}
        isUserContentOwner={isUserContentOwner}
      />
    </div>
  );
};

export default HookCommentsPanel;
