<?php
/**
 * Template Name: Faq Page
 */

get_header();
$extraQueryParams = [];
$tIds = getFaaTaxonomyIds();
if ($tIds !== false) {
    if (count($tIds) == 0) {
        $terms = [];
    } else {
        $terms = get_terms( [
            'taxonomy' => 'fac_category_type',
            'hide_empty' => true,
            'orderby'    => 'term_order',
            'include' => $tIds
        ]);
    }
} else {
    $terms = get_terms( [
        'taxonomy' => 'fac_category_type',
        'hide_empty' => true,
        'orderby'    => 'term_order',
    ]);
}




?>
<div class="content no-pb">
    <div class="breadcrumbs">
        <div class="cont">
            <div class="inner-cont">
                <ol class="breadcrumb">
                    <li><a href="/">Home</a></li>
                    <li class="active">FAQ</li>
                </ol>
            </div>
        </div>
    </div>
    <div class="page-head">
        <div class="cont">
            <div class="inner-cont">
                <h1>Frequently Asked Questions</h1>
            </div>
        </div>
    </div>

    <div class="faq-list">
        <div class="cont">
            <div class="inner-cont">
                <div class="faq-search">
                    <div class="search-input with-btn">
                        <form method="POST" class="si-flex" id="search-form" action="/faq-page">
                            <div class="left">
                                <span class="icon-search hide-sm"></span>
                                <input 
                                    type="text" 
                                    class="form-control" 
                                    placeholder="What do you need help with?" 
                                    name="search_text" 
                                    value="<?= enableSearchQuery()?$_POST['search_text']:''?>"
                                    >
                                <button type="reset" class="button clear link">
                                    <span class="icon-close"></span>
                                </button>
                            </div>
                            <div class="right">
                                <button type="submit" class="button action start-search">
                                    <span class="icon-search show-sm"></span>
                                    <span class="btn-text hide-sm">Search</span>													
                                </button>
                            </div>
                        </form>										
                    </div>
                </div>
                <?php foreach ($terms as $term):?>
                <div class="front-accordion">
                    <div class="fa-head">
                        <button class="button borderless collapse-toggle" data-bs-target="#fc-<?= $term->term_id ?>" data-bs-toggle="collapse" role="button" aria-expanded="true">
                            <?= $term->name?>
                            <span class="icon-down"></span>
                        </button>
                    </div>
                    <div class="fa-body collapse show" id="fc-<?= $term->term_id ?>">
                        <div class="fa-cont">
                            <?php
                            $posts = getFaqPosts(['post_type' => 'fac_category_answer',
                                'numberposts' => -1,
                                'suppress_filters' => false,
                                'tax_query' => [
                                    [
                                        'taxonomy' => 'fac_category_type',
                                        'field' => 'id',
                                        'terms' => $term->term_id,
                                        'include_children' => false
                                    ]
                                ]
                            ]);
                            foreach ($posts as $post) {

                                echo '
                                    <div class="faq-question">
                                        <a href="'.get_permalink($post).'">'.$post->post_title.'</a>
                                    </div>
                                ';
                            }

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

    <div class="mp-feature with-bg bot-form">
        <div class="cont">
            <div class="inner-cont">
                <div class="flex">
                    <div class="col">
                        <div class="mp-interested centered">
                            <h4 class="text-header">Interested? Get to know more</h4>
                            <div class="buttons">
                                <a href="/contact-us" class="button action big">Request a demo</a>
                                <a href="<?= get_lawcarta_url()?>/user/registration" class="button secondary big">Sign up for free</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
get_footer();

