import preact, { h, Component } from 'preact'; // eslint-disable-line no-unused-vars

import Markup from 'preact-markup';

import { getContent } from '../helpers/helpers';

export default class Home extends Component {

    constructor() {
        super();
    }

    render(props) {
        const page = props.page || null,
              posts = Array.isArray(props.posts) ? props.posts : [],
              categoryID = (page) ? page.categoryID : -1,
              sections = posts.filter((post) => { return (post.categoryID === categoryID && post.type === '') }).sort((a, b) => { return (a.order > b.order ? 1 : -1) }) || [];

        return (
            <div>
                {sections.map(section => {
                    return (
                        <article class="o-section">
                            <Markup markup={getContent(section.content)} />
                        </article>
                    )
                })}
            </div>
        );
    }
}
