<?php

use UkrSolution\BarcodeScanner\API\classes\Users;
use UkrSolution\BarcodeScanner\features\settings\Settings;

$settings = new Settings();


$usbs = $jsData && isset($jsData['usbs']) ? $jsData['usbs'] : array();
$usbsCustomCss = $jsData && isset($jsData['usbsCustomCss']) ? $jsData['usbsCustomCss'] : array();
$usbsHistory = $jsData && isset($jsData['usbsHistory']) ? $jsData['usbsHistory'] : array();
$usbsUserCF = $jsData && isset($jsData['usbsUserCF']) ? $jsData['usbsUserCF'] : array();
$usbsOrderCF = $jsData && isset($jsData['usbsOrderCF']) ? $jsData['usbsOrderCF'] : array();
$usbsWooShippmentProviders = $jsData && isset($jsData['usbsWooShippmentProviders']) ? $jsData['usbsWooShippmentProviders'] : array();
$usbsLangs = $jsData && isset($jsData['usbsLangs']) ? $jsData['usbsLangs'] : array();
$usbsInterface = $jsData && isset($jsData['usbsInterface']) ? $jsData['usbsInterface'] : array();
$cartExtraData = $jsData && isset($jsData['cartExtraData']) ? $jsData['cartExtraData'] : array();
$usbsOrdersListFilter = $jsData && isset($jsData['usbsOrdersListFilter']) ? $jsData['usbsOrdersListFilter'] : array();

$userId = $usbs && isset($usbs['userId']) ? $usbs['userId'] : "";
$userRole = $userId ? Users::getUserRole($userId) : '';
?>
<title>Barcode Scanner</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<a href="#?p=barcode-scanner-frontend" data-plugin="barcode-scanner-frontend" id="barcode-scanner-auto-show" style="display:none;">Barcode scanner</a>
<link href="<?php echo esc_url(USBS_PLUGIN_BASE_URL); ?>/assets/css/style.css" />

<!-- label printing integration - HTML -->
<?php echo $printingInitHTML; ?>

<!-- label printing integration - DOM data -->
<?php if ($printingDOMData) : ?>
    <?php foreach ($printingDOMData as $key => $value) : ?>
        <script>
            window.<?php echo $key; ?> = <?php echo json_encode($value); ?>;
        </script>
    <?php endforeach; ?>
<?php endif; ?>

<!-- label printing integration - scrips -->
<?php if ($printingScripts) : ?>
    <?php $jQuery_url = includes_url('/js/jquery/jquery.js'); ?>
    <script src="<?php echo esc_url($jQuery_url); ?>"></script>

    <?php foreach ($printingScripts as $value) : ?>
        <?php
        $fileInfo = pathinfo($value);
        $extension = isset($fileInfo['extension']) ? strtolower($fileInfo['extension']) : '';
        ?>
        <?php if ($extension == "js") : ?>
            <script src="<?php echo esc_url($value); ?>"></script>
        <?php elseif ($extension == "css") : ?>
            <link rel="stylesheet" href="<?php echo esc_url($value); ?>">
        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>

<!-- barcode scanner scripts -->
<script>
    window.BarcodeScannerFront = true;
    window.BarcodeScannerAutoShow = true;
    window.BarcodeScannerDisableClose = true;
    window.BarcodeScannerDisableResize = true;
</script>
<script>
    window.usbsAccessDenied = <?php echo $accessDenied ? 1 : 0; ?>;
</script>
<script>
    window.usbsLangs = <?php echo json_encode($usbsLangs); ?>;
</script>
<script>
    window.usbsInterface = <?php echo json_encode(apply_filters("scanner_product_fields_filter", $usbsInterface)); ?>;
</script>
<script>
    window.usbs = <?php echo json_encode($usbs); ?>;
</script>
<script>
    window.usbsCustomCss = <?php echo json_encode($usbsCustomCss); ?>;
</script>
<script>
    window.usbsHistory = <?php echo json_encode($usbsHistory); ?>;
</script>
<script>
    window.usbsUserCF = <?php echo json_encode($usbsUserCF); ?>;
</script>
<script>
    window.usbsOrderCF = <?php echo json_encode($usbsOrderCF); ?>;
</script>
<script>
    window.usbsWooShippmentProviders = <?php echo json_encode($usbsWooShippmentProviders); ?>;
</script>
<script>
    window.cartExtraData = <?php echo json_encode($cartExtraData); ?>;
</script>
<script>
    window.usbsOrdersListFilter = <?php echo json_encode($usbsOrdersListFilter); ?>;
</script>
<script src="<?php echo esc_url(home_url()); ?>/wp-includes/js/jquery/jquery.min.js"></script>
<script src="<?php echo esc_url(home_url()); ?>/wp-includes/js/jquery/jquery-migrate.min.js"></script>

<?php
if (function_exists('BSPrintLabelJsHook')) {
    BSPrintLabelJsHook();
} 

if (function_exists('BSFrontendJsHook')) {
    BSFrontendJsHook();
} 

if (function_exists('wp_enqueue_media')) wp_enqueue_media();
if (function_exists('wp_enqueue_style')) {
    wp_enqueue_style('dashicons');
    wp_enqueue_style('common');
    wp_enqueue_style('forms');
    wp_enqueue_style('buttons');
    wp_enqueue_style('media');
    wp_enqueue_style('media-views');
    wp_enqueue_style('wp-pointer');
}
if (function_exists('wp_print_styles')) wp_print_styles();
if (function_exists('wp_print_media_templates')) wp_print_media_templates();
if (function_exists('wp_print_scripts')) wp_print_scripts();

?>

<script src="<?php echo esc_url($path); ?>assets/js/index-business-1.12.0-1776150596682.js"></script>

<?php
