<?php 

namespace App\Services\Views;

use Request;
use App\Models\Lang;

class LangService
{
    //获取语言版本
    public function lists()
    {
        static $data = null;

        $data = $data ?? Lang::where('buy', 1)->whereIn('slug', [config('managerLang'), config('setting.lang')])->where('enabled', 1)->oldest('orders')->get();

        return $data ?? '';
    }

    //获取翻译语言版本
    public function translates()
    {
        static $data = null;

        $data = $data ?? Lang::where('buy', 1)->where('enabled', 1)->where('slug', '<>', config('setting.lang'))->oldest('orders')->get();

        return $data ?? '';
    }


    //调取当前语言版本
    public function show()
    {
        static $data = null;

        $data = $data ?? Lang::where('buy', 1)->where('enabled', 1)->flag()->oldest('orders')->get();
        $defaultLang = config('setting.lang');

        foreach ($data as &$value) {
            $domain = $value->domain ?: ($value->slug == $defaultLang ? secondaryDomain() : secondaryDomain($value->slug));
        	$value->url = Request::getScheme().'://'.$domain.Request::getRequestUri();
        }

        return $data ?? '';
    }

}