<?php
/**
 * Template Name: RentPress Neighborhood Single
 *
 * @package RentPress Templates
 */
add_action('wp_enqueue_scripts', 'rentpress_term_style');
function rentpress_term_style()
{
  wp_enqueue_style('city-archive', RENTPRESS_PLUGIN_PUBLIC_TEMPLATES_DIR . 'template-city-archive-styles.css');
}

get_header();

$options = get_option('rentpress_options');
$city_image = $options['rentpress_default_city_image_section'];
$accentColor = $options['rentpress_accent_color_section_input'];
$hoodID = get_the_id();
$hoodMeta = get_post_meta($hoodID);
$hoodName = get_the_title();
$hoodRomance = get_post_meta($hoodID, 'rentpress_custom_field_neighborhood_romance_copy')[0];
$hoodImage = !empty(get_the_post_thumbnail_url($hoodID)) ? get_the_post_thumbnail_url($hoodID, "full") : $city_image;
$hoodPostContent = !empty(get_the_content()) ? get_the_content() :'';

$args = array(
  'numberposts'		=> 3,
  'post_type'		=> 'rentpress_hood',
  'meta_key' => 'rentpress_custom_field_neighborhood_property_codes',
  'meta_value' => ' ',
  'meta_compare' => '!=',
  'exclude'		=> $hoodID
);
$hoods = get_posts($args);

?>

</header>

<main class="main-content" role="main">
    <div class="rentpress-page-hero">
        <header class="rentpress-page-hero-full">
            <h1 class="rentpress-inherited-font-family rentpress-page-title rentpress-neighborhood-title">
                <?php echo 'Explore <br />'. esc_html($hoodName); ?></h1>
            <img src="<?php echo esc_url($hoodImage); ?>"
                class="lazyload rentpress-neighborhood-banner rentpress-template-banner"
                alt="<?php echo esc_attr($hoodName); ?> banner">
        </header>
    </div>

    <section class="clearfix rentpress-term-short-description rentpress-neighborhood-short-description">
        <div class="container">
            <h2 class="rentpress-inherited-font-family"
                style="font-size:3em; display:block; margin:auto; padding:15px; text-align:center; color:<?php echo esc_attr($accentColor);?> ">
                <?php echo esc_attr($hoodName); ?></h2>
            <p class="rentpress-inherited-font-family"
                style="margin: auto;	font-size: 1.1em;	max-width: 100ch;	padding-top: 20px; padding-bottom: 20px; max-width:800px;">
                <?php echo wp_kses_post($hoodRomance); ?>
            </p>
        </div>
    </section>

    <section class="clearfix rentpress-term-properties rentpress-neighborhood-properties">
        <?php echo do_shortcode('[rentpress_property_search neighborhood="'. $hoodID .'" HIDEFILTERS=true][/rentpress_property_search]'); ?>
    </section>

    <section class="clearfix rentpress-extended-term-description rentpress-extended-neighborhood-description">
        <div class="container">
            <?php echo wp_kses_post($hoodPostContent); ?>
        </div>
    </section>

    <?php if (isset($hoods[1])) : ?>
    <section>
        <h3>
            <p style="text-align:center">Explore Other Options</p>
        </h3>
        <div class="city-term-grid neighborhood-grid-explore">
            <?php foreach ($hoods as $hood) :
        $image = !empty(get_the_post_thumbnail($hood->ID)) ? get_the_post_thumbnail_url($hood->ID, 'large') : $city_image;
      ?>

            <div class="is-rp-city is-rp-neighborhood flex-grid-thirds">
                <a href="<?php echo esc_url(get_permalink($hood->ID)); ?>">
                    <figure class="rp-city-figure rp-neighborhood-figure">
                        <img class="rp-city-image rp-neighborhood-image" src="<?php echo esc_url($image); ?>"
                            alt="<?php echo wp_kses_post(get_the_title($hood->ID)); ?>">
                    </figure>
                    <section class="rp-city-details rp-neighborhood-details">
                        <div class="rp-city-top rp-neighborhood-top">
                            <h2 class="rp-city-name rp-city-name rp-neighborhood-name"
                                style="font-weight: bold; color: <?php echo esc_attr($accentColor); ?> ;">
                                <?php echo wp_kses_post(get_the_title($hood->ID)); ?></h2>
                        </div>
                    </section>
                </a>
            </div>

            <?php endforeach ; ?>
        </div>
    </section>
    <?php endif; ?>

</main>

<?php get_footer(); ?>