<?php
$array = Pakrco_Project::getInstance()->get_all_meta_field_value();
?>
<div class="search-project dark-mode">
    <div class="container">
        <form action="<?php echo get_post_type_archive_link('pakrco_project'); ?>" method="get">
            <div class="project-group">
                <?php if (!project_get_option('hide_status')): ?>
                    <div class="project-inner">
                        <label><?php echo esc_html__('Project Status', 'pakrco'); ?></label>
                        <select name="project_status">
                            <option value=""><?php echo esc_html__('Any', 'pakrco'); ?></option>
                            <?php
                            foreach ($array['project_status'] as $item) {
                                ?>
                                <option value="<?php echo esc_attr($item); ?>" <?php echo esc_attr(isset($_GET['project_status']) && $item == $_GET['project_status'] ? 'selected' : ''); ?>><?php echo esc_html($item); ?></option>
                                <?php
                            }

                            ?>
                        </select>
                    </div>
                <?php endif; ?>
                <?php if (!project_get_option('hide_type')): ?>
                    <div class="project-inner">
                        <label><?php echo esc_html__('Project Type', 'pakrco'); ?></label>
                        <select name="project_type">
                            <option value=""><?php echo esc_html__('Any', 'pakrco'); ?></option>
                            <?php
                            foreach ($array['project_type'] as $item) {
                                ?>
                                <option value="<?php echo esc_attr($item); ?>" <?php echo esc_attr(isset($_GET['project_type']) && $item == $_GET['project_type'] ? 'selected' : ''); ?>><?php echo esc_html($item); ?></option>
                                <?php
                            }
                            ?>
                        </select>
                    </div>
                <?php endif; ?>
                <?php if (!project_get_option('hide_location')): ?>
                    <div class="project-inner">
                        <label><?php echo esc_html__('Location', 'pakrco'); ?></label>
                        <select name="project_location">
                            <option value=""><?php echo esc_html__('Any', 'pakrco'); ?></option>
                            <?php
                            foreach ($array['project_location'] as $item) {
                                ?>
                                <option value="<?php echo esc_attr($item); ?>" <?php echo esc_attr(isset($_GET['project_location']) && $item == $_GET['project_location'] ? 'selected' : ''); ?>><?php echo esc_html($item); ?></option>
                                <?php
                            }
                            ?>
                        </select>
                    </div>
                <?php endif; ?>
                <?php
                if (!project_get_option('hide_budget')): ?>
                    <div class="project-inner">
                        <label><?php echo esc_html__('Budget', 'pakrco'); ?></label>
                        <select name="project_budget">
                            <option value=""><?php echo esc_html__('Any', 'pakrco'); ?></option>
                            <?php
                            $symbol = !empty(get_option('project_archive')['currency_symbol']) ? get_option('project_archive')['currency_symbol'] : '$';
                            $range = project_get_option('range');
                            if ($range) {
                                foreach ($range as $k => $number) {
                                    $min = $number['min'];
                                    $max = $number['max'];
                                    if (!$min && !$max) {
                                        continue;
                                    }
                                    $text_min = $min ? $symbol . $min : '';
                                    $text_min = $max ? $text_min : '> ' . $text_min;
                                    $text_max = $max ? $symbol . $max : '';
                                    $text_max = $min ? $text_max : '< ' . $text_max;

                                    $text_min_max = $text_min && $text_max ? $text_min . ' - ' : $text_min;
                                    $text_min_max = $text_max ? $text_min_max . $text_max : $text_min_max;

                                    ?>
                                    <option value="<?php echo esc_attr($min . '|' . $max); ?>" <?php echo isset($_GET['project_budget']) && ($min . '|' . $max) == $_GET['project_budget'] ? 'selected' : ''; ?>><?php echo esc_html($text_min_max); ?></option>
                                    <?php
                                }
                            } else {
                                foreach ($arr = range(0, floatval($array['project_price_max']), floatval($array['project_price_max']) / 10) as $k => $number) {
                                    if ($k > 0) {
                                        ?>
                                        <option value="<?php echo esc_attr($arr[$k - 1] . '|' . $number); ?>" <?php echo isset($_GET['project_budget']) && ($arr[$k - 1] . '|' . $number) == $_GET['project_budget'] ? 'selected' : ''; ?>><?php echo esc_html($symbol . $arr[$k - 1] . ' - ' . $symbol . $number); ?></option>
                                        <?php
                                    }
                                }
                            }

                            ?>
                        </select>
                    </div>
                <?php endif; ?>
                <div class="project-inner align-self-end">
                    <button type="submit" class="btn btn-primary btn-block">
                        <?php echo esc_html__('Search', 'pakrco'); ?>
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<main class="site-main">
    <div class="container clearfix">
        <?php if (apply_filters('pakrco_page_title', true)) : ?>
            <header class="page-header text-center">
                <?php
                the_archive_title('<h1 class="entry-title">', '</h1>');
                the_archive_description('<p class="archive-description">', '</p>');
                ?>
            </header>
        <?php endif; ?>
        <div id="primary" class="content-area">

            <?php
            $column = pakrco_get_theme_option('project_archive_column', 3);
            $style = pakrco_get_theme_option('project_archive_style', 'default');
            echo '<div class="row isotope-grid elementor-project-style-' . esc_attr($style) . '" data-elementor-columns="' . esc_attr($column) . '" data-elementor-columns-tablet="2" data-elementor-columns-mobile="1">';

            while (have_posts()) : the_post();
                ?>
                <div class="column-item project-entries">
                    <?php
                    get_template_part('template-parts/project/content');
                    ?>
                </div>
            <?php
            endwhile;
            echo '</div>';
            $args = array(
                'type'      => 'list',
                'next_text' => '<i class="pakrco-icon-angle-right"></i>',
                'prev_text' => '<i class="pakrco-icon-angle-left"></i>',
            );

            the_posts_pagination($args);
            ?>
        </div>
    </div>
</main>
