<?php

if (!class_exists('nc_core')) { die; }

?>
<div class="nc_admin_fieldset_head"><?= NETCAT_MODULE_SERVICES_DIRECT_BANNERS; ?></div>
<?php

$table = $ui->table()->wide()->striped()->bordered()->hovered();

$thead = $table->thead(); // chaining produces invalid code

$thead->th(NETCAT_MODULE_SERVICES_DIRECT_BANNER_ID)->compact()->text_center();
$thead->th(NETCAT_MODULE_SERVICES_DIRECT_BANNER_TITLE)->compact()->text_center();
$thead->th(NETCAT_MODULE_SERVICES_DIRECT_BANNER_HREF)->text_center();
$thead->th(NETCAT_MODULE_SERVICES_DIRECT_BANNER_STATUS)->compact()->text_center();
$thead->th(NETCAT_MODULE_SERVICES_DIRECT_BANNER_PHRASES_STATUS)->compact()->text_center();
$thead->th()->compact();
$thead->th()->compact();

$tr = $table->row();
$tr->id = $tr->td();
$tr->title = $tr->td();
$tr->link = $tr->td();
$tr->status = $tr->td()->text_center();
$tr->phrases_status = $tr->td()->text_center();
$tr->action_links = $tr->td()->text_center();
$tr->delete_button = $tr->td()->text_center();

foreach ($banners as $row) {
    $banner_id = $row['BannerID'];
    $edit_link = "$link_prefix.banner.edit($banner_id)";

    $post_actions_params = array('controller' => "direct", 'banner_id' => $banner_id, 'campaign_id' => $campaign_id);

    $tr->id->text($banner_id);
    $tr->title->text(
        "<a href='$edit_link' target='_top' class='nc-netshop-list-item-title'>" . $row['Title'] . "</a>"
    );
    
    $tr->link->text($row['Href'])->text_center();
    $tr->status->text($row['StatusText']);
    $tr->phrases_status->text($row['StatusPhrasesText']);

    $archive_link =  $current_url . "archive_banner&campaign_id=$campaign_id&banner_id=$banner_id";
    $unarchive_link =  $current_url . "unarchive_banner&campaign_id=$campaign_id&banner_id=$banner_id";
    $resume_link =  $current_url . "resume_banner&campaign_id=$campaign_id&banner_id=$banner_id";
    $stop_link =  $current_url . "stop_banner&campaign_id=$campaign_id&banner_id=$banner_id";
    
    $tr->action_links->text(
      (!empty($row['ShowArchiveAction']) ? "<a href='".$archive_link."'>".NETCAT_MODULE_SERVICES_ACTION_ARCHIVE."</a><br>" : "")
      . (!empty($row['ShowUnarchiveAction']) ? "<a href='".$unarchive_link."'>".NETCAT_MODULE_SERVICES_ACTION_UNARCHIVE."</a><br>" : "")
      . (!empty($row['ShowResumeAction']) ? "<a href='".$resume_link."'>".NETCAT_MODULE_SERVICES_ACTION_RESUME."</a><br>" : "")
      . (!empty($row['ShowStopAction']) ? "<a href='".$stop_link."'>".NETCAT_MODULE_SERVICES_ACTION_STOP."</a><br>" : "")
    );
    
    $tr->delete_button->text(
      $ui->controls->delete_button(
        sprintf(NETCAT_MODULE_SERVICES_CONFIRM_DELETE, $row['Title']),
        $post_actions_params
    ));

    $table->add_row($tr);
}


echo $table, "<br>";
