import { useBlocksQuery } from '../../../src/gql'
import { FunctionComponent } from 'react'
import { TBlock } from '../../../src/training/types'
import { AdminList } from '../../../src/app'
import theme from '../../../src/styles/theme'

const AdminBlock: FunctionComponent<{ item: TBlock; className?: string }> = ({
  item,
  className,
}) => {
  return (
    <div className={className}>
      <div className='admin-training-title'>{item.title}</div>{' '}
      <div className='admin-training-description'>{item.description}</div>
      <div className='admin-training-info'>{item.format.name}</div>
      <style jsx>{`
        .${className} {
          display: flex;
        }
        .admin-training-title {
          width: 15%;
        }
        .admin-training-description {
          width: 65%;
        }
        .admin-training-info {
          width: 20%;
          text-align: right;
        }
        button {
          margin: 0 0.4em;
          padding: 0;
          color: ${theme.colors.buttonBackground};
          background-color: transparent;
        }
      `}</style>
    </div>
  )
}

const AdminBlocks = () => {
  const props = {
    name: 'Blocks',
    adminMenu: '/admin/block',
    get: useBlocksQuery(),
    dataKey: 'blocks',
    Component: AdminBlock,
  }
  return <AdminList {...props} />
}

export default AdminBlocks
