<commit_before><?php

namespace App;

use LaravelLocalization;

trait NavigationTrait
{
    /**
     * resolve route & params for lang switcher.
     *
     * @param [type] $name [description]
     * @param [type] $code [description]
     *
     * @return [type] [description]
     */
    public function getUrl($name, $code)
    {
        $url = $this->routeLink($name, $code);

        if (!$url) {
            // page is hardcoded
            return LaravelLocalization::getLocalizedURL($code);
        }

        // if we have a saved params
        if (session()->has($name)) {
            $params = session()->get($name);

            return LaravelLocalization::getLocalizedURL(
                $code, url($this->getParams($url, $params))
            );
        }

        // no params
        return LaravelLocalization::getLocalizedURL(
            $code, url($this->rmvNonUsedParams($url))
        );
    }

    /**
     * resolve route & params for links.
     *
     * @param [type] $crntRouteName [description]
     * @param [type] $another       [description]
     * @param [type] $params        [description]
     *
     * @return [type] [description]
     */
    public function getRoute($crntRouteName, $another = null, $params = null)
    {
        $code = LaravelLocalization::getCurrentLocale();
        $url = $this->routeLink($crntRouteName, $code);

        if (is_array($another)) {
            foreach ($another as $k => $v) {
                if ($crntRouteName == $k) {
                    if (!session()->has($crntRouteName)) {
                        session([$crntRouteName => $v]);
                    }

                    return $this->checkForhideDefaultLocaleInURL($code, $url, $v);
                }
            }
        } else {
            if (($crntRouteName == $another) && $params) {
                // set a session item so we can redir with params
                // from the lang switcher
                if (!session()->has($crntRouteName)) {
                    session([$crntRouteName => $params]);
                }

                return $this->checkForhideDefaultLocaleInURL($code, $url, $params);
            }
        }

        return route($crntRouteName);
    }

    /**
     * render menu.
     *
     * @param [type] $pages   [description]
     * @param [type] $classes [description]
     * @param [type] $params  [description]
     * @param [type] $url     [description]
     *
     * @return [type] [description]
     */
    public function render($pages, $classes = null, $params = null, $url = null)
    {
        switch ($classes) {
            case 'config':
                $ul = config('simpleMenu.listClasses.ul');
                $li = config('simpleMenu.listClasses.li');
                $a = config('simpleMenu.listClasses.a');
                break;
            default:
                $ul = array_get($classes, 'ul');
                $li = array_get($classes, 'li');
                $a = array_get($classes, 'a');
                break;
        }

        return $this->getHtml($pages, $ul, $li, $a, $params, $url);
    }

    /**
     * to resolve 'hideDefaultLocaleInURL => true' problem.
     *
     * @param [type] $code   [description]
     * @param [type] $url    [description]
     * @param [type] $params [description]
     *
     * @return [type] [description]
     */
    protected function checkForhideDefaultLocaleInURL($code, $url, $params)
    {
        if (LaravelLocalization::hideDefaultLocaleInURL() &&
            LaravelLocalization::getCurrentLocale() == app('laravellocalization')->getDefaultLocale()) {
            return url($this->getParams($url, $params));
        }

        return LaravelLocalization::getLocalizedURL(
            $code, url($this->getParams($url, $params))
        );
    }

    /**
     * resolve route url.
     *
     * @param [type] $name [description]
     * @param [type] $code [description]
     *
     * @return [type] [description]
     */
    protected function routeLink($name, $code)
    {<commit_msg>update LaravelLocalization<commit_after><?php

namespace App;

use LaravelLocalization;

trait NavigationTrait
{
    /**
     * resolve route & params for lang switcher.
     *
     * @param [type] $name [description]
     * @param [type] $code [description]
     *
     * @return [type] [description]
     */
    public function getUrl($name, $code)
    {
        $url = $this->routeLink($name, $code);

        if (!$url) {
            // page is hardcoded
            return LaravelLocalization::getLocalizedURL($code);
        }

        // if we have a saved params
        if (session()->has($name)) {
            $params = session()->get($name);

            return LaravelLocalization::getLocalizedURL(
                $code, url($this->getParams($url, $params)), [], true
            );
        }

        // no params
        return LaravelLocalization::getLocalizedURL(
            $code, url($this->rmvNonUsedParams($url)), [], true
        );
    }

    /**
     * resolve route & params for links.
     *
     * @param [type] $crntRouteName [description]
     * @param [type] $another       [description]
     * @param [type] $params        [description]
     *
     * @return [type] [description]
     */
    public function getRoute($crntRouteName, $another = null, $params = null)
    {
        $code = LaravelLocalization::getCurrentLocale();
        $url = $this->routeLink($crntRouteName, $code);

        if (is_array($another)) {
            foreach ($another as $k => $v) {
                if ($crntRouteName == $k) {
                    if (!session()->has($crntRouteName)) {
                        session([$crntRouteName => $v]);
                    }

                    return $this->checkForhideDefaultLocaleInURL($code, $url, $v);
                }
            }
        } else {
            if (($crntRouteName == $another) && $params) {
                // set a session item so we can redir with params
                // from the lang switcher
                if (!session()->has($crntRouteName)) {
                    session([$crntRouteName => $params]);
                }

                return $this->checkForhideDefaultLocaleInURL($code, $url, $params);
            }
        }

        return route($crntRouteName);
    }

    /**
     * render menu.
     *
     * @param [type] $pages   [description]
     * @param [type] $classes [description]
     * @param [type] $params  [description]
     * @param [type] $url     [description]
     *
     * @return [type] [description]
     */
    public function render($pages, $classes = null, $params = null, $url = null)
    {
        switch ($classes) {
            case 'config':
                $ul = config('simpleMenu.listClasses.ul');
                $li = config('simpleMenu.listClasses.li');
                $a = config('simpleMenu.listClasses.a');
                break;
            default:
                $ul = array_get($classes, 'ul');
                $li = array_get($classes, 'li');
                $a = array_get($classes, 'a');
                break;
        }

        return $this->getHtml($pages, $ul, $li, $a, $params, $url);
    }

    /**
     * to resolve 'hideDefaultLocaleInURL => true' problem.
     *
     * @param [type] $code   [description]
     * @param [type] $url    [description]
     * @param [type] $params [description]
     *
     * @return [type] [description]
     */
    protected function checkForhideDefaultLocaleInURL($code, $url, $params)
    {
        if (LaravelLocalization::hideDefaultLocaleInURL() &&
            LaravelLocalization::getCurrentLocale() == app('laravellocalization')->getDefaultLocale()) {
            return url($this->getParams($url, $params));
        }

        return LaravelLocalization::getLocalizedURL(
            $code, url($this->getParams($url, $params)), [], true
        );
    }

    /**
     * resolve route url.
     *
     * @param [type] $name [description]
     * @param [type] $code [description]
     *
     * @return [type] [description]
     */
    protected function routeLink($name, $code)
    {
{'fraction_non_alphanumeric': 0.14428412874583796, 'fraction_numerical': 0.0, 'mean_word_length': 1.8179291174426686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5080665', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2278, 'n_words': 508}