Jake Vanderwerf
2025-09-30 6a627f09d33967ca7fa5b6d939a9347d8223a1e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
<?php
namespace JVBase\managers;
 
use JVBase\managers\CRUD;
use JVBase\meta\MetaManager;
use WP_User;
 
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
 
/**
 * The base constructor for our custom dashboard
 */
class DashboardManager
{
    protected WP_User $user;
    protected CacheManager $cache;
    protected string $role;
    protected int $userLink;
 
    public function __construct()
    {
        $this->cache = new CacheManager('dashboard');
        $this->cache->invalidateGroup('dashboard');
        add_action('init', [$this, 'registerDashboard']);
        if (!$this->isRegistered()) {
            add_action('init', [$this, 'buildDashboard']);
        }
        $this->user = wp_get_current_user();
        $this->role = jvbUserRole();
        $this->userLink = (int)get_user_meta($this->user->ID, BASE.'link', true);
 
        add_action('template_include', [$this, 'dashboardTemplates']);
        add_action('admin_init', [$this, 'redirectFromAdmin']);
        add_action('wp_enqueue_scripts', [$this, 'dashboardScripts'], 50);
    }
 
    /**
     * Registers the custom post type that handles the dashboard
     * @return void
     */
    public function registerDashboard():void
    {
 
        $plural = 'Dashboards';
        $singular = 'Dashboard';
        register_post_type(BASE.'dash', array(
            'labels'                => [
                'name' => $plural,
                'singular_name' => $singular,
                'menu_name' => $plural,
                'add_new' => "Add New {$singular}",
                'add_new_item' => "Add New {$singular}",
                'edit_item' => "Edit {$singular}",
                'new_item' => "New {$singular}",
                'view_item' => "View {$singular}",
                'search_items' => "Search {$plural}",
                'not_found' => "No {$plural} found",
                'not_found_in_trash' => "No {$plural} found in Trash"
            ],
            'menu_icon'             => jvbCSSIcon('gauge'),
            'public'                => true,
            'publicly_queryable'    => true,
            'show_in_menu'          => true,
            'show_in_admin_bar'     => false,
            'has_archive'           => true,
            'hierarchical'          => true,
            'rewrite'               => array(
                'slug'          => 'dash',
                'with_front'    => false
            ),
            'capability_type'   => 'post',
            'supports'          => array('title', 'editor', 'custom-fields')
        ));
    }
 
    /**
     * Redirect all non-admin users from wp-admin to custom dashboard
     */
    public function redirectFromAdmin()
    {
        // Allow admins to access wp-admin if needed
        if (current_user_can('manage_options')) {
            return;
        }
 
        // Redirect to custom dashboard
        wp_redirect(home_url('dash'));
        exit;
    }
 
    /**
     * Ensures the necessary pages ar created
     * @return void
     */
    public function buildDashboard():void
    {
        $manageableContent = jvbGetAllDashboardPages();
        foreach ($manageableContent as $slug) {
            $title = $this->getTitle($slug);
            $slug = sanitize_title($title);
 
            $ID = wp_insert_post(array(
                'post_title'    => $title,
                'post_name'     => $slug,
                'post_type'     => BASE.'dash',
                'post_status'   => 'publish',
            ));
 
            if ($title === 'Integrations') {
                $integrations = ['BlueSky', 'Cloudflare', 'Facebook', 'Google Maps', 'Google My Business', 'Helcim', 'Instagram', 'Square', 'Umami'];
                foreach ($integrations as $integration) {
                    $slug = sanitize_title($integration);
                    wp_insert_post([
                        'post_title'    => $integration,
                        'post_name'     => $slug,
                        'post_type'     => BASE.'dash',
                        'post_status'   => 'publish',
                        'post_parent'   => $ID
                    ]);
                }
            }
        }
        update_option(BASE.'dashboard_registered', true);
        remove_action('init', [$this, 'buildDashboard']);
    }
 
    protected function getTitle(string $page):string
    {
        $content = JVB_CONTENT;
        $contentTax = array_filter(JVB_TAXONOMY, function ($tax) {
            return jvbCheck('is_content', $tax);
        });
        $content = array_merge($content, $contentTax);
        $title = '';
 
 
        if (array_key_exists($page, $content)) {
            $config = $content[$page];
            $title = (array_key_exists('dash_title', $config)) ? $config['dash_title'] : $config['plural'];
        } else {
            switch ($page) {
                case 'admin':
                    $title = 'Admin';
                    break;
                default:
                    $title = ucwords(str_replace('_', ' ', str_replace('-', ' ', $page)));
            }
        }
 
        return $title;
    }
 
