<?php
/**
 * @var $auctions WP_Term[]
 * @var $auctionsData array
 * @var $isAdmin boolean
 */

use auctionforge\inc\helpers\SettingsHelper;

?>
<?php foreach ($auctions as $auction) { ?>
    <?php
    $auction = apply_filters('auctionforge_prepare_auction_object', $auction);
    $auctionTitle = apply_filters('auctionforge_auction_name_build', $auction->name, $auction);

    $auctionId = SettingsHelper::getTermOption($auction->term_id, 'auction_id');
    $auctionNumber = SettingsHelper::getTermOption($auction->term_id, 'auction_number');
    $notification = "AUCTION_CATALOG_UPDATED";
    $paramsCatalogUpdated = [
        'auctionId' => $auctionId,
        'auctionNumber' => $auctionNumber,
        'notificationType' => $notification,
    ];

    //$notification = "AUCTION_DAY_ENDED";
    $notification = "AUCTION_UPDATED";
    $paramsAuctionDayEnded = [
        'auctionId' => $auctionId,
        'auctionNumber' => $auctionNumber,
        'notificationType' => $notification,
        'endedDayIndex' => 0,
        'auctionName' => $auctionTitle,
        'term' => $auction
    ];
    //{"endedDayIndex":1,"auctionId":242,"auctionNumber":"15","notificationType":"AUCTION_DAY_ENDED","auctionName":"Hidden auction"}
    ?>
    <tr>
        <td data-label="Auction"><?= $auctionId ?>: <?= $auctionTitle ?></td>
        <td data-label="Total lots"><?= $auction->count ?></td>
        <?php if (isset($auctionsData[$auctionId])) { ?>
            <td data-label="Not synced lots"><?= count($auctionsData[$auctionId]) ?></td>
        <?php } else { ?>
            <td data-label="Not synced lots">0</td>
        <?php } ?>
        <td data-label="Actions" class="actions">
            <div data-class="primary, secondary" style="text-align: center">
                <button data-action="<?= $auctionId ?>"
                    data-params='<?= json_encode($paramsCatalogUpdated) ?>'
                    class="tiny ui button re-sync-action"
                    data-tooltip="This button will start resync this auction lots sync process.">
                    Resync lots
                </button>
                &nbsp;
                <button data-action="<?= $auctionId ?>"
                        data-params='<?= json_encode($paramsAuctionDayEnded) ?>'
                        class="tiny ui button re-sync-action"
                        data-tooltip="This button will start resync this auction.">
                    Resync auction
                </button>
            </div>
        </td>
    </tr>
<?php } ?>