/**
 * Form Field Type Definitions
 */

export const FIELD_TYPES = {
    text: { label: 'Text', icon: 'text', category: 'input' },
    url: { label: 'URL', icon: 'link', category: 'input' },
    email: { label: 'Email', icon: 'email', category: 'input' },
    tel: { label: 'Telephone', icon: 'phone', category: 'input' },
    number: { label: 'Number', icon: 'number', category: 'input' },
    date: { label: 'Date', icon: 'calendar', category: 'input' },
    datetime: { label: 'Date & Time', icon: 'calendar-alt', category: 'input' },
    color: { label: 'Color', icon: 'art', category: 'input' },
    select: { label: 'Select Dropdown', icon: 'list-view', category: 'choice' },
    checkbox: { label: 'Checkbox', icon: 'checkbox', category: 'choice' },
    radio: { label: 'Radio', icon: 'radio', category: 'choice' },
    hidden: { label: 'Hidden', icon: 'hidden', category: 'advanced' },
    textarea: { label: 'Textarea', icon: 'document', category: 'input' },
    divider: { label: 'Divider', icon: 'minus', category: 'layout' },
    page_break: { label: 'Page Break', icon: 'page-break', category: 'layout' },
    country_list: { label: 'Preset: Country List', icon: 'globe', category: 'preset' },
};

export const FIELD_CATEGORIES = {
    input: { label: 'Input Fields', order: 1 },
    choice: { label: 'Choice Fields', order: 2 },
    layout: { label: 'Layout', order: 3 },
    preset: { label: 'Presets', order: 4 },
    advanced: { label: 'Advanced', order: 5 },
};

export const DEFAULT_FIELD_CONFIG = {
    field_type: 'text',
    label: '',
    field_id: '',
    placeholder: '',
    default_value: '',
    description: '',
    is_required: false,
    field_options: [],
    option_grid_columns: 1,
};

/**
 * Get field types grouped by category
 */
export function getFieldTypesByCategory() {
    const grouped = {};

    Object.entries(FIELD_TYPES).forEach(([type, config]) => {
        if (!grouped[config.category]) {
            grouped[config.category] = [];
        }
        grouped[config.category].push({ type, ...config });
    });

    return grouped;
}

/**
 * Generate unique field ID
 */
export function generateFieldId(label) {
    const base = label.toLowerCase().replace(/[^a-z0-9]/g, '_');
    const timestamp = Date.now().toString(36);
    return `${base}_${timestamp}`;
}
