<?php
/**
 * The template for displaying all pages.
 *
 * @package Maskitto Light
 */
$maskitto_light;
get_header(); ?>

	<?php while ( have_posts() ) : the_post();
        $style1 = (string) NULL;
        $style2 = (string) NULL;
        $style3 = (string) NULL;

        $subtitle = get_post_meta( get_the_ID(), 'wpcf-subtitle', true );
        $titlebar = get_post_meta( get_the_ID(), 'wpcf-title-layout', true );
        $title_color = get_post_meta( get_the_ID(), 'wpcf-title-color', true );
        $background_color = get_post_meta( get_the_ID(), 'wpcf-background-color', true );
        $background_image = get_post_meta( get_the_ID(), 'wpcf-background-image', true );
        $padding = get_post_meta( get_the_ID(), 'wpcf-page-padding', true );
        $comments = get_post_meta( get_the_ID(), 'wpcf-comments', true );

        if( $padding == 'small' ) {
            $style1.= "padding: 35px 0;";
        } else if( $padding == 'large' ) {
            $style1.= "padding: 150px 0;";
        }

        if( $background_color ) {
            $style1.= "background-color: $background_color;";
        }

        if( $background_image ) {
            $style1.= "background-image: url($background_image);";
        }

        if( $title_color ) {
            $style2.= "color: $title_color;";
        }


		$content = get_the_content();
		$content = apply_filters('the_content', $content);

		preg_match('/div class="page-section"/s', $content, $matches);

		if( count($matches) > 0 ) {
			$style1.= "padding-bottom: 0px!important;";
		}
	?>

	<div class="page-single-page" style="<?php echo $style1; ?>">

		<?php if( $titlebar != 'none' ) { ?>
	        <div class="page-section" style="padding: 0px!important;">
	            <div class="container page-list">
	                <?php if( $titlebar == 'small' ) { ?>
	                    <h4 class="text-center" style="<?php echo $style2; ?>"><?php the_title(); ?><?php echo maskitto_light_admin_edit(get_the_ID()); ?></h4>
	                <?php } else if( $titlebar == 'large' ) { ?>
	                    <div class="section-title-large text-center">
	                        <div class="title" style="<?php echo $style2; ?>"><?php the_title(); ?><?php echo maskitto_light_admin_edit(get_the_ID()); ?></div>
	                    </div>
	                    <?php if( $page->post_content ) { ?>
	                        <div class="section-content-large post-inner" style="<?php echo $style2; ?>"><?php echo $page->post_content; ?></div>
	                    <?php } ?>
	                <?php } else { ?>
	                    <div class="section-title text-center">
	                        <h3 style="<?php echo $style2; ?>"><?php the_title(); ?><?php echo maskitto_light_admin_edit(get_the_ID()); ?></h3>
	                        <?php if( $subtitle ){ ?>
	                            <div class="subtitle"><p><?php echo $subtitle; ?></p></div>
	                        <?php } ?>
	                        <div class="section-title-line"></div>
	                    </div>
	                <?php } ?>
				</div>
			</div>
		<?php } ?>

		<?php get_template_part( 'content', 'page' ); ?>

		<?php if( $comments == 'on' ) { ?>
		<div class="page-section" style="padding-bottom: 10px!important; padding-top: 30px!important;">
			<div class="container page-list">
			<?php
				// If comments are open or we have at least one comment, load up the comment template
				if ( comments_open() || get_comments_number() ) :
					comments_template();
				endif;
			?>
			</div>
		</div>

		<?php } ?>

	</div>

	<?php endwhile; ?>

<?php //get_sidebar();
?>
<?php get_footer(); ?>
