<?php

use system\entity\filter\baseFilter;

class ControllerMarketplaceShopee extends Controller
{

    public function index()
    {
        $this->language->load('module/shopee');
        $this->data['breadcrumbs'] = array();

        $this->data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home'),
            'separator' => false
        );

        $this->data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_title'),
            'href' => $this->url->link('marketplace/shopee'),
            'separator' => $this->language->get('text_separator')
        );

        $this->breadcrumbs->setbreadcumbs($this->data['breadcrumbs']);

        $this->document->setTitle($this->language->get('text_title'));

        $this->data['heading_title'] = $this->language->get('text_title');
        $this->data['text_intro'] = $this->language->get('text_intro');
        $this->data['text_auth'] = $this->language->get('text_auth');
        $this->data['text_auth_done'] = $this->language->get('text_auth_done');
        $this->data['button_continue'] = $this->language->get('button_continue');
        $this->data['continue'] = $this->url->link('common/home');

        $this->data['error'] = '';
        if (isset($this->request->get['error'])) {
            $this->data['error'] = 'Error: ' . $this->request->get['error'] . (($this->request->get['error_description']) ? ' - ' . $this->request->get['error_description'] : '');
        }

        if (isset($this->request->get['code']) && isset($this->request->get['shop_id'])) {
            $this->shopee->getAccessToken($this->request->get['code'], $this->request->get['shop_id']);
        }

        $this->data['auth_done'] = '';
        if ($this->shopee->validateAccess()) {
            $this->data['auth_done'] = '1';
            $this->data['text_auth'] = $this->language->get('text_reauth');
        }

        $this->data['login_url'] = $this->shopee->getLoginUrl();


        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/marketplace/shopee_auth.twig')) {
            $this->template = $this->config->get('config_template') . '/template/marketplace/shopee_auth.twig';
        } else {
            $this->template = 'default/template/marketplace/shopee_auth.twig';
        }

        $this->children = array(
            'common/breadcrumbs',
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );

        $this->response->setOutput($this->render());
    }

}
