<div>
    <style>
        @media print {
            nav, footer { display: none !important; }
            main, .max-w-7xl { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
            .no-print { display: none !important; }
            body { background: white !important; }
            * {
                -webkit-print-color-adjust: exact !important;
                color-adjust: exact !important;
                print-color-adjust: exact !important;
            }
        }
    </style>

    <script src="https://cdn.jsdelivr.net/npm/xlsx-js-style@1.2.0/dist/xlsx.min.js"></script>

    <!-- Toolbar (No Print) -->
    <div class="no-print flex flex-col md:flex-row justify-between items-center bg-white p-4 rounded-2xl shadow-sm border border-slate-100 mb-6 gap-4">
        <div>
            <h1 class="text-xl font-black text-slate-800">بيان الحسابات</h1>
            <p class="text-xs text-slate-500 mt-1">كشف تفصيلي ببيانات الحسابات المالية</p>
        </div>

        <div class="flex items-center gap-3 flex-wrap">
            
            <!-- Party Filter -->
            <div class="w-full md:w-64" x-data="{
                open: false,
                search: '',
                selected: <?php if ((object) ('party_id') instanceof \Livewire\WireDirective) : ?>window.Livewire.find('<?php echo e($__livewire->getId()); ?>').entangle('<?php echo e('party_id'->value()); ?>')<?php echo e('party_id'->hasModifier('live') ? '.live' : ''); ?><?php else : ?>window.Livewire.find('<?php echo e($__livewire->getId()); ?>').entangle('<?php echo e('party_id'); ?>')<?php endif; ?>.live,
                options: <?php echo e(Js::from($parties->map(fn($p) => ['id' => $p->id, 'name' => $p->name]))); ?>,
                get filteredOptions() {
                    return this.search === '' ? this.options : this.options.filter(o => o.name.includes(this.search));
                },
                get selectedName() {
                    let opt = this.options.find(o => o.id == this.selected);
                    return opt ? opt.name : 'جميع الأطراف';
                }
            }" @click.away="open = false">
                <div class="relative">
                    <button @click="open = !open" type="button" class="w-full text-right bg-white border border-slate-200 rounded-xl px-4 py-2.5 text-sm focus:ring-indigo-500 focus:border-indigo-500 shadow-sm flex items-center justify-between">
                        <span x-text="selectedName" class="font-bold text-slate-700 truncate block"></span>
                        <svg class="w-4 h-4 text-slate-400 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                    </button>
                    <div x-show="open" x-cloak class="absolute z-50 w-full mt-1 bg-white border border-slate-200 rounded-xl shadow-xl overflow-hidden" style="display: none;">
                        <div class="p-2 border-b border-slate-100 bg-slate-50">
                            <input type="text" x-model="search" placeholder="ابحث عن طرف..." class="w-full border-slate-200 rounded-lg text-sm py-1.5 px-3 focus:ring-indigo-500 focus:border-indigo-500">
                        </div>
                        <ul class="max-h-48 overflow-y-auto py-1">
                            <li @click="selected = ''; open = false; search = ''" 
                                class="px-4 py-2 text-sm cursor-pointer hover:bg-slate-50 transition-colors"
                                :class="selected == '' ? 'bg-indigo-50 text-indigo-700 font-bold' : 'text-slate-700'">
                                جميع الأطراف
                            </li>
                            <template x-for="option in filteredOptions" :key="option.id">
                                <li @click="selected = option.id; open = false; search = ''" 
                                    class="px-4 py-2 text-sm cursor-pointer hover:bg-slate-50 transition-colors"
                                    :class="selected == option.id ? 'bg-indigo-50 text-indigo-700 font-bold' : 'text-slate-700'">
                                    <span x-text="option.name"></span>
                                </li>
                            </template>
                        </ul>
                    </div>
                </div>
                <input type="hidden" id="party_id_filter" :value="selected">
            </div>

            <!-- Columns Dropdown -->
            <div class="relative" x-data="{ open: false }" @click.away="open = false">
                <button @click="open = !open" class="bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-xl shadow-sm font-bold text-sm flex items-center gap-2 transition">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2M9 7a2 2 0 012-2h2a2 2 0 012 2m0 10V7m0 10a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 00-2-2h-2a2 2 0 00-2 2"></path></svg>
                    الأعمدة
                    <svg class="w-3 h-3 transition-transform" :class="{'rotate-180': open}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
                </button>
                <div x-show="open" x-transition class="absolute right-0 mt-2 w-56 bg-white rounded-xl shadow-lg border border-slate-100 p-2 z-50 text-sm" style="display: none;">
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="party" wire:click="toggleColumn('party')" <?php if($columns['party']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">الطرف</span>
                    </label>
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="currency" wire:click="toggleColumn('currency')" <?php if($columns['currency']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">العملة</span>
                    </label>
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="account_number" wire:click="toggleColumn('account_number')" <?php if($columns['account_number']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">رقم الحساب</span>
                    </label>
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="name" wire:click="toggleColumn('name')" <?php if($columns['name']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">الاسم</span>
                    </label>
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="notes" wire:click="toggleColumn('notes')" <?php if($columns['notes']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">الملاحظات</span>
                    </label>
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="is_active" wire:click="toggleColumn('is_active')" <?php if($columns['is_active']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">الحالة</span>
                    </label>
                    <label class="flex items-center gap-2 p-2 hover:bg-slate-50 rounded cursor-pointer">
                        <input type="checkbox" data-column="created_at" wire:click="toggleColumn('created_at')" <?php if($columns['created_at']): ?> checked <?php endif; ?> class="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500">
                        <span class="font-bold text-slate-700">تاريخ الإضافة</span>
                    </label>
                </div>
            </div>

            <!-- Print Button -->
            <button onclick="openPrint()" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl shadow-sm font-bold text-sm flex items-center gap-2 transition">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z"></path></svg>
                طباعة
            </button>

            <!-- Excel Export Button -->
            <button onclick="exportExcel()" class="bg-emerald-600 hover:bg-emerald-500 text-white px-4 py-2 rounded-xl shadow-sm font-bold text-sm flex items-center gap-2 transition">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                تصدير
            </button>
        </div>
    </div>

    <!-- Table Container -->
    <div class="bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-sm text-right">
                <thead class="bg-indigo-50 text-indigo-900 border-b-2 border-indigo-100">
                    <tr>
                        <th class="px-4 py-3 font-bold w-12 text-center">#</th>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['party']): ?> <th class="px-4 py-3 font-bold">الطرف</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['currency']): ?> <th class="px-4 py-3 font-bold">العملة</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['account_number']): ?> <th class="px-4 py-3 font-bold">رقم الحساب</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['name']): ?> <th class="px-4 py-3 font-bold">الاسم</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['notes']): ?> <th class="px-4 py-3 font-bold">الملاحظات</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['is_active']): ?> <th class="px-4 py-3 font-bold text-center">الحالة</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['created_at']): ?> <th class="px-4 py-3 font-bold">تاريخ الإضافة</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                    <tr class="hover:bg-slate-50 transition-colors">
                        <td class="px-4 py-3 text-center text-slate-500 font-bold"><?php echo e($index + 1); ?></td>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['party']): ?> <td class="px-4 py-3 text-slate-800"><?php echo e($account->party->name ?? '-'); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['currency']): ?> <td class="px-4 py-3 text-slate-800"><?php echo e($account->currency->name ?? '-'); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['account_number']): ?> <td class="px-4 py-3 font-bold text-indigo-700" dir="ltr"><?php echo e($account->account_number); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['name']): ?> <td class="px-4 py-3 font-bold text-slate-800"><?php echo e($account->name); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['notes']): ?> <td class="px-4 py-3 text-slate-600"><?php echo e($account->notes ?: '-'); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['is_active']): ?>
                        <td class="px-4 py-3 text-center">
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($account->is_active): ?>
                                <span class="bg-emerald-100 text-emerald-700 px-2 py-0.5 rounded text-xs font-bold print:bg-transparent print:text-emerald-700">نشط</span>
                            <?php else: ?>
                                <span class="bg-red-100 text-red-700 px-2 py-0.5 rounded text-xs font-bold print:bg-transparent print:text-red-700">غير نشط</span>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </td>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($columns['created_at']): ?> <td class="px-4 py-3 text-slate-500 text-xs" dir="ltr"><?php echo e($account->created_at->format('Y-m-d')); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </tr>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                    <tr>
                        <td colspan="20" class="px-4 py-8 text-center text-slate-500 font-bold">لا يوجد حسابات مسجلة بعد.</td>
                    </tr>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Data Island for JS Export -->
    <script id="accounts-data" type="application/json">
        <?php echo json_encode($accounts); ?>

    </script>

    <!-- JavaScript Functions -->
    <script>
        function getActiveColumns() {
            var cols = {};
            document.querySelectorAll('input[data-column]').forEach(function(checkbox) {
                cols[checkbox.getAttribute('data-column')] = checkbox.checked;
            });
            return cols;
        }

        function openPrint() {
            var colsState = getActiveColumns();
            var query = [];
            
            // Add Filters
            var partyId = document.getElementById('party_id_filter').value;
            if(partyId) {
                query.push('party_id=' + partyId);
            }

            // Add Columns
            for (var key in colsState) {
                if (colsState[key]) {
                    query.push('columns[' + key + ']=1');
                }
            }
            var url = "<?php echo e(route('reports.accounts.print')); ?>?" + query.join('&');
            window.open(url, '_blank');
        }

        function exportExcel() {
            var data = [];
            var r = 0;
            
            var titleStyle = { font: { bold: true, sz: 16, color: { rgb: "FFFFFF" } }, fill: { fgColor: { rgb: "312e81" } }, alignment: { horizontal: "center", vertical: "center" } };
            var tableHeaderStyle = { font: { bold: true, color: { rgb: "FFFFFF" } }, fill: { fgColor: { rgb: "4f46e5" } }, alignment: { horizontal: "center", vertical: "center" } };
            var centerStyle = { alignment: { horizontal: "center", vertical: "center" } };
            var boldCenter = { font: { bold: true }, alignment: { horizontal: "center", vertical: "center" } };

            var colsState = getActiveColumns();
            var accounts = JSON.parse(document.getElementById('accounts-data').textContent || '[]');
            
            var activeColsCount = 1;
            for(var key in colsState) { if(colsState[key]) activeColsCount++; }

            var partyId = document.getElementById('party_id_filter').value;
            var partyName = document.querySelector('div[x-data*="party_id"]')?.querySelector('span[x-text="selectedName"]')?.innerText || '';
            if(partyName === 'جميع الأطراف') partyName = '';

            var reportTitle = "بيان الحسابات";
            if(partyName) reportTitle += " - الطرف: " + partyName;

            data.push([{ v: reportTitle, s: titleStyle }]);
            var mergeCells = [{ s: { r: r, c: 0 }, e: { r: r, c: activeColsCount - 1 } }]; 
            r++;

            data.push([]); r++; 

            var colHeaders = [{ v: "#", s: tableHeaderStyle }];
            if(colsState['party']) colHeaders.push({ v: "الطرف", s: tableHeaderStyle });
            if(colsState['currency']) colHeaders.push({ v: "العملة", s: tableHeaderStyle });
            if(colsState['account_number']) colHeaders.push({ v: "رقم الحساب", s: tableHeaderStyle });
            if(colsState['name']) colHeaders.push({ v: "الاسم", s: tableHeaderStyle });
            if(colsState['notes']) colHeaders.push({ v: "الملاحظات", s: tableHeaderStyle });
            if(colsState['is_active']) colHeaders.push({ v: "الحالة", s: tableHeaderStyle });
            if(colsState['created_at']) colHeaders.push({ v: "تاريخ الإضافة", s: tableHeaderStyle });
            
            data.push(colHeaders); r++;

            accounts.forEach(function(account, index) {
                var row = [{ v: index + 1, s: boldCenter }];
                
                var partyNameValue = account.party ? account.party.name : '-';
                var currencyNameValue = account.currency ? account.currency.name : '-';

                if(colsState['party']) row.push({ v: partyNameValue, s: boldCenter });
                if(colsState['currency']) row.push({ v: currencyNameValue, s: centerStyle });
                if(colsState['account_number']) row.push({ v: account.account_number || '-', s: centerStyle });
                if(colsState['name']) row.push({ v: account.name || '-', s: boldCenter });
                if(colsState['notes']) row.push({ v: account.notes || '-', s: centerStyle });
                if(colsState['is_active']) {
                    var status = account.is_active ? 'نشط' : 'غير نشط';
                    row.push({ v: status, s: { font: { bold: true, color: { rgb: account.is_active ? "15803d" : "b91c1c" } }, alignment: { horizontal: "center", vertical: "center" } } });
                }
                if(colsState['created_at']) {
                    var formattedDate = account.created_at;
                    if(formattedDate && formattedDate.includes('T')) {
                        formattedDate = formattedDate.split('T')[0];
                    }
                    row.push({ v: formattedDate || '-', s: centerStyle });
                }
                
                data.push(row); r++;
            });

            var ws = XLSX.utils.aoa_to_sheet(data);
            ws['!dir'] = 'rtl';
            ws['!merges'] = mergeCells;
            
            var colWidths = [{ wpx: 40 }];
            if(colsState['party']) colWidths.push({ wpx: 200 });
            if(colsState['currency']) colWidths.push({ wpx: 120 });
            if(colsState['account_number']) colWidths.push({ wpx: 150 });
            if(colsState['name']) colWidths.push({ wpx: 200 });
            if(colsState['notes']) colWidths.push({ wpx: 250 });
            if(colsState['is_active']) colWidths.push({ wpx: 80 });
            if(colsState['created_at']) colWidths.push({ wpx: 100 });
            
            ws['!cols'] = colWidths;

            var wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, "بيان الحسابات");
            
            var today = new Date().toISOString().split('T')[0];
            XLSX.writeFile(wb, "بيان_الحسابات_" + today + ".xlsx");
        }
    </script>
</div>
<?php /**PATH D:\laragon\www\Ledger\resources\views/livewire/reports/accounts-report.blade.php ENDPATH**/ ?>