import { create } from 'zustand';
import { IDistrict, IRegion } from '../interfaces/gis';

export interface RegionsState {
    regionsData: IRegion[],
    districtsData: IDistrict[],
}

export const useRegionsStore = create<RegionsState>(() => ({
    regionsData: [],
    districtsData: []
}))

export const getRegionData = (id: number) => {
    return useRegionsStore.getState().regionsData.find(region => region.id === id)
}

export const getRegionsData = () => {
    return useRegionsStore.getState().regionsData
}

export const setRegionsData = (regionsData: any) => {
    useRegionsStore.setState(() => ({ regionsData: regionsData }))
}

export const getDistrictData = (id: number) => {
    return useRegionsStore.getState().districtsData.find(district => district.id === id)
}

export const getDistrictsData = () => {
    return useRegionsStore.getState().districtsData
}

export const setDistrictsData = (districtsData: any) => {
    useRegionsStore.setState(() => ({ districtsData: districtsData }))
}