import { create } from 'zustand';
import { persist } from 'zustand/middleware';

interface TenantViewState {
  viewingTenantId: string | null;
  viewingTenantName: string | null;
  viewingTenantRfc: string | null;
  setViewingTenant: (id: string | null, name: string | null, rfc?: string | null) => void;
  clearViewingTenant: () => void;
}

export const useTenantViewStore = create<TenantViewState>()(
  persist(
    (set) => ({
      viewingTenantId: null,
      viewingTenantName: null,
      viewingTenantRfc: null,
      setViewingTenant: (id, name, rfc = null) => set({ viewingTenantId: id, viewingTenantName: name, viewingTenantRfc: rfc }),
      clearViewingTenant: () => set({ viewingTenantId: null, viewingTenantName: null, viewingTenantRfc: null }),
    }),
    {
      name: 'horux-tenant-view',
    }
  )
);
