<?php

class Page_handler extends MY_FrontendController
{

    public function __construct()
    {
        parent::__construct();


        hooks()->do_action('after_clients_area_init', $this);
    }

    public function index($main, $submenu = '')
    {

        //load about us content
        $default['main_color'] = '#084c94';
        $this->load->model('Landingmain_Model', 'landingmain');
        $landingmain = $this->landingmain->search_by_uri($main);

        if (count($landingmain) == 0) {
            redirect('header: ' . base_url('page_not_found'));

            exit;
        }
        $this->main_id = $landingmain['id'];
      /*  $this->breadcrumb[$landingmain['uri']] = [
            'name' => $landingmain['title'],
            'url' => base_url($landingmain['uri']),
        ];*/
        $breadcrumb['main'] = [
            'name'=>$landingmain['title'],
            'url'=> base_url($landingmain['uri']),
        ];
        $submenu_id = 0;
        if ($submenu !== '') {
            $this->load->model('Landingsubmenu_Model', 'landingsubmenu');
            $submenu = $this->landingsubmenu->search_by_uri($landingmain['id'], $submenu);
            if (count($submenu) == 0) {
                redirect('header: ' . base_url('page_not_found'));

                exit;
            }
            $submenu_id = $submenu['id'];
            $this->breadcrumb[$submenu['uri']] = [
                'name' => $submenu['title'],
                'url' => base_url($submenu['uri']),
            ];
            $breadcrumb['sub'] = [
                'name' => $submenu['title'],
                'url' => base_url($submenu['uri'])
            ];
        }
        $this->submenu_id = $submenu_id;
        $this->load->model('Page_settings_model', 'page_settings');
        $settings = $this->page_settings->get_page_settings($landingmain['id'], $submenu_id);
        $this->page_color = $default['main_color'];
        if (!empty($settings)) {
            $this->use_navigation = $settings['use_navigation'];
            $this->use_banner = $settings['use_banner'];
            $this->use_sidebar = $settings['use_sidebar'];
            $this->use_breadcrumb = $settings['use_breadcrumb'];
            $this->use_footer = $settings['use_footer'];
            $this->banner_desktop = $settings['banner_desktop'];
            $this->banner_mobile = $settings['banner_mobile'];
            $this->background_image = $settings['background_image'];
            if (trim($settings['page_color']) !== "") {
                $this->page_color = $settings['page_color'];
            }
        }
        $this->load->model('Page_objects_model', 'page_objects');

        if ($main != "about_us" && $main != "staff" && $main != "promote" && $main != "cases" && $main != "app_recommand" && $main != "contact_us") {
            $required_css = false;
            $css_file = '';
        } else {
            $required_css = true;
            $css_file = 'public/static/front/css/' . $main . '.css';
        }



        $data = [
            'page' => 'page_handler',
            'objects' => $this->page_objects->load_objects($this->main_id, $this->submenu_id),
            'required_css' => $required_css,
            'css_file' => $css_file,
            'nav_active' => $main,
            'use_banner' => true,
            'use_breadcrumb' => true
        ];
        $data = array_merge($data,$breadcrumb);
       

        //  $this->data($data);
        $this->view('front/page_handler', $data);
        //$this->layout();
    }
}
