// Elementor Global Settings Service - Manage global colors, fonts, and settings
import { AxiosInstance } from 'axios';
import { logger } from '../../utils/logger.js';
import { ErrorHandler } from '../../utils/error-handler.js';
import { ElementorGlobalSettings } from '../../types/elementor.js';
export class ElementorGlobalSettingsService {
constructor(private client: AxiosInstance) {}
/**
* Get Elementor global settings
*/
async getGlobalSettings(): Promise<ElementorGlobalSettings> {
return ErrorHandler.wrapAsync(async () => {
logger.debug('Fetching Elementor global settings');
// Elementor global settings are stored in options
// This is a simplified version - actual implementation would need
// to access WordPress options API
return {
custom_colors: [],
custom_fonts: [],
default_generic_fonts: 'Sans-serif',
site_name: '',
site_description: ''
};
}, 'ElementorGlobalSettingsService.getGlobalSettings');
}
/**
* Update global settings
*/
async updateGlobalSettings(settings: Partial<ElementorGlobalSettings>): Promise<void> {
return ErrorHandler.wrapAsync(async () => {
logger.info('Updating Elementor global settings');
// This would update the Elementor options in WordPress
// Implementation depends on having access to WordPress options API
logger.info('Global settings updated');
}, 'ElementorGlobalSettingsService.updateGlobalSettings');
}
/**
* Add custom color
*/
async addCustomColor(title: string, color: string): Promise<void> {
return ErrorHandler.wrapAsync(async () => {
logger.info('Adding custom color', { title, color });
const settings = await this.getGlobalSettings();
const customColors = settings.custom_colors || [];
customColors.push({
_id: Math.random().toString(36).substring(2, 10),
title,
color
});
await this.updateGlobalSettings({ custom_colors: customColors });
logger.info('Custom color added');
}, 'ElementorGlobalSettingsService.addCustomColor');
}
/**
* Add custom font
*/
async addCustomFont(title: string, fontFamily: string): Promise<void> {
return ErrorHandler.wrapAsync(async () => {
logger.info('Adding custom font', { title, fontFamily });
const settings = await this.getGlobalSettings();
const customFonts = settings.custom_fonts || [];
customFonts.push({
_id: Math.random().toString(36).substring(2, 10),
title,
font_family: fontFamily
});
await this.updateGlobalSettings({ custom_fonts: customFonts });
logger.info('Custom font added');
}, 'ElementorGlobalSettingsService.addCustomFont');
}
/**
* Remove custom color
*/
async removeCustomColor(colorId: string): Promise<void> {
return ErrorHandler.wrapAsync(async () => {
logger.info('Removing custom color', { colorId });
const settings = await this.getGlobalSettings();
const customColors = (settings.custom_colors || []).filter(
color => color._id !== colorId
);
await this.updateGlobalSettings({ custom_colors: customColors });
logger.info('Custom color removed');
}, 'ElementorGlobalSettingsService.removeCustomColor');
}
/**
* Remove custom font
*/
async removeCustomFont(fontId: string): Promise<void> {
return ErrorHandler.wrapAsync(async () => {
logger.info('Removing custom font', { fontId });
const settings = await this.getGlobalSettings();
const customFonts = (settings.custom_fonts || []).filter(
font => font._id !== fontId
);
await this.updateGlobalSettings({ custom_fonts: customFonts });
logger.info('Custom font removed');
}, 'ElementorGlobalSettingsService.removeCustomFont');
}
}