<?php 
    ini_set('display_errors',0);
    if(!isset($_GET["id"]) || empty($_GET["id"])){
        header("Location: /admin/orders/list");
        exit();
    }
    $order_details       = $order->getOrder($_GET['id']);
    $order_items         = $order->getOrderItems($order_details['id']);
    if(empty($order_details)) {
        header("Location: /admin/orders/list");
        exit();
    }
    $shipping_agency    = $order->getShippingAgency($order_details['shipping_agency_id']);
    $data = array();

    $barcode = new \Com\Tecnick\Barcode\Barcode();

    $bobj = $barcode->getBarcodeObj("C128", $order_details['tracking_code'], -3, -30, 'black', array(0, 0, 0, 0));
?>
<html>
    <head>
        <title><?php echo $order_details['order_id']; ?> Teslimat Bilgileri</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <style>
            *{
                font-family: "Arial" !important;
                font-size: 13px;
                -webkit-print-color-adjust: exact;
                margin: 0;
                padding: 0;
                line-height: 1.5;
            }
            *, ::after, ::before {
                box-sizing: border-box;
            }
            table{
                border-collapse: separate;
                border-spacing: 0;
                width: 100%;
                margin-bottom: 1rem;
                background-color: transparent;
                border: 1px solid #777777;
                margin: 10px 0;
            }
            table > thead {
                background-color: rgba(0, 0, 0, 0.05);
            }
            table > thead > tr > th, table > thead > tr > td {
                border-bottom: 1px solid #777777;
                border-top: 0;
                border-right-width: 0;
                color: #777777;
            }
            table > thead > tr > th:first-child, table > thead > tr > td:first-child {
                border-left-width: 0;
            }
            table > tbody > tr:last-child > th, table > tbody > tr:last-child > td {
                border-bottom-width: 0;
            }
            table thead > tr > th, table tfoot > tr > th {
                border-top: 0;
                font-weight: 700;
                font-size: 12px;
                color: #333;
                letter-spacing: 0.5px;
            }
            table th, table td {
                border-right-width: 0;
                border-top-width: 0;
                padding: 10px;
                vertical-align: middle;
                border: 1px solid #777777;
                color: #333;
            }
            table > tbody > tr > th, table > tbody > tr > td {
                border-right-width: 0;
                border-top-width: 0;
                vertical-align: middle;
            }
            table > tbody > tr > th:first-child, table > tbody > tr > td:first-child {
                border-left-width: 0;
            }


            .container {
                width: 100%;
                margin-right: auto;
                margin-left: auto;
            }
            .row {
                display: -ms-flexbox;
                display: flex;
                -ms-flex-wrap: wrap;
                flex-wrap: wrap;
                margin-right: -10px;
                margin-left: -10px;
            }
            .col-6 {
                -ms-flex: 0 0 50%;
                flex: 0 0 50%;
                max-width: 50%;
                position: relative;
                width: 100%;
                padding-right: 15px;
                padding-left: 15px;
            }

            /*@media print {
                @page { margin: 0; }
                body { margin: 1.6cm; }
            }*/
        </style>
    </head>
    <body>
        <div style="margin: 10px 0 25px;">
            <img src="<?php echo $config->get('site_url'); ?>public/assets/images/logo.webp" style="max-height: 60px">
        </div>
        <div class="products">
            <table>
                <tbody width="100%">
                    <tr>
                        <td width="50%" style="font-weight: bold; font-size: 14px;">Gönderici Bilgileri</td>
                        <td width="50%" style="font-weight: bold; font-size: 14px;">Alıcı Bilgileri</td>
                    </tr>
                    <tr>
                        <td><?php echo $config->get('company_title'); ?>
                        </td>
                        <td><?php echo $order_details['name']; ?></td>
                    </tr>
                    <tr>
                        <td width="50%" style="font-weight: bold; font-size: 14px;">İletişim / Adres Bilgileri</td>
                        <td width="50%" style="font-weight: bold; font-size: 14px;">İletişim / Adres Bilgileri</td>
                    </tr>
                    <tr>
                        <td>
                            <?php echo $config->get('company_address'); ?><br><br>
                            <span style="font-weight: bold;">Telefon:</span> <?php echo $config->get('company_phone'); ?>
                        </td>
                        <td>
                            <?php echo $order_details['address']. "   ". $order_details['town']. " - ". $order_details['city']; ?><br><br>
                            <span style="font-weight: bold;">Telefon:</span> <?php echo $order_details['phone']; ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span style="font-weight: bold;">Paket İçeriği</span>
                        </td>
                        <td>
                            <?php foreach ($order_items as $item): ?>
                                <?php echo $item["quantity"] . " x " . $item["product_title"]; ?><br>
                            <?php endforeach; ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span style="font-weight: bold; font">Kargo Firması</span>: <?php echo $shipping_agency['title']; ?><br>
                            <span style="font-weight: bold; font">Kargo Takip No</span>: <?php echo $order_details['tracking_code']; ?>
                        </td>
                        <td>
                            <p style="font-family:monospace;"><?php echo $bobj->getHtmlDiv(); ?></p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <script>
            window.onafterprint = window.close;
            window.print();
        </script>
    </body>
</html>