<x-app-layout>
<div class="row">
    <div class="col-xl-12"></div>
    <div class="mt-4 bg-gray">
        <div class="row">
            <div class="col-xl-12 col-lg-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                        <h3 class="m-0 font-weight-bold text-primary">Lista de Ordenes</h3>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped table-sm" id="dataTable" width="100%" cellspacing="0">
                                <thead>
                                    <tr>
                                        <th>N° Orden</th>
                                        <th>Nombre Comercial</th>
                                        <th>Cliente</th>
                                        <th>Tipo venta</th>
                                        <th>Estatus</th>
                                        <th>Acciones</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($ordenes as $orden)
                                        <tr>
                                            <td>{{ 'OC_' . $orden->id_vendedor . '_' . $orden->id_orden }}</td>
                                            <td>{{ $orden->nombre_comercial }}</td>
                                            <td>{{ $orden->dueno }}</td>
                                            <td>{{ $orden->tipo_venta }}</td>
                                            <td>{!! $orden->estado !!}</td>
                                            <td>
                                                <div class="dropdown">
                                                    <button class="btn btn-dark dropdown-toggle" type="button" id="{{'OC' . $orden->id_orden}}" data-bs-toggle="dropdown"
                                                        data-bs-container="body" aria-expanded="false">
                                                        opciones
                                                    </button>
                                                    <ul class="dropdown-menu" aria-labelledby="{{'OC' . $orden->id_orden}}">
                                                        {{-- <li><a class="dropdown-item" href="#">Ver detalles</a></li> --}}
                                                        <li><a class="dropdown-item" href="javascript:void(0);" onclick="openPDF('{{ $orden->id_orden }}')">
                                                            <i class="align-middle me-1" data-feather="printer"></i>
                                                            Generar PDF</a></li>
                                                    </ul>
                                                </div>

                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    <script>

        function openPDF(id_orden) {
            let api_pdf = `{{ route('proformas.generarPDF', ':id_orden') }}`;
            api_pdf = api_pdf.replace(':id_orden', id_orden);
            let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=0,height=0,left=-500,top=-500`;
            var newWindow = open(api_pdf, 'PDF', params);
            setTimeout(function () {
                newWindow.close();
            }, 5000);
        }
    </script>
<script type="module" src="{{asset("/js/custom/orden_compra_lista.js")}}"></script>
</x-app-layout>
