<?php
/**
 * #8037 "Show my posts" checkbox row (+ the hidden input that holds show_mine/hide_mine).
 *
 * Rendered either embedded at the bottom of the stream-type "Filter" dropdown (with a leading
 * separator) or as the sole content of the standalone "Filter" dropdown. The persisted value and
 * endpoint param are unchanged (stream_filter_show_my_posts); the checkbox just maps
 * checked => show_mine, unchecked => hide_mine (so it is ticked by default). Follows the rule:
 * renders nothing when the my-posts list is empty (e.g. guests).
 *
 * @param bool $separator  Render a horizontal separator before the checkbox (embedded case).
 */

$show_my_posts_list = apply_filters('peepso_show_my_posts_list', array());
if (!$show_my_posts_list || !is_array($show_my_posts_list) || !count($show_my_posts_list)) {
    return;
}

$user_stream_filters = PeepSoUser::get_stream_filters();
reset($show_my_posts_list);
$default = key($show_my_posts_list);
$show_my_posts = isset($user_stream_filters['show_my_posts']) ? $user_stream_filters['show_my_posts'] : $default;
if (!array_key_exists($show_my_posts, $show_my_posts_list)) {
    $show_my_posts = $default;
}

$separator = isset($separator) ? $separator : false;
?>
<input type="hidden" id="peepso_stream_filter_show_my_posts" value="<?php echo esc_attr($show_my_posts); ?>" />
<div class="pso-posts-filter__myposts" data-myposts>
    <?php if ($separator) { ?><div class="pso-posts-filter__separator"></div><?php } ?>
    <div class="pso-posts-filter__options">
        <a class="pso-posts-filter__option pso-posts-filter__option--checkbox" role="menuitemcheckbox">
            <div class="pso-posts-filter-option__control">
                <input type="checkbox" id="peepso_stream_filter_show_my_posts_cb" <?php if ('hide_mine' !== $show_my_posts) echo 'checked'; ?> />
            </div>
            <label class="pso-posts-filter-option__content" for="peepso_stream_filter_show_my_posts_cb">
                <span class="pso-posts-filter-option__name"><?php echo esc_attr__('Show my posts', 'peepso-core'); ?></span>
            </label>
        </a>
    </div>
</div>
