import React, { Component } from 'react'
import Link from 'gatsby-link'

import PageIntro from '../components/PageIntro'
import Card from '../components/Card'

import PageTransition from 'gatsby-plugin-page-transitions'

class Blog extends Component {
  render() {
    const data = this.props.data
    return (
      <PageTransition>
        <div className="container mx-auto p-4 w-full md:flex md:flex-wrap items-stretch w-full">
          {data.allWordpressPost.edges.map(({ node }) => (
            <div key={node.id} className="mt-4 md:w-1/2 p-2">
              <Link
                to={`blog/${node.slug}`}
                className="pointer no-underline saburly-transition hover:opacity-50"
              >
                <Card
                  title={node.title}
                  date={node.date}
                  excerpt={node.excerpt}
                  image={
                    node.featured_media
                      ? node.featured_media.localFile.childImageSharp
                          .resolutions
                      : undefined
                  }
                />
              </Link>
            </div>
          ))}
        </div>
      </PageTransition>
    )
  }
}

export const query = graphql`
  query blogQuery {
    allWordpressPost {
      edges {
        node {
          id
          title
          excerpt
          status
          slug
          date(formatString: "MMMM DD, YYYY")
          featured_media {
            localFile {
              childImageSharp {
                resolutions(width: 600, height: 300) {
                  src
                  width
                  height
                }
              }
            }
          }
        }
      }
    }
  }
`

export default Blog
