                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                der has %d items, but Czech Post allows at most 20 customs declaration rows — only the first 20 items are pre-filled below. Merge items (e.g. by HS code) and adjust the quantities, weights and values so the declaration covers the whole shipment.', TCPSLUG),
                    $tcp_customs_items_total
                ) . '</p>';
            }
            $content .= '<label for="tcp-customs-category">' . __('Category', TCPSLUG) . '</label>';
            $content .= '<select id="tcp-customs-category">';
            foreach ($customs_categories as $cat_code => $cat_label) {
                $content .= '<option value="' . esc_attr($cat_code) . '"' . selected($customs_category, $cat_code, false) . '>' . esc_html($cat_label) . '</option>';
            }
            $content .= '</select>';
            if ($documents_only) {
                $content .= '<p class="description">' . __('Per Universal Postal Union rules (from 1 Jan 2026), international registered and insured letters may contain documents only. To ship goods, use an ordinary letter or a parcel service.', TCPSLUG) . '</p>';
            }
            $content .= '<label for="tcp-customs-note">' . __('Note (required for category "Other (991)")', TCPSLUG) . '</label>';
            $content .= '<input id="tcp-customs-note" type="text" maxlength="100" value="' . esc_attr($customs_note) . '" />';
            // Importer reference number (e.g. Norway VOEC) — some destinations
            // reject the declaration without it (438 MISSING_IMPORTER_ADDRESSEE_
            // REFERENCE). Prefilled from the order override or the global default.
            $customs_importer = $order->get_meta('_tcp_customs_override', true);
            $customs_importer = (is_array($customs_importer) && array_key_exists('importer_ref', $customs_importer))
                ? $customs_importer['importer_ref']
                : tcp_get_customs_importer_ref_for_country($order->get_shipping_country());
            $content .= '<label for="tcp-customs-importer">' . __('Importer reference number (VOEC/IOSS)', TCPSLUG) . '</label>';
            $content .= '<input id="tcp-customs-importer" type="text" maxlength="35" value="' . esc_attr($customs_importer) . '" />';

            // The extra customs service 44 (own export clearance) requires the
            // MRN code of the export declaration — Czech Post rejects the
            // shipment with MISSING_REQUIRED_MRN_CODE without it.
            if (get_option('tcp_customs_service') === '44') {
                $customs_mrn = $order->get_meta('_tcp_customs_override', true);
                $customs_mrn = (is_array($customs_mrn) && !empty($customs_mrn['mrn'])) ? $customs_mrn['mrn'] : '';
                $content .= '<label for="tcp-customs-mrn">' . __('MRN code (export declaration)', TCPSLUG) . '</label>';
                $content .= '<input id="tcp-customs-mrn" type="text" maxlength="18" value="' . esc_attr($customs_mrn) . '" placeholder="15CZ65000021QMDZN0" />';
            }

            // USA and Puerto Rico require a 13-character declaration ID
            // (444 MISSING_DECLARATION_ID without it).
            if (in_array($order->get_shipping_country(), array('US', 'PR'), true)) {
                $customs_declid = $order->get_meta('_tcp_customs_override', true);
                $customs_declid = (is_array($customs_declid) && !empty($customs_declid['declaration_id'])) ? $customs_declid['declaration_id'] : '';
                $content .= '<label for="tcp-customs-declid">' . __('Declaration ID (required for the USA and Puerto Rico, 13 characters)', TCPSLUG) . '</label>';
                $content .= '<input id="tcp-customs-declid" type="text" maxlength="13" value="' . esc_attr($customs_declid) . '" />';
                $content .= '<p class="description">' . __('Obtain the ID for each shipment in the Zonos Prepay application (dashboard.zonosprepay.com) after paying the duties. It is valid for 5 days and single-use. Documents (category 91) and shipments over 2500 USD do not need one.', TCPSLUG) . '</p>';
            }
            // Compact table: fixed column widths and no stretching to the popup
            // width, so the description column can't swallow the free space and
            // every header sits exactly above its input.
            $th = 'text-align:left;padding:4px 10px 2px 0;';
            $td = 'padding:2px 10px 2px 0;';
            $content .= '<table class="tcp-customs-table" style="width:auto;border-collapse:collapse;margin-top:8px;">';
            $content .= '<thead><tr>'
                . '<th style="' . $th . 'width:320px;">' . __('Description', TCPSLUG) . '</th>'
                . '<th style="' . $th . 'width:100px;">' . __('HS code', TCPSLUG) . '</th>'
                . '<th style="' . $th . 'width:60px;">' . __('Qty', TCPSLUG) . '</th>'
                . '<th style="' . $th . 'width:90px;">' . __('Weight/pc (kg)', TCPSLUG) . '</th>'
                // Show the declaration currency — USA/Puerto Rico values are
                // pre-converted to the mandated USD, everything else uses the
                // order currency.
                . '<th style="' . $th . 'width:90px;">' . __('Value/pc', TCPSLUG) . ' ('
                . esc_html(tcp_customs_currency_for_country($order->get_shipping_country()) ?: $order->get_currency())
                . ')</th>'
                . '<th style="' . $th . 'width:50px;">' . __('Origin', TCPSLUG) . '</th>'
                . '</tr></thead><tbody>';
            foreach ($customs_rows as $row) {
                $content .= '<tr class="tcp-customs-row">'
                    . '<td style="' . $td . '"><input class="tcp-cust-desc" type="text" value="' . esc_attr($row['customCont']) . '" style="width:100%;box-sizing:border-box;"></td>'
                    . '<td style="' . $td . '"><input class="tcp-cust-hs" type="text" value="' . esc_attr($row['hsCode']) . '" style="width:100%;box-sizing:border-box;"></td>'
                    . '<td style="' . $td . '"><input class="tcp-cust-qty" type="number" min="1" value="' . esc_attr($row['quantity']) . '" style="width:100%;box-sizing:border-box;"></td>'
                    . '<td style="' . $td . '"><input class="tcp-cust-weight" type="number" step="0.001" min="0" value="' . esc_attr($row['weight']) . '" style="width:100%;box-sizing:border-box;"></td>'
                    . '<td style="' . $td . '"><input class="tcp-cust-val" type="number" step="0.01" min="0" value="' . esc_attr($row['customVal']) . '" style="width:100%;box-sizing:border-box;"></td>'
                    . '<td style="' . $td . '"><input class="tcp-cust-iso" type="text" maxlength="2" value="' . esc_attr($row['iso']) . '" style="width:100%;box-sizing:border-box;"></td>'
                    . '</tr>';
            }
            $content .= '</tbody></table>';
            $content .= '<p class="description">' . __('Fill in HS codes and values where missing. Required for shipments outside the EU.', TCPSLUG) . '</p>';
            $content .= '</div>';
        }


        //
        // ------------- BUTTONS ----------------
        //

        $buttons = [
            [
                'text'  => __('Close', $slug),
                'class' => 'button torlib-popup-btn torlib-popup-close-footer torlib-secondary-button',
                'type'  => 'button'
            ],
            [
                'text'  => __('Continue', $slug),
                'class' => 'button torlib-popup-btn tcp-popup-continue torlib-primary-button',
                'type'  => 'button'
            ],
        ];


        //
        // ------------- FINAL POPUP GENERATION ----------------
        //

        return Draw::add_popup([
            'id'         => 'tcp-popup-send-' . $order_id,
            'title'      => __('Send to Czech Post', $slug),
            'content'    => $content,
            'buttons'    => $buttons,
            'show_close' => true,
            'auto_open'  => true,
            'class'      => $popup_class,
            'return'     => true
        ]);
    }


    static function print_dialog($order_id, $slug, $order_ids, $bulk = false)
    {
        $default_position = get_option('tcp_defalt_position', '1');
        $default_id = get_option('tcp_label_formid', '103');

        if (!empty($order_id)) {
            $order = wc_get_order($order_id);
            $country = $order->get_shipping_country();
            $shipping_method = tcp_get_shipping_method_id($order);

            if ($country == 'CZ') {
                $default_id = get_option(
                    'tcp_formid_' . array_search($shipping_method, TCPSHIPPINGS_METHODS) . '_cz_enabled',
                    $default_id
                );
            } else {
                $default_id = get_option(
                    'tcp_formid_' . array_search($shipping_method, TCPSHIPPINGS_METHODS) . '_int_enabled',
                    $default_id
                );
            }
        }

        //
        // ------------- POPUP CONTENT ----------------
        //

        $content = '<div class="torlib-popup-field-group">';
        $content .= '<label for="tcp_label_position">' . __('Position:', TCPSLUG) . '</label>';
        $content .= '<input type="number" min="1" max="4" id="tcp_label_position" value="' . $default_position . '" />';
        $content .= '</div>';

        $content .= '<div class="torlib-popup-field-group">';
        $content .= '<label for="tcp_formid">' . __('Form ID:', TCPSLUG) . '</label>';
        $content .= '<input type="number" id="tcp_formid" value="' . $default_id . '" />';
        $content .= '</div>';

        // hidden inputs
        $content .= '<input type="hidden" id="is_bulk" value="' . $bulk . '">';
        $content .= '<input type="hidden" id="order_ids" value="' . implode(',', $order_ids) . '">';
        $content .= '<input type="hidden" id="order_id" value="' . $order_id . '">';


        //
        // ------------- BUTTONS ----------------
        //

        $buttons = [
            [
                'text'  => __('Close', $slug),
                'class' => 'button torlib-popup-btn torlib-popup-close-footer torlib-secondary-button',
                'type'  => 'button'
            ],
            [
                'text'  => __('Continue', $slug),
                'class' => 'button torlib-popup-btn tcp-popup-print torlib-primary-button',
                'type'  => 'button'
            ],
        ];

        //
        // ------------- FINAL POPUP GENERATION ----------------
        //

        return Draw::add_popup([
            'id'         => 'tcp-popup-print-' . $order_id,
            'title'      => __('Print label', $slug),
            'content'    => $content,
            'buttons'    => $buttons,
            'show_close' => true,
            'auto_open'  => true,
            'class'      => 'popup-small',
            'return'     => true
        ]);
    }


}<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://veronikamartinkova.cz/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-posts-al_product-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-posts-product-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-posts-wpm-testimonial-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-taxonomies-product_cat-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-taxonomies-wpm-testimonial-category-1.xml</loc></sitemap><sitemap><loc>https://veronikamartinkova.cz/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
