<?php

use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Dcat\Admin\Admin;


/**
 * 原后台框架路由
 */
Admin::routes();

Route::group([
    'prefix'     => config('admin.route.prefix'),
    'namespace'  => config('admin.route.namespace'),
    'middleware' => config('admin.route.middleware'),
], function (Router $router) {
    //主页
    $router->get('/', 'HomeController@index');
    //产品
    //$router->get('base-product/parameter', 'DistProductController@parameter');
    $router->resource('dist-product', 'DistProductController');
    //分类
    $router->resource('product-category', 'DistProductCategoryController');
    //参数
    //$router->resource('product-parameter', 'DistProductParameterController');
    //视频分类
    $router->resource('video-category', 'DistVideoCategoryController');
    //视频管理
    $router->resource('dist-video', 'DistVideoController');
    //产品导入
    $router->get('import-product', 'ImportProductController@index');
    $router->get('import-product/{id}', 'ImportProductController@show');
    //询价管理
    $router->get('dist-inquiry', 'DistInquiryController@index');
    $router->get('dist-inquiry/{id}','DistInquiryController@show');
    //配置
    $router->get('dist-settings', 'SettingsController@index');
    $router->post('dist-settings', 'SettingsController@store');
    $router->post('dist-settings/upload', 'SettingsController@upload');
    $router->get('dist-cache', 'CacheController@index');
    $router->post('dist-cache/clear', 'CacheController@clear');
    //外观选择
    $router->get('dist-appearance', 'DistAppearanceController@index');
    //菜单管理
    $router->get('site-menu', 'SiteMenuController@index');//列表
    $router->get('site-menu/create','SiteMenuController@create');//新增
    $router->post('site-menu', 'SiteMenuController@store');//新增保存
    $router->get('site-menu/{id}/edit', 'SiteMenuController@edit');//编辑
    $router->put('site-menu/{id}', 'SiteMenuController@update');//编辑保存
    $router->delete('site-menu/{id}', 'SiteMenuController@destroy');//删除
    //文章管理
    $router->resource('site-pages', 'SitePagesController');
    $router->resource('site-pages-tag', 'SitePagesTagController');
    //banner管理
    $router->resource('site-banner', 'SiteBannerController');
    //API相关
    $router->get('api/products', 'ApiController@products');
    $router->get('api/pages', 'ApiController@pages');
    $router->get('api/landing-pages', 'ApiController@landingPages');
    $router->get('api/tag', 'ApiController@tag');
    $router->get('api/generate-slug', 'ApiController@generateSlug');
    $router->get('api/videos', 'ApiController@videos');
    // 定义切换语言的路由
    $router->get('language-switch','LanguageController@index');
    // 不需要登录的路由
    $router->get('captcha','CaptchaController@generate');

    $router->resource('messages', 'DistMessageController');
    //可视化编辑器
    $router->get('visual-editor', 'VisualEditorController@index');
    $router->post('visual-editor/upload', 'VisualEditorController@upload');
    $router->post('visual-editor/preview-save', 'VisualEditorController@previewSave');
    $router->post('visual-editor/publish', 'VisualEditorController@publish');
    //宣传资料
    $router->get('site-album', 'SiteAlbumController@index');
    $router->get('site-album/{id}', 'SiteAlbumController@show');

});

/*
 * 重写上传路由，修改tinymce上传路径
 */
$attributes = [
    'prefix'     => admin_base_path('dcat-api'),
    'middleware' => config('admin.route.middleware'),
    'as'         => 'dcat-api.',
];
app('router')->group($attributes, function ($router) {
    $router->post('editor-md/upload', function () {exit;})->name('editor-md.upload');
    $router->post('tinymce/upload', 'App\Http\Controllers\TinymceController@upload')->name('tinymce.upload');
});
