// src/stores/downloadstpdfStore.js import { defineStore } from 'pinia' import { download, extractApiErrorDetail } from 'src/services/api' export const useDownloadstpdfStore = defineStore('downloadstpdf', { actions: { /* ========================================================== 📄 PDF İNDİR / AÇ ========================================================== */ async downloadPDF(accountCode, startDate, endDate, parislemler = []) { try { // 🔹 Query params const params = { accountcode: accountCode, startdate: startDate, enddate: endDate } if (Array.isArray(parislemler) && parislemler.length > 0) { params.parislemler = parislemler.filter( p => p !== undefined && p !== null && p !== '' ) } // 🔥 MERKEZİ API — BLOB const blob = await download('/export-pdf', params) // 🔹 Blob → URL const pdfUrl = window.URL.createObjectURL( new Blob([blob], { type: 'application/pdf' }) ) // 🔹 Yeni sekmede aç window.open(pdfUrl, '_blank') console.log('✅ PDF yeni sekmede açıldı') return { ok: true, message: '📄 PDF hazırlandı' } } catch (err) { const detail = await extractApiErrorDetail(err) const status = err?.status || err?.response?.status || '-' console.error(`? PDF a�ma hatas� [${status}] /export-pdf: ${detail}`) return { ok: false, message: detail || 'PDF al�namad�' } } } } })