    protected function getDescription(string $page):string
    {
        $content = JVB_CONTENT;
        $contentTax = array_filter(JVB_TAXONOMY, function ($tax) {
            return jvbCheck('is_content', $tax);
        });
        $content = array_merge($content, $contentTax);
        if (array_key_exists($page, $content)) {
            $config = $content[$page];
            $description = (array_key_exists('dash_description', $config)) ? $config['dash_description'] : '';
        } else {
            switch ($page) {
                case 'approval':
                    $description = 'See your approval requests for term creation, joining shops, or joining edmonton.ink. You can also help shape the community by approving other\'s requests!';
                    break;
                case 'metrics':
                    $description = 'See what kind of traffic you\'re getting. <i>(coming soon)</i>';
                    break;
                case 'favourites':
                    $description = 'See what you favourited, and create, manage, and share lists.';
                    break;
                case 'support':
                    $description = 'Sometimes we all need a hand. This is your direct access to the site admin - or text Jake at <a href="sms:18258239916">825-823-9916</a>';
                    break;
                case 'settings':
                    $description = 'Control your privacy and email frequency.';
                    break;
            }
        }
 
        return $description;
    }
 
    /**
     * Checks if we've already created the need pages
     * @return bool
     */
    protected function isRegistered():bool
    {
        return get_option(BASE.'dashboard_registered', false);
    }
 
    /**
     * Hacking into the template_include to set our custom templates and protections
     * @param string $template
     *
     * @return string
     */
    public function dashboardTemplates(string $template):string
    {
        if (!is_singular(BASE.'dash') && !is_post_type_archive(BASE.'dash')) {
            return $template;
        }
        if (!isOurPeople() && !current_user_can('manage_options')) {
            wp_redirect(wp_login_url(get_home_url(2, '/dash')));
            exit;
        }
 
        // Get current page/section
 
        $page = $this->getCurrentPage();
 
        // Enqueue needed styles/scripts
        jvbInlineStyles('nav');
        jvbInlineStyles('dash');
        jvbInlineStyles('forms');
        $this->cache->delete($page);
        echo $this->cache->remember(
            $page,
            function() use ($page) {
                ob_start();
                $this->renderHeader();
 
                switch ($page) {
                    case 'dash':
                        if (current_user_can('manage_options')) {
                            $content = apply_filters('jvbAdminDashboard', '');
 
                            if ($content !== '') {
                                echo $content;
                            }else {
                                $this->renderAdmin();
                            }
                        } else {
                            $this->renderIndex();
                        }
 
                        break;
                    case 'admin':
                        $this->renderAdmin();
                        break;
                    case 'bio':
                        $this->renderForm(JVB_USER[$this->role]['profile']);
                        break;
                    case 'settings':
                        $this->renderSettings();
                        break;
                    case 'integrations':
                    case 'bluesky':
                    case 'cloudflare':
                    case 'facebook':
                    case 'google-maps':
                    case 'google-my-business':
                    case 'helcim':
                    case 'instagram':
                    case 'square':
                    case 'umami':
                        $this->renderIntegrations($page);
                        break;
                    case 'approval':
                        $this->renderApprovals();
                        break;
                    default:
                        $this->renderCRUD($page);
                        break;
                }
 
                echo jvbLoadingScreen();
                $this->renderFooter();
 
                // Get buffer contents and clean buffer
                return ob_get_clean();
            }
        );
 
        // Return empty string to prevent default template
        return '';
    }
 
