import { LaporanNeracaProps } from "@/pages/laporan/akuntansi/neraca";
import { LaporanAnggotaProps } from "@/pages/laporan/anggota/nominatif_anggota";
import { LaporanDepositoProps } from "@/pages/laporan/deposito/nominatif_deposito";
import { LaporanTabunganProps } from "@/pages/laporan/tabungan/nominatif_tabungan";
import { LaporanBukuBesarProps } from '../pages/laporan/akuntansi/buku_besar';

export const getLaporanTransaksiRincian = async (filter, token : string) => {
    const params = new URLSearchParams();
    if (filter.tgl_awal) params.append('tgl_awal', filter.tgl_awal);
    if (filter.tgl_akhir) params.append('tgl_akhir', filter.tgl_akhir);
    if (filter.jenis_transaksi) params.append('jenis_transaksi', filter.jenis_transaksi);

    return await fetch(`/api/laporan/transaksi-rincian?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getLaporanTransaksiRekap = async (filter, token : string) => {
    const params = new URLSearchParams();
    if (filter.tgl_awal) params.append('tgl_awal', filter.tgl_awal);
    if (filter.tgl_akhir) params.append('tgl_akhir', filter.tgl_akhir);

    return await fetch(`/api/laporan/transaksi-rekap?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getLaporanNominatifAnggota = async (filter : LaporanAnggotaProps, token : string) => {
    const params = new URLSearchParams();
    if (filter.status) params.append('status', filter.status.toString());
    if (filter.jenis_kelamin) params.append('jenis_kelamin', filter.jenis_kelamin);
    if (filter.kelurahan) params.append('kelurahan', filter.kelurahan);
    if (filter.kecamatan) params.append('kecamatan', filter.kecamatan);
    if (filter.kabupaten) params.append('kabupaten', filter.kabupaten);
    if (filter.status_marital) params.append('status_marital', filter.status_marital);
    if (filter.agama) params.append('agama', filter.agama);

    return await fetch(`/api/laporan/nominatif-anggota?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getLaporanNominatifTabungan = async (filter : LaporanTabunganProps, token : string) => {
    const params = new URLSearchParams();
    if (filter.status) params.append('status', filter.status.toString());
    if (filter.produk) params.append('produk', filter.produk);

    return await fetch(`/api/laporan/nominatif-tabungan?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getLaporanNominatifDeposito = async (filter : LaporanDepositoProps, token : string) => {
    const params = new URLSearchParams();
    if (filter.status) params.append('status', filter.status.toString());
    if (filter.produk) params.append('produk', filter.produk);

    return await fetch(`/api/laporan/nominatif-deposito?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getLaporanNeraca = async (filter : LaporanNeracaProps, token : string) => {
    const params = new URLSearchParams();
    if (filter.tanggal) params.append('tanggal', filter.tanggal);

    return await fetch(`/api/laporan/neraca?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getLaporanLabaRugi = async (filter : LaporanNeracaProps, token : string) => {
    const params = new URLSearchParams();
    if (filter.tanggal) params.append('tanggal', filter.tanggal);

    return await fetch(`/api/laporan/laba-rugi?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}

export const getBukuBesar = async (filter : LaporanBukuBesarProps, token : string) => {
    const params = new URLSearchParams();
    if (filter.kode_akun) params.append('kode_akun', filter.kode_akun);
    if (filter.tgl_awal) params.append('tgl_awal', filter.tgl_awal);
    if (filter.tgl_akhir) params.append('tgl_akhir', filter.tgl_akhir);

    return await fetch(`/api/laporan/buku-besar?${params.toString()}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${token}`
        },
    });
}
