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

interface AppEnvState {
  // Branding
  appName: string;
  appTagline: string;
  appMotto: string;
  appLogo: string; // URL or emoji

  // Colors
  primaryColor: string; // hex like #f97316
  primaryHover: string;
  accentColor: string;
  gradientFrom: string;
  gradientTo: string;

  // Layout
  currencySymbol: string; // ৳
  footerText: string;

  // Contact
  contactPhone: string;
  contactEmail: string;
  contactAddress: string;

  // Module toggles
  enableHouseRental: boolean;
  enableShopRental: boolean;
  enableMarketplace: boolean;
  enableMedicine: boolean;
  enableEducation: boolean;
  enableCommunity: boolean;

  // Actions
  updateEnv: (partial: Partial<AppEnvState>) => void;
  resetEnv: () => void;
}

const defaultEnv: Omit<AppEnvState, 'updateEnv' | 'resetEnv'> = {
  appName: 'Needyfy',
  appTagline: 'Your Super App for Bangladesh',
  appMotto: 'Simplifying Life, One Tap at a Time',
  appLogo: '🏠',
  primaryColor: '#f97316',
  primaryHover: '#ea580c',
  accentColor: '#f59e0b',
  gradientFrom: '#ea580c',
  gradientTo: '#f59e0b',
  currencySymbol: '৳',
  footerText: '© 2025 Needyfy. All rights reserved.',
  contactPhone: '+880 1234-567890',
  contactEmail: 'support@needyfy.com',
  contactAddress: 'Dhaka, Bangladesh',
  enableHouseRental: true,
  enableShopRental: true,
  enableMarketplace: true,
  enableMedicine: true,
  enableEducation: true,
  enableCommunity: true,
};

export const useAppEnv = create<AppEnvState>()(
  persist(
    (set) => ({
      ...defaultEnv,
      updateEnv: (partial) => set((state) => ({ ...state, ...partial })),
      resetEnv: () => set(defaultEnv),
    }),
    {
      name: 'needyfy-env',
    }
  )
);