    /**
     * Enqueues necessary scripts
     * @return void
     */
    public function dashboardScripts():void
    {
        if (is_post_type_archive(BASE.'dash') || is_singular(BASE.'dash')) {
 
 
//        wp_enqueue_style('quill-css', 'https://cdn.quilljs.com/1.3.6/quill.snow.css');
 
 
            wp_enqueue_script('jvb-loading');
            wp_enqueue_script('jvb-form');
 
 
            // Consolidate all dashboard settings
            wp_localize_script('jvb-loading', 'dashboardSettings', array(
                'loadingMessages' => array(
                    'default' => 'Loading...',
                    'error' => 'Failed to load page'
                ),
                'strings' => array(
                    'deleteConfirm' => 'Are you sure you want to delete this item?',
                    'bulkDeleteConfirm' => 'Are you sure you want to delete these items?',
                    'deleteSuccess' => 'Item(s) deleted successfully',
                    'deleteError' => 'Error deleting item(s)',
                    'saveSuccess' => 'Changes saved successfully',
                    'saveError' => 'Error saving changes',
                    'loadError' => 'Error loading content'
                ),
                'currentUser' => array(
                    'id' => $this->user->ID,
                    'name' => $this->user->display_name,
                    'role' => array_values($this->user->roles)[0] ?? '',
                    'type' => str_replace(BASE, '', array_values($this->user->roles)[0]),
                    'city' => '', // Add if needed,
                    'artistID'  => $this->userLink,
                )
            ));
 
            wp_enqueue_script('jvb-selector');
            wp_enqueue_script('jvb-uploader');
            wp_enqueue_script('jvb-content');
            wp_enqueue_script('jvb-crud');
//            wp_enqueue_script('jvb-dashboard-navigator');
 
            $page = $this->getCurrentPage();
 
            switch ($page) {
                case 'notifications':
                    if (jvbSiteHasNotifications()) {
                        wp_enqueue_script('jvb-notification-manager');
                    }
                    break;
                case 'integrations':
                    wp_enqueue_script('jvb-integrations');
 
                    break;
                case 'admin':
                case 'dash':
                    if (current_user_can('manage_options') && apply_filters('jvbAdminDashboard', '') === '') {
                        wp_enqueue_script(
                        'jvb-admin',
                        JVB_URL . 'assets/js/min/admin.min.js',
                        [
                            'jvb-queue',
                            'jvb-loading'
                        ],
                        [
                            'strategy' => 'defer',
                            'in_footer' => true
                        ]
                    );
 
                    wp_localize_script(
                        'jvb-admin',
                        'jvbAdmin',
                        [
                            'nonce' => wp_create_nonce('itsme')
                        ]
                    );
                    }
                    break;
            }
            if (jvbSiteHasFavourites()) {
                 wp_enqueue_script('jvb-favourites');
                wp_localize_script('jvb-favourites-manager', 'favouritesSettings', [
                    'strings' => [
                        'loadError' => 'Error loading favourites',
                        'saveError' => 'Error updating favourite',
                        'removeSuccess' => 'Removed from favourites',
                        'addSuccess' => 'Added to favourites'
                    ]
                ]);
            }
 
 
 
            wp_enqueue_script('jvb-creator');
 
            if (jvbSiteHasForum()) {
            wp_enqueue_script('jvb-news');
            }
            do_action('jvbDashScripts', $page);
        }
    }
 
    protected function getCurrentPage():string
    {
        global $wp;
        $dash = str_replace('dash/', '', $wp->request);
        if (str_starts_with($dash, 'integrations/')) {
            $dash = str_replace('integrations/', '', $dash);
        }
 
        return ($dash === '') ? 'dash' : $dash;
    }
 
    protected function renderHeader():void
    {
    ?>
        <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
        <head>
            <title><?= (array_key_exists('dashboard_title', JVB_SITE)) ? JVB_SITE['dashboard_title'] : 'Dashboard | '.get_bloginfo('name') ?></title>
            <meta charset="<?php bloginfo('charset'); ?>">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <?php
            $pages = jvbGetUserDashboardPages();
            foreach($pages as $page) {
                $page = str_replace('_', '-', $page);
                $link = ($page === 'dash') ? '/'.$page : "/dash/$page";
                ?>
                <link rel="preconnect" href="<?= get_home_url(2, $link)?>"/>
                <?php
            }
             ?>
             <link rel="preconnect" href="<?= get_home_url()?>"/>
            <?php wp_head(); ?>
        </head>
    <body class="dashboard<?= ' '.$this->getCurrentPage()?>">
        <?php jvbAccessibility();?>
        <header>
            <?php
            $checked = (is_user_logged_in() && current_user_can('prefers_dark_theme', true)) ? ' checked' : '';
            $title = ($checked == '') ? 'Toggle Dark Mode' : 'Toggle Light Mode';
            echo '<label title="'.$title.'" id="theme-switch" class="toggle-switch" for="theme-switcher">
        <input class="theme-switch row" id="theme-switcher" type="checkbox"'.$checked.' role="switch" name="dark-mode"><span class="slider">'.
                 jvbIcon('light').
                 jvbIcon('dark').'</span></label>';
            ?>
            <p class="title">
                <a href="<?= get_home_url(); ?>" rel="home" title="Back to Site">
                    <?= jvbIcon('logo-basic'); ?>
                </a>
            </p>
 
            <nav>
                <ul>
                    <?= jvbNotificationMenu() ?>
                    <?= jvbHelpMenu() ?>
                </ul>
            </nav>
        </header>
 
        <main><section class="replace">
    <?php
    }
 
