import PocketBase from 'pocketbase';
import type { RecordModel } from 'pocketbase';

export interface HeroData {
  id: string;
  title: string;
  subtitle: string;
  image: string;
  alt_text: string;
  // Дополнительные поля от PocketBase
  collectionId: string;
  collectionName: string;
  created: string;
  updated: string;
}

export const heroService = {
  async getHeroData(pb: PocketBase): Promise<HeroData> {
    try {
      const result = await pb.collection('preise_hero').getFirstListItem('id != ""');
      
      return {
        id: result.id,
        title: result.title,
        subtitle: result.subtitle,
        image: result.image,
        alt_text: result.alt_text,
        collectionId: result.collectionId,
        collectionName: result.collectionName,
        created: result.created,
        updated: result.updated
      };
    } catch (error) {
      console.error('Error fetching hero data:', error);
      throw error;
    }
  }
};