<?php

    /* Preview Theme URLs */

    define('_PREVIEW_SUFFIX_', '_preview');
    define('_SP_', '/');
    define('DEFAULT_THEME_NAME', 'designer_theme');
    define('IMAGE_STORAGE', _PS_IMG_DIR_ . _SP_ . 'designer');
    define('IMG_PATH_TOKEN', '../img');

    function isPreviewTheme() {
        $result = Tools::getValue('theme_name', false);
        if ($result) return true;
        return false;
    }

    function getPreviewThemeName() {
        $themeName = Tools::getValue('theme_name', '');
        if (!empty($themeName)) 
            return $themeName . _PREVIEW_SUFFIX_;
        return ''; 
    }

    function getPreviewThemeUrl() {
        return _THEMES_DIR_ . getPreviewThemeName() . _SP_;
    }

    function getPreviewThemeDir() {
        return _PS_ROOT_DIR_ . _SP_ . 'themes' . _SP_ . getPreviewThemeName() . _SP_;
    }

    function getPreviewCssDir() {
        return getPreviewThemeUrl() .  'css' . _SP_;
    }

    function getPreviewImgDir() {
        return getPreviewThemeUrl() .  'img' . _SP_;
    }

    function getPreviewJsDir() {
        return getPreviewThemeUrl() .  'js' . _SP_;
    }

    function getThemeName() {
        return isPreviewTheme() ? getPreviewThemeName() : _THEME_NAME_;
    }

    function getThemeUrl() {
        return isPreviewTheme() ? getPreviewThemeUrl() : _THEME_DIR_;
    }

    function getThemeDir($themeName = '') {
        if (empty($themeName))
            return isPreviewTheme() ? getPreviewThemeDir() : _PS_THEME_DIR_;
            
        return _PS_ALL_THEMES_DIR_ . $themeName;
    }

    function getProjectPath($themeName) {
        return _PS_ALL_THEMES_DIR_ . $themeName . '/project/project.json';
    }
