<table align="center" style="border-spacing: {{$barcode_details->col_distance * 1}}in {{$barcode_details->row_distance * 1}}in; overflow: hidden !important;">
  @foreach($page_products as $page_product)  
    @if($loop->index % $barcode_details->stickers_in_one_row == 0)
      <!-- create a new row -->
      <tr>
      <!-- <columns column-count="{{$barcode_details->stickers_in_one_row}}" column-gap="{{$barcode_details->col_distance*1}}"> -->
    @endif
      <td align="center" valign="center">
        <div style="overflow: hidden !important;display: flex; flex-wrap: wrap;align-content: center;width: {{$barcode_details->width * 1}}in; height: {{$barcode_details->height * 1}}in; justify-content: center; margin: 0px 10px 0px 10px;">
        <!--  -->
          <div style="">
            {{-- Price --}}
            @if(!empty($print['price']))
            <span style="font-size: {{$print['price_size']}}px; float: right; margin-top: 10px; padding-right: 10px;">
              {{-- @lang('lang_v1.price') --}}
              <b>{{session('currency')['symbol'] ?? ''}}
                {{@num_format((float) filter_var($page_product->product_price, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION))}}
              </b>
            </span>
            @endif
            {{-- Business Name --}}
            @if(!empty($print['business_name']))
              <b style="display: block !important; font-size: {{$print['business_name_size']}}px">{{$business_name}}</b>
            @endif
                        
            @if(!empty($print['exp_date']) && !empty($page_product->exp_date))
              <br>
              <span style="font-size: {{$print['exp_date_size']}}px">
                <b>@lang('product.exp_date'):</b>
                {{$page_product->exp_date}}
              </span>
              @if($barcode_details->is_continuous)
              <br>
              @endif
            @endif
  
            @if(!empty($print['packing_date']) && !empty($page_product->packing_date))
              <span style="font-size: {{$print['packing_date_size']}}px">
                <b>@lang('lang_v1.packing_date'):</b>
                {{$page_product->packing_date}}
              </span>
            @endif
            <br><br>
            
            {{-- Product Name --}}
            @if(!empty($print['name']))
          {{-- @if(strlen($page_product->product_title) > 25)
                @php
                  $words = explode(' ', $page_product->product_title);
                  if(strlen($page_product->product_title) > 25) {
                    $words_show = implode(' ', array_slice($words, 0, 3));
                  } else {
                    $words_show = implode(' ', array_slice($words, 0, 4));
                  }
                @endphp
                {{ $words_show }}
              @else
                {{$page_product->product_title}}
              @endif --}}

              @php
                $max_chars = 25; // Adjust based on your box/font size

                // Clean up the title if needed
                $title = $page_product->product_title;

                if (strlen($title) <= $max_chars) {
                    $words_show = $title;
                } else {
                  $words = explode(' ', $title);
                  $words_show = '';
                  $current_length = 0;

                  foreach ($words as $word) {
                      if (($current_length + strlen($word) + 1) > $max_chars) break;
                      $words_show .= $word . ' ';
                      $current_length += strlen($word) + 1; // +1 for space
                  }

                  $words_show = trim($words_show);
                }

              @endphp
              <span style="display: block !important; font-size: {{$print['name_size']}}px; max-width:81% !important;margin-left : 5% !important; white-space: nowrap; margin-top: 5px; float: left; padding-left: 25px;">{{ $words_show }}@if(!empty($print['lot_number']) && !empty($page_product->lot_number))
                  <span style="font-size: {{12*$factor}}px">
                      ({{$page_product->lot_number}})
                  </span>
                @endif
              </span>
            @endif            
  
            {{-- Barcode --}}
            <!-- should be: barcode_details->height*0.24 -->
            <!-- <img style="max-width:80% !important;height: {{$barcode_details->height*0.30}}in !important; width: {{$barcode_details->width*0.80}}in !important; display: block; float: right; padding-right: 10px;" src="data:image/png;base64,{{DNS1D::getBarcodePNG(substr($page_product->SellerSku ? $page_product->SellerSku : $page_product->seller_sku, 0, 13), $page_product->barcode_type, 2,30, array(0, 0, 0), false)}}"> -->
            <img style="max-width:80% !important;height: {{$barcode_details->height*0.30}}in !important; width: {{$barcode_details->width*0.80}}in !important; display: block; float: right; padding-right: 10px;" src="data:image/png;base64,{{DNS1D::getBarcodePNG(
              substr(
                $page_product->SellerSku ?: $page_product->seller_sku,-13),
                $page_product->barcode_type,
                2,
                30,
                [0, 0, 0],
                false
              )}}">
            {{-- Category Code --}}
            <span style="font-size: 14px !important; margin-top: 5px; float: left;">
              {{-- $page_product->SellerSku --}}
              {{ $page_product->category_code }}
            </span>
          </div>
        </div>
      
      </td>
  
    @if($loop->iteration % $barcode_details->stickers_in_one_row == 0)
      </tr>
    @endif
  @endforeach
  </table>
  
  <style type="text/css">
    body {
      font-family: arial;
    }

    td{
      border: 0px dotted lightgray;
    }
    @media print{
      body {
        font-family: arial;
      } 
      /* table{
        page-break-after: always;
      } */
  
      
      @page {
      size: {{$paper_width}}in {{$paper_height}}in;
  
      width: {{$barcode_details->paper_width}}in !important;
      height:@if($barcode_details->paper_height != 0){{$barcode_details->paper_height}}in !important @else auto @endif;
      margin-top: {{$margin_top}}in !important;
      margin-bottom: {{($margin_top)}}in !important;
      margin-left: {{$margin_left}}in !important;
      margin-right: {{$margin_left}}in !important;
      }
    }
  </style>