    protected function renderFooter():void
    {
        ?>
        </section>
        <footer class="col">
            <nav class="dashboard-nav">
                <?php
                $current_page = $this->getCurrentPage();
                $pages = jvbGetUserDashboardPages()?:[];
 
                global $jvb_everything;
                echo '<ul>';
                foreach ($pages as $page) {
                    // Add data-page attribute for the navigator
                    $active = ($current_page == $page) ? ' class="current"' : '';
                    $current = ($current_page == $page) ? ' aria-current="page"' : '';
                    $icon = (array_key_exists($page, $jvb_everything)) ? $jvb_everything[$page]['icon'] ?? $page : $page;
 
                    $title = $this->getTitle($page);
                    $page = str_replace('_', '-', $page);
 
                    $link = ($page === 'dash') ? '/'.$page : "/dash/$page";
 
                    printf(
                        '<li%s><a href="%s"%s data-page="%s" data-dash title="%s">%s<span>%s</span></a></li>',
                        $active,
                        get_home_url(2, $link),
                        $current,
                        $page,
                        $title,
                        jvbIcon($icon, ['title'=> $title]),
                        $title
                    );
                }
 
                echo '</ul>';
                ?>
            </nav>
        </footer>
 
 
        <?php
        do_action('jvbRenderDashboardSettings', $this->getCurrentPage());
        ?>
        <?php wp_footer(); ?>
 
        </body>
        </html>
 
        <?php
    }
 
    protected function renderIndex():void
    {
        $name = get_post_meta($this->userLink, BASE.'firstname', true);
        $name = ($name === '') ? $this->user->display_name : $name;
 
        echo '<h1 style="text-transform:none;margin-top:2em!important;">Hey '.$name.'</h1>';
        echo '<p>Welcome back!</p>';
 
        $pages = jvbGetUserDashboardPages();
 
 
        echo '<h2>What would you like to do today?</h2>';
 
        global $jvb_everything;
        echo '<ul>';
        foreach ($pages as $page) {
 
            $title = $this->getTitle($page);
            $url = sanitize_title($title);
            $description = $this->getDescription($page);
 
            if ($title !== '') {
                echo '<li><p><a href="'.get_home_url(2, '/dash/'.$url.'/').'"
                    data-page="'.$url.'" data-dash>'.jvbIcon($page).ucfirst($title).'</a></p>'.$description.'</li>';
            }
 
        }
        echo '</ul>';
 
        echo '<p>Everything saves auto-magically, so rest easy.</p>';
 
    }
    /**
     * Similar to CRUD, except it only manages a single item, such as a user's profile or a shop
    * @param string $type
    *
    * @return void
     */
    protected function renderForm(string $type):void
    {
        if (!current_user_can('manage_'.$type)) {
            wp_redirect(get_home_url(2, '/dash'));
            exit;
        }
        wp_enqueue_script(
            'jvb-bio-manager',
            JVB_URL.'assets/js/min/bioManager.min.js',
            array('jvb-queue', 'sortablejs', 'quill-js', 'jvb-selector'),
            '1.0.0',
            true
        );
        wp_localize_script('jvb-bio-manager', 'bioSettings', [
            'type'   => 'bio_update',
        ]);
        jvbRenderSections($this->userLink, 'post', $type);
    }
 
    protected function renderSettings():void
    {
        if (!current_user_can('manage_options') && !current_user_can('manage_settings')) {
            wp_redirect(get_home_url(2, '/dash'));
            exit;
        }
        wp_enqueue_script('jvb-form');
        wp_enqueue_script(
            'jvb-bio-manager',
            JVB_URL.'assets/js/min/bioManager.min.js',
            array('jvb-client-queue', 'sortablejs', 'quill-js', 'jvb-taxonomy-selector'),
            '1.0.0',
            true
        );
        wp_localize_script('jvb-bio-manager', 'bioSettings', [
            'type'   => 'user_settings',
        ]);
        $content = apply_filters('jvbDashboardSettings', '');
        if ($content !== '') {
            echo $content;
        } else {
        jvbRenderSections($this->user->ID, 'user', jvbUserRole());
        }
 
    }
 
