/**
  * Display tracking on Order/Mail etc.
  *
  * @param string $content
  * @param WC_Order $wc_order
  * @return string
  */
 static function order_display_tracking_info($content, $wc_order)
 {
     $order = new Bring_WC_Order_Adapter($wc_order);
     if ($order->is_booked()) {
         $content .= '<div class="bring-order-details-booking">';
         $content .= '<strong>' . __('Your tracking number: ', 'bring-fraktguiden') . '</strong>';
         $content .= '<ul>';
         foreach ($order->get_booking_consignments() as $consignment) {
             $confirmation = $consignment->confirmation;
             $consignment_number = $confirmation->consignmentNumber;
             $content .= '<li><a href="' . $confirmation->links->tracking . '">' . $consignment_number . '</a></li>';
         }
         $content .= '</ul>';
         $content .= '</div>';
     }
     return $content;
 }
    /**
     * @param Bring_WC_Order_Adapter $order
     */
    static function render_consignments($order)
    {
        $consignments = $order->get_booking_consignments();
        if ($consignments) {
            ?>
      <div class="bring-consignments">
        <?php 
            foreach ($consignments as $consignment) {
                //$correlation_id     = $consignment->correlationId;
                $errors = $consignment->errors;
                $confirmation = $consignment->confirmation;
                $consignment_number = $confirmation->consignmentNumber;
                $links = $confirmation->links;
                $tracking = $links->tracking;
                $date_and_times = $confirmation->dateAndTimes;
                $earliest_pickup = $date_and_times->earliestPickup ? date_i18n(wc_date_format(), $date_and_times->earliestPickup / 1000) : 'N/A';
                $expected_delivery = $date_and_times->expectedDelivery ? date_i18n(wc_date_format(), $date_and_times->expectedDelivery / 1000) : 'N/A';
                $packages = $confirmation->packages;
                $labels_url = Bring_Booking_Labels::create_download_url($order->order->id);
                ?>
          <div>
            <table>
              <tr>
                <th colspan="2"><?php 
                printf('NO: %s', $consignment_number);
                ?>
</th>
              </tr>
              <tr>
                <td><?php 
                _e('Earliest Pickup', 'bring-fraktguiden');
                ?>
:</td>
                <td><?php 
                echo $earliest_pickup;
                ?>
</td>
              </tr>
              <tr>
                <td><?php 
                _e('Expected delivery', 'bring-fraktguiden');
                ?>
:</td>
                <td><?php 
                echo $expected_delivery;
                ?>
</td>
              </tr>
              <tr>
                <td><?php 
                _e('Labels', 'bring-fraktguiden');
                ?>
:</td>
                <td>
                  <a href="<?php 
                echo $labels_url;
                ?>
"
                     target="_blank"><?php 
                _e('Download', 'bring-fraktguiden');
                ?>
</a>
                </td>
              </tr>
              <tr>
                <td><?php 
                _e('Tracking', 'bring-fraktguiden');
                ?>
:</td>
                <td>
                  <a href="<?php 
                echo $tracking;
                ?>
"
                     target="_blank"><?php 
                _e('View', 'bring-fraktguiden');
                ?>
                    →</a>
                </td>
              </tr>
              <tr>
                <td>
                  <?php 
                _e('Packages', 'bring-fraktguiden');
                ?>
:
                </td>
                <td>
                  <ul>
                    <?php 
                foreach ($packages as $package) {
                    //$correlation_id = property_exists( $package, 'correlationId' ) ? $package->correlationId : 'N/A';
                    ?>
                      <li style="position: relative">
                        <span class="bring-package"></span>
                        <?php 
                    printf('NO: %s', $package->packageNumber);
                    ?>
                      </li>
                    <?php 
                }
                ?>
                  </ul>
                </td>
              </tr>
            </table>
          </div>
          <?php 
            }
            ?>
      </div>
      <?php 
        }
    }
 static function open_pdfs()
 {
     add_submenu_page(null, 'Download', 'Download', 'manage_woocommerce', 'bring_labels', function () {
         if (!isset($_GET['order_ids']) || $_GET['order_ids'] == '') {
             return;
         }
         $current_user = wp_get_current_user();
         // ID 0 is a not an user.
         if ($current_user->ID == 0) {
             exit;
         }
         // Admins and managers can download all orders.
         $can_download = in_array('manage_woocommerce', $current_user->roles) || in_array('administrator', $current_user->roles);
         if (!$can_download) {
             exit;
         }
         $order_ids = explode(',', $_GET['order_ids']);
         $files_to_merge = [];
         foreach ($order_ids as $order_id) {
             $order = new Bring_WC_Order_Adapter(new WC_Order($order_id));
             if (!$order->has_booking_consignments()) {
                 continue;
             }
             $consignments = $order->get_booking_consignments();
             foreach ($consignments as $consignment) {
                 $confirmation = $consignment->confirmation;
                 $consignment_number = $confirmation->consignmentNumber;
                 $file_path = Bring_Booking_Labels::get_file_path($order->order->id, $consignment_number);
                 if (file_exists($file_path)) {
                     $files_to_merge[] = Bring_Booking_Labels::get_file_path($order->order->id, $consignment_number);
                 }
             }
         }
         include_once FRAKTGUIDEN_PLUGIN_PATH . '/vendor/myokyawhtun/pdfmerger/PDFMerger.php';
         $merger = new PDFMerger();
         foreach ($files_to_merge as $file) {
             $merger->addPDF($file);
         }
         $merge_result_file = Bring_Booking_Labels::get_local_dir() . '/labels-merged.pdf';
         $merger->merge('file', $merge_result_file);
         header("Content-Length: " . filesize($merge_result_file));
         header("Content-type: application/pdf");
         header("Content-disposition: inline; filename=" . basename($merge_result_file));
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         // Workaround for Chrome's inline pdf viewer
         ob_clean();
         flush();
         readfile($merge_result_file);
         exit;
     });
 }