<?php

namespace App\Models;

use App\Core\Model;

class Menu extends Model
{
    protected static string $table = 'iw_menus';

    public static function getItems(string $location): array
    {
        $menu = static::findWhere(['location' => $location]);
        if (!$menu) {
            return [];
        }

        return static::db()->fetchAll(
            "SELECT * FROM iw_menu_items WHERE menu_id = :menu_id AND is_visible = 1 ORDER BY sort_order ASC",
            ['menu_id' => $menu['id']]
        );
    }
}
