'use client';
import { PollProps } from '../../types/types';
import PollBlock from './poll-block';
import { api } from '@/lib/trpc/client';

export default function PollWidget({ props }: { props: PollProps }) {
  if (!props) {
    return null;
  }
  const { pollId } = props;

  const { data: poll } = api.poll.get.useQuery({
    with: ['questions'],
    id: pollId
  });

  if (!poll) {
    return null;
  }

  return (
    <div className='poll my-6 grid'>
      <PollBlock poll={poll} />
    </div>
  );
}
