<?php

namespace Modules\Admin\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Modules\Admin\Services\MenusService;

class AdminDatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $menus = [
            array (
                'icon' => 'username',
                'title' => '用户管理',
                'slug' => 'adminUsers',
                'path' => '/admin/users',
                'sort' => 10,
                'show' => '1',
                'child' =>
                    array (
                        0 =>
                            array (
                                'icon' => 'user',
                                'title' => '用户列表',
                                'slug' => 'adminUsersList',
                                'path' => '/admin/users/list',
                                'sort' => 10,
                                'show' => '1',
                                'child' =>
                                    array (
                                        0 =>
                                            array (
                                                'icon' => 'add-1',
                                                'title' => '添加用户',
                                                'slug' => 'adminUsersListAdd',
                                                'path' => '/admin/users/list/add',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        1 =>
                                            array (
                                                'icon' => 'search',
                                                'title' => '查看用户',
                                                'slug' => 'adminUsersListView',
                                                'path' => '/admin/users/list/view',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        2 =>
                                            array (
                                                'icon' => 'edit',
                                                'title' => '编辑用户',
                                                'slug' => 'adminUsersListEdit',
                                                'path' => '/admin/users/list/edit',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        3 =>
                                            array (
                                                'icon' => 'close',
                                                'title' => '删除用户',
                                                'slug' => 'adminUsersListDel',
                                                'path' => '/admin/users/list/del',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        4 =>
                                            array (
                                                'icon' => 'password',
                                                'title' => '重置密码',
                                                'slug' => 'adminUsersListResetpassword',
                                                'path' => '/admin/users/list/resetpassword',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                    ),
                            ),
                    ),
            ),
            array (
                'icon' => 'app',
                'title' => '矿区管理',
                'slug' => 'adminMine',
                'path' => '/admin/mine',
                'sort' => 10,
                'show' => '1',
                'child' =>
                    array (
                        0 =>
                            array (
                                'icon' => 'list',
                                'title' => '矿区列表',
                                'slug' => 'adminMineList',
                                'path' => '/admin/mine/list',
                                'sort' => 10,
                                'show' => '1',
                                'child' =>
                                    array (
                                        0 =>
                                            array (
                                                'icon' => 'add-1',
                                                'title' => '添加矿区',
                                                'slug' => 'adminMineAdd',
                                                'path' => '/admin/mine/add',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        1 =>
                                            array (
                                                'icon' => 'edit',
                                                'title' => '修改矿区',
                                                'slug' => 'adminMineEdit',
                                                'path' => '/admin/mine/edit',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                    ),
                            ),
                        1 =>
                            array (
                                'icon' => 'tabs',
                                'title' => '矿区区域列表',
                                'slug' => 'adminSurfaceList',
                                'path' => '/admin/surface/list',
                                'sort' => 10,
                                'show' => '1',
                                'child' =>
                                    array (
                                        0 =>
                                            array (
                                                'icon' => 'add-1',
                                                'title' => '添加区域',
                                                'slug' => 'adminSurfaceAdd',
                                                'path' => '/admin/surface/add',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        1 =>
                                            array (
                                                'icon' => 'search',
                                                'title' => '查看区域',
                                                'slug' => 'adminSurfaceView',
                                                'path' => '/admin/surface/view',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        2 =>
                                            array (
                                                'icon' => 'edit',
                                                'title' => '编辑区域',
                                                'slug' => 'adminSurfaceEdit',
                                                'path' => '/admin/surface/edit',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        3 =>
                                            array (
                                                'icon' => 'close',
                                                'title' => '删除区域',
                                                'slug' => 'adminSurfaceDel',
                                                'path' => '/admin/surface/del',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                    ),
                            ),
                    ),
            ),
            array (
                'icon' => 'video',
                'title' => '摄像头管理',
                'slug' => 'adminCamera',
                'path' => '/admin/camera',
                'sort' => 10,
                'show' => '1',
                'child' =>
                    array (
                        0 =>
                            array (
                                'icon' => 'list',
                                'title' => '摄像头列表',
                                'slug' => 'adminCameraList',
                                'path' => '/admin/camera/list',
                                'sort' => 10,
                                'show' => '1',
                                'child' =>
                                    array (
                                        0 =>
                                            array (
                                                'icon' => 'add-1',
                                                'title' => '添加记录',
                                                'slug' => 'adminCameraListAdd',
                                                'path' => '/admin/camera/list/add',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        1 =>
                                            array (
                                                'icon' => 'edit',
                                                'title' => '编辑记录',
                                                'slug' => 'adminCameraListEdit',
                                                'path' => '/admin/camera/list/edit',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        2 =>
                                            array (
                                                'icon' => 'search',
                                                'title' => '查看记录',
                                                'slug' => 'adminCameraListView',
                                                'path' => '/admin/camera/list/view',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        3 =>
                                            array (
                                                'icon' => 'close',
                                                'title' => '删除记录',
                                                'slug' => 'adminCameraListDel',
                                                'path' => '/admin/camera/list/del',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        4 =>
                                            array (
                                                'icon' => 'upload-drag',
                                                'title' => '导入记录',
                                                'slug' => 'adminCameraListImport',
                                                'path' => '/admin/camera/list/import',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                        5 =>
                                            array (
                                                'icon' => 'download-circle',
                                                'title' => '下载导入模板',
                                                'slug' => 'adminCameraListImportTemplate',
                                                'path' => '/admin/camera/list/importTemplate',
                                                'sort' => 10,
                                                'show' => '0',
                                                'child' =>
                                                    array (
                                                    ),
                                            ),
                                    ),
                            ),
                    ),
            ),
            array (
                'icon' => 'set-sm',
                'title' => '后台配置',
                'slug' => 'adminSetting',
                'path' => '/admin/setting',
                'sort' => 5,
                'show' => '1',
                'child' =>
                    array (
                        0 =>
                            array (
                                'icon' => 'table',
                                'title' => '菜单设置',
                                'slug' => 'adminSettingMenus',
                                'path' => '/admin/menus/list',
                                'sort' => 10,
                                'show' => '1',
                                'child' =>
                                    array (
                                    ),
                            ),
                        1 =>
                            array (
                                'icon' => 'add-1',
                                'title' => '添加菜单',
                                'slug' => 'adminSettingMenusAdd',
                                'path' => '/admin/menus/add',
                                'sort' => 10,
                                'show' => '0',
                                'child' =>
                                    array (
                                    ),
                            ),
                        2 =>
                            array (
                                'icon' => 'edit',
                                'title' => '编辑菜单',
                                'slug' => 'adminSettingMenusEdit',
                                'path' => '/admin/menus/edit',
                                'sort' => 10,
                                'show' => '0',
                                'child' =>
                                    array (
                                    ),
                            ),
                        3 =>
                            array (
                                'icon' => 'close',
                                'title' => '删除菜单',
                                'slug' => 'adminSettingMenusDel',
                                'path' => '/admin/menus/del',
                                'sort' => 10,
                                'show' => '0',
                                'child' =>
                                    array (
                                    ),
                            ),
                    ),
            ),
        ];

        $this->addMenu($menus);
    }

    public function addMenu($menuList, $parentId = 0)
    {
        $menuService = new MenusService();
        foreach ($menuList as $menu) {
            $menu['parent_id'] = $parentId;
            $_menu             = $menu;
            unset($_menu['child']);
            $menu_parent = $menuService->addMenu($_menu, 'slug');
            if (count($menu['child']) > 0) {
                $this->addMenu($menu['child'], $menu_parent['id']);
            }
        }
    }
}