    protected function getIntegrationsMenu():string
    {
        $integrations = JVB()->getAvailableServices(false);
        $out = '';
        if (!empty($integrations)) {
            $out = '<nav class="integrations"><ul>';
 
            $url = get_home_url(2, '/dash/integrations/');
            $out .= '<li><a href="'.$url.'">'.jvbIcon('plugs-connected').'Integrations</a></li>';
            foreach ($integrations as $name=> $integration) {
                if (!JVB()->userCanConnect($name, $this->user->ID) || !$integration->hasDefaults()) {
                    continue;
                }
                $link = sanitize_title(str_replace('_', '-',$name));
                $out .= '<li><a href="'.$url.$link.'">'.jvbIcon($integration->icon).$integration->getTitle().'</a></li>';
            }
            $out .= '</ul></nav>';
        }
        return $out;
    }
 
    protected function renderIntegrations(string $page):void
    {
 
        //TODO: Make manage_integrations permission
//      if (!current_user_can('manage_integrations')) {
//          wp_redirect(get_home_url(2, '/dash'));
//          exit;
//      }
        echo $this->getIntegrationsMenu();
        $map = [
            'google-my-business' => 'gmb',
            'google-maps'       => 'maps'
        ];
        $connection = (array_key_exists($page, $map)) ? $map[$page] : $page;
        if ($connection !== 'integrations') {
 
            $userID = (jvbSiteHasMembership()) ? $this->user->ID : null;
            $integration = JVB()->connect($connection, $userID);
 
            echo '<h1>Managing '.$integration->title.'</h1>';
            $integration->renderDefaults();
        } else {
            ?>
            <section class="item-grid integrations">
            <?php
            $all = JVB()->getAvailableServices();
            foreach ($all as $name) {
                if (current_user_can('manage_options')) {
                    $userID = null;
                } else {
                    $userID = $this->user->ID;
                }
 
                JVB()->connect($name, $userID)->renderConnection();
            }
            ?>
            </section>
            <?php
 
        }
 
 
    }
 
    protected function renderApprovals():void
    {
        if (!current_user_can('skip_moderation')) {
            wp_redirect(get_home_url(2, '/dash'));
            exit;
        }
        ?>
        <div class="approvals container">
            <nav class="tabs row start" role="tablist">
                <button type="button" class="tab active" data-tab="summary" role="tab" aria-selected="true">
                    <h2><?= jvbIcon('all')?>All</h2>
                </button>
                <button type="button" class="tab" data-tab="artists" role="tab" aria-selected="false">
                    <h2><?= jvbIcon('artists')?>Artists</h2>
                </button>
                <button type="button" class="tab" data-tab="terms" role="tab" aria-selected="false">
                    <h2><?= jvbIcon('style')?>Terms</h2>
                </button>
                <button type="button" class="tab" data-tab="yours" role="tab" aria-selected="false">
                    <h2><?= jvbIcon('artist')?>Yours</h2>
                </button>
            </nav>
        </div>
        <section>
            <table>
                <thead>
                    <tr>
                        <th scope="col">
                            <input type="checkbox" id="select-all" name="select-all">
                            <label for="select-all">All</label>
                        </th>
                        <th scope="col">
                            Name
                        </th>
                        <th scope="col">
                            Requester
                        </th>
                        <th>
                            Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
 
                </tbody>
                <tfoot>
                    <tr>
                        <th scope="col">
                            <input type="checkbox" id="select-all" name="select-all">
                            <label for="select-all">All</label>
                        </th>
                        <th scope="col">
                            Name
                        </th>
                        <th scope="col">
                            Requester
                        </th>
                        <th scope="col">
                            Actions
                        </th>
                    </tr>
                </tfoot>
            </table>
        </section>
        <?php
    }
 
    protected function renderFavourites():void
    {
 
    }
 
    protected function renderCRUD(string $type):void
    {
        $type = match($type) {
            'menu-item' => 'menu_item',
            'events'    => 'event',
            default => $type
        };
 
        $permission = JVB_CONTENT[$type]['plural']??$type.'s';
        if (!current_user_can('edit_'.$permission)) {
            wp_redirect(get_home_url(2, '/dash'));
            exit;
        }
        $crud = new CRUD($type);
        $crud->render();
 
    }
 
