<?php

use Phinx\Seed\AbstractSeed;

class MenuSeeder extends AbstractSeed
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run(): void
    {
        $data = [
            [
                'name' => 'Main Menu',
                'module' => 'menu',
            ],
            [
                'name' => 'Account Menu',
                'module' => 'menu',
            ],
        ];

        foreach ($data as $row) {
            $this->execute("INSERT INTO menus (name, module) VALUES (:name, :module) ON DUPLICATE KEY UPDATE name=:name", [':name' => $row['name'], ':module' => $row['module']]);
        }

        $data = [
            [
                "title" => "Home",
                "routeName" => 'home',
                "href" => '/',
                "icon" => "home",
                "mid" => 1,
                "parentId" => 0,
            ],
            [
                "title" => "Settings",
                "routeName" => 'user.display.settings',
                "href" => '/user/settings',
                "icon" => "cogs",
                "mid" => 2,
                "parentId" => 0,
            ],
            [
                "title" => "Logout",
                "routeName" => 'user.logout',
                "href" => '/logout',
                "icon" => "sign-out",
                "mid" => 2,
                "parentId" => 0,
            ],
        ];

        foreach ($data as $row) {
            $this->execute(
                "INSERT INTO menu_links (title, routeName, href, icon, mid, parentId)
                VALUES (:title, :routeName, :href, :icon, :mid, :parentId)
                ON DUPLICATE KEY UPDATE title=:title, routeName=:routeName, href=:href, icon=:icon, mid=:mid, parentId=:parentId",
                [
                    ':title' => $row['title'],
                    ':routeName' => $row['routeName'],
                    ':href' => $row['href'],
                    ':icon' => $row['icon'],
                    ':mid' => $row['mid'],
                    ':parentId' => $row['parentId'],
                ]
            );
        }
    }
}
