<?php

class Page_handler extends 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('at-admin/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']),
        ];
        $submenu_id = 0;
        if ($submenu !== '') {
            $this->load->model('at-admin/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']),
            ];
        }
        $this->submenu_id = $submenu_id;
        $this->load->model('at-admin/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('at-admin/Page_objects_model', 'page_objects');
        $data = [
            'page' => 'page_handler',
            'objects' => $this->page_objects->load_objects($this->main_id, $this->submenu_id),
        ];
           
        if($this->submenu_id == "8"){
        $data["extra_css"] = "/assets/themes/artech/front/css/service1.css";
        }
        $this->data($data);
        $this->view('page_handler');
        $this->layout();
    }

}