    protected function renderAdmin():void
    {
        //TODO: This has to be built from the settings from setup.php
        if (!current_user_can('manage_options')) {
            wp_redirect(get_home_url(2, '/dash'));
            exit;
        }
 
        ?>
        <nav class="tabs row start" role="tablist">
        <?php
        $i=1;
        $content = JVB_CONTENT;
        $contentTax = array_filter(JVB_TAXONOMY, function ($tax) {
            return jvbCheck('is_content', $tax);
        });
        $taxonomies = JVB_TAXONOMY;
        foreach($contentTax as $key => $config) {
            unset($taxonomies[$key]);
        }
        $content = array_merge($content, $contentTax);
        foreach ($content as $type => $settings) {
            $active = ($i === 1) ? ' active' : '';
            ?>
            <button type="button" class="tab<?=$active?>" data-tab="<?=$type?>" role="tab" aria-selected="<?= ($active !== '') ? 'true' : 'false'?>">
                <h2><?=jvbIcon($type)?> <?= $settings['plural'] ?></h2>
            </button>
            <?php
            $i++;
        }
         ?>
 
        <label for="tab-select">Taxonomy:</label><select class="tab-list" id="tab-select">
            <option> ... Taxonomy</option>
            <?php
 
            foreach ($taxonomies as $type => $settings) {
                echo '<option value="'.$type.'">'.$settings['plural'].'</option>';
            }
            ?>
        </select>
 
    </nav>
 
    <div class="tab-content active" data-tab="artist" role="tabpanel">
        <h1>Artists<small>Manage artists here</small></h1>
    </div>
    <div class="actions">
        <?= jvbRenderToggleTextField(
            'vertical',
            'TAB NAV:',
            '',
            jvbIcon('down'),
            jvbIcon('right'))?>
 
    </div>
    <div class="items-container">
    </div>
 
    <?php
    global $jvb_everything;
 
    foreach ($jvb_everything as $type => $settings) {
        $meta = new MetaManager(null, 'form');
        $fields = jvbGetFields($type);
        ?>
        <template class="<?= $type ?>Table">
            <table>
                <thead>
                    <tr>
                        <th id="select" scope="col"></th>
                        <th scope="col">Actions</th>
                        <?php
                        foreach ($fields as $n => $config) {
                            if (array_key_exists('quickEdit', $config)) {
                                $extra = '';
                                switch ($config['type']) {
                                    case 'set':
                                    case 'radio':
                                        $extra = '( '.implode(', ', $config['options']).' )';
                                        break;
                                    case 'repeater':
                                        $temp = [];
                                        foreach ($config['fields'] as $f => $c) {
                                            $temp[] = $c['label'];
                                        }
                                        $extra = '[ '.implode(', ', $temp).' ]';
                                        break;
                                }
                                $extra = ($extra === '') ? '' : '<p>'.$extra.'</p>';
                                if (!array_key_exists('label', $config)) {
                                    error_log('No label set for: '.print_r($n, true));
                                }
                                ?>
                                <th scope="col" data-id="<?=$n?>">
                                    <?= $config['label'].$extra ?>
                                </th>
                                <?php
                            }
                        }
                        ?>
                    </tr>
                </thead>
                <tbody></tbody>
                <tfoot></tfoot>
            </table>
        </template>
 
        <template class="<?= $type ?>Row">
            <tr>
                <td>
                     <?= jvbIcon('grab') ?>
                 </td>
                 <td data-id="actions" class="col">
                     <?= jvbRenderToggleTextField(
                         'public',
                         '',
                         '',
                         jvbIcon('show'),
                         jvbIcon('hide'))
                     ?>
                     <button type="button" data-action="edit">
                         <?= jvbIcon('edit') ?>
                    </button>
                </td>
                <?php
                foreach ($fields as $n => $config) {
                    if (array_key_exists('quickEdit', $config)) {
                        ?>
                        <td data-id="<?= $n ?>">
                            <?php
                            $config['type'] = 'text';
                            $config['description'] = '';
                            $meta->render('form', $n, $config);
                            ?>
                        </td>
                        <?php
                    }
                }
                ?>
            </tr>
        </template>
 
        <?php
 
        echo jvbNewModal(
            'edit-modal '.$type,
            'Edit '.ucfirst($type),
            $meta->renderForm('admin', [], $fields)
        );
        }
    }
}