import { ref } from 'vue';

export const useAsnafMockData = () => {
  // Mock data for Asnaf (beneficiaries) module
  const mockData = ref([
    {
      id: 1,
      name: 'Ahmad bin Abdullah',
      ic: '850123-01-1234',
      phone: '019-1234567',
      address: 'No. 123, Jalan Merdeka, 15000 Kota Bharu, Kelantan',
      category: 'Fakir',
      status: 'Active',
      registrationDate: '2023-01-15',
      lastUpdate: '2023-10-15'
    },
    {
      id: 2,
      name: 'Fatimah binti Hassan',
      ic: '900615-05-5678',
      phone: '013-9876543',
      address: 'No. 456, Lorong Parit, 16150 Kubang Kerian, Kelantan',
      category: 'Miskin',
      status: 'Active',
      registrationDate: '2023-02-20',
      lastUpdate: '2023-09-30'
    },
    {
      id: 3,
      name: 'Omar bin Salleh',
      ic: '751203-14-9012',
      phone: '017-5554321',
      address: 'No. 789, Kampung Tok Guru, 17070 Pasir Mas, Kelantan',
      category: 'Gharimin',
      status: 'Pending',
      registrationDate: '2023-03-10',
      lastUpdate: '2023-10-01'
    }
  ]);

  const categories = ref([
    'Fakir',
    'Miskin',
    'Amil',
    'Muallaf',
    'Riqab',
    'Gharimin',
    'Fi Sabilillah',
    'Ibn Sabil'
  ]);

  const statuses = ref([
    'Active',
    'Pending',
    'Suspended',
    'Inactive'
  ]);

  // Methods
  const getAsnafById = (id) => {
    return mockData.value.find(item => item.id === parseInt(id));
  };

  const getAsnafByCategory = (category) => {
    return mockData.value.filter(item => item.category === category);
  };

  const updateAsnaf = (id, updatedData) => {
    const index = mockData.value.findIndex(item => item.id === parseInt(id));
    if (index !== -1) {
      mockData.value[index] = { ...mockData.value[index], ...updatedData };
      return mockData.value[index];
    }
    return null;
  };

  const addAsnaf = (newData) => {
    const newId = Math.max(...mockData.value.map(item => item.id)) + 1;
    const newAsnaf = { id: newId, ...newData };
    mockData.value.push(newAsnaf);
    return newAsnaf;
  };

  const deleteAsnaf = (id) => {
    const index = mockData.value.findIndex(item => item.id === parseInt(id));
    if (index !== -1) {
      return mockData.value.splice(index, 1)[0];
    }
    return null;
  };

  return {
    mockData,
    categories,
    statuses,
    getAsnafById,
    getAsnafByCategory,
    updateAsnaf,
    addAsnaf,
    deleteAsnaf
  };
}; 