<?php

namespace App\Distributor\Repositories;

use App\Admin\Repositories\DistAppearanceTemplateLog;
use App\Models\DistAppearanceTemplate as Model;
use App\Models\SiteAppearanceTemplate;
use Dcat\Admin\Repositories\EloquentRepository;
use Illuminate\Support\Carbon;

class DistAppearanceTemplate extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    /*
     * 同步模版到正式表上
     */
    public static function syncAppearanceTemplates($appearanceId,$distId)
    {
        $model = new Model();
        return $model->syncAppearanceTemplates($appearanceId,$distId);
    }

    /*
     * 得到独立页的模版数组
     */
    public static function getLandingPageTemplateOptions() {
    {
        $distInfo = DistAdminDistributor::getInfo();
        $distId = $distInfo->id;
        $appearanceId = $distInfo->appearance_id;
        $model = new Model();
        $result =  $model->where('appearance_id', $appearanceId)->where('dist_id', $distId)->select('file_name')->get();
        $options = ['pages_detail.liquid'=>config('dictionary.landing_page_default_template')];
        foreach ($result as $key => $value) {
            // 检查字符串是否以 "pages_sp_" 开头
            if (strpos($value->file_name, 'pages_sp_') === 0) {
                // 提取 "xxxx" 部分
              //  $part = str_replace('pages_sp_', '', $value->file_name);
               // $part = str_replace('.liquid', '', $part);
                $part = $value->file_name;
                $options[$part] = $part;
            }
        }
        return $options;
    }

}



}
