<?php
// pages/components/audience_list_modal.php
// Thin wrapper delegating to generic CRUD controller for Audience Lists

use Components\Resources\Controllers\CrudController;
use Components\Models\Audience;

ob_start();

echo CrudController::handle([
    'modelClass'   => Audience::class,
    'selfRoute'    => 'audience_list_modal',

    'event_prefix' => 'audience_lists',
    'autoclose' => true,
    'on_save' => function($model, $postAll, $id) {
        /** @var Audience $model */
        foreach ($model->newsletterItems() as $item) {
            \Components\Models\NewsletterItem::invalidateFlowCacheById((int)$item->newsletter_items_id);
        }
    },
]);

$__html = ob_get_clean();
echo $__html;
