przebuduj by gui wyglądało nowocześniej,estetyczniej i futurystyczniej - pozbądź się galerii i możliwości dodawania zdjęć oraz cytatu


import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initializeDateFormatting();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Timelapse App',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: const Color(0xFF3B82F6),
          brightness: Brightness.light,
        ),
        useMaterial3: true,
        fontFamily: 'Montserrat',
        cardTheme: CardTheme(
          elevation: 3,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
          shadowColor: Colors.black.withOpacity(0.1),
        ),
        appBarTheme: const AppBarTheme(
          centerTitle: true,
          elevation: 0,
          backgroundColor: Color(0xFF3B82F6),
          foregroundColor: Colors.white,
        ),
      ),
      home: const Timelaps(),
    );
  }
}

class Timelaps extends StatefulWidget {
  const Timelaps({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<Timelaps> with SingleTickerProviderStateMixin {
  late TabController _tabController;
  
  // TUTAJ MOŻESZ ZMIENIĆ DATY DLA SWOJEGO PROJEKTU
  final DateTime startDate = DateTime(2025, 1, 1);
  final DateTime endDate = DateTime(2025, 12, 31);
  
  late DateTime currentDate;
  late Duration daysPassed;
  late Duration daysToGo;
  double totalProgress = 0.0;
  int currentPhaseIndex = 0;
  List<String> savedImages = [];

  // TUTAJ MOŻESZ DODAĆ SWOJE WŁASNE FAZY
  final List<Phase> phases = [
    Phase(
      title: "FAZA 1",
      startDate: DateTime(2025, 1, 1),
      endDate: DateTime(2025, 3, 31),
      description: "",
      goals: [],
    ),
    Phase(
      title: "FAZA 2",
      startDate: DateTime(2025, 4, 1),
      endDate: DateTime(2025, 6, 30),
      description: "",
      goals: [],
    ),
    Phase(
      title: "FAZA 3",
      startDate: DateTime(2025, 7, 1),
      endDate: DateTime(2025, 9, 30),
      description: "",
      goals: [],
    ),
    Phase(
      title: "FAZA 4",
      startDate: DateTime(2025, 10, 1),
      endDate: DateTime(2025, 12, 31),
      description: "",
      goals: [],
    ),
  ];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 6, vsync: this);
    currentDate = DateTime.now();
    _updateProgressData();
    _loadProgress();
    _loadSavedImages();
    initializeDateFormatting('pl_PL', null);
  }

  void _updateProgressData() {
    setState(() {
      daysPassed = currentDate.difference(startDate);
      daysToGo = endDate.difference(currentDate);
      totalProgress = daysPassed.inDays / endDate.difference(startDate).inDays;
      currentPhaseIndex = _getCurrentPhaseIndex();
    });
  }

  int _getCurrentPhaseIndex() {
    for (int i = 0; i < phases.length; i++) {
      if (currentDate.isAfter(phases[i].startDate.subtract(const Duration(days: 1))) && 
          currentDate.isBefore(phases[i].endDate.add(const Duration(days: 1)))) {
        return i;
      }
    }
    return phases.length - 1;
  }

  Future<void> _loadSavedImages() async {
    final prefs = await SharedPreferences.getInstance();
    setState(() {
      savedImages = prefs.getStringList('saved_images') ?? [];
    });
  }

  Future<void> _saveImagePath(String path) async {
    final prefs = await SharedPreferences.getInstance();
    setState(() {
      savedImages.add(path);
    });
    await prefs.setStringList('saved_images', savedImages);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  Future<void> _loadProgress() async {
    final prefs = await SharedPreferences.getInstance();
    
    for (int i = 0; i < phases.length; i++) {
      for (int j = 0; j < phases[i].goals.length; j++) {
        final progress = prefs.getDouble('phase_${i}_goal_${j}_progress') ?? 0.0;
        setState(() {
          phases[i].goals[j].progress = progress;
        });
      }
    }
  }
  
  Future<void> _saveProgress() async {
    final prefs = await SharedPreferences.getInstance();
    
    for (int i = 0; i < phases.length; i++) {
      for (int j = 0; j < phases[i].goals.length; j++) {
        await prefs.setDouble('phase_${i}_goal_${j}_progress', phases[i].goals[j].progress);
      }
    }
  }

  void _updateGoalProgress(int phaseIndex, int goalIndex, double newProgress) {
    setState(() {
      phases[phaseIndex].goals[goalIndex].progress = newProgress;
      _saveProgress();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'Timelapse',
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
        backgroundColor: Colors.blue,
        elevation: 0,
        bottom: TabBar(
          controller: _tabController,
          isScrollable: true,
          tabs: const [
            Tab(icon: Icon(Icons.home), text: 'Podsumowanie'),
            Tab(icon: Icon(Icons.flag), text: 'Faza 1'),
            Tab(icon: Icon(Icons.flag), text: 'Faza 2'),
            Tab(icon: Icon(Icons.flag), text: 'Faza 3'),
            Tab(icon: Icon(Icons.flag), text: 'Faza 4'),
            Tab(icon: Icon(Icons.photo_library), text: 'Galeria'),
          ],
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: [
          _buildMainTab(),
          _buildPhaseTab(0),
          _buildPhaseTab(1),
          _buildPhaseTab(2),
          _buildPhaseTab(3),
          _buildGalleryTab(),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _showImagePickerModal,
        child: const Icon(Icons.add_a_photo),
        tooltip: 'Dodaj zdjęcie',
      ),
    );
  }

  void _showImagePickerModal() {
    showModalBottomSheet(
      context: context,
      backgroundColor: Theme.of(context).colorScheme.surface,
      isScrollControlled: true,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
      ),
      builder: (context) {
        return Padding(
          padding: const EdgeInsets.all(24.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Center(
                child: Container(
                  width: 40,
                  height: 4,
                  decoration: BoxDecoration(
                    color: Colors.grey.withOpacity(0.3),
                    borderRadius: BorderRadius.circular(4),
                  ),
                ),
              ),
              const SizedBox(height: 24),
              Text(
                'Dodaj zdjęcie',
                style: TextStyle(
                  fontSize: 22,
                  fontWeight: FontWeight.bold,
                  color: Theme.of(context).colorScheme.onSurface,
                ),
              ),
              const SizedBox(height: 8),
              Text(
                'Wybierz źródło nowego zdjęcia',
                style: TextStyle(
                  fontSize: 16,
                  color: Theme.of(context).colorScheme.onSurfaceVariant,
                ),
              ),
              const SizedBox(height: 32),
              Row(
                children: [
                  Expanded(
                    child: InkWell(
                      onTap: () {
                        Navigator.pop(context);
                        _pickImage(ImageSource.camera);
                      },
                      borderRadius: BorderRadius.circular(16),
                      child: Container(
                        padding: const EdgeInsets.symmetric(vertical: 20),
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: Theme.of(context).colorScheme.outline.withOpacity(0.3),
                          ),
                          borderRadius: BorderRadius.circular(16),
                        ),
                        child: Column(
                          children: [
                            Icon(
                              Icons.camera_alt,
                              size: 48,
                              color: Theme.of(context).colorScheme.primary,
                            ),
                            const SizedBox(height: 12),
                            Text(
                              'Aparat',
                              style: TextStyle(
                                fontSize: 16,
                                fontWeight: FontWeight.w500,
                                color: Theme.of(context).colorScheme.onSurface,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(width: 16),
                  Expanded(
                    child: InkWell(
                      onTap: () {
                        Navigator.pop(context);
                        _pickImage(ImageSource.gallery);
                      },
                      borderRadius: BorderRadius.circular(16),
                      child: Container(
                        padding: const EdgeInsets.symmetric(vertical: 20),
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: Theme.of(context).colorScheme.outline.withOpacity(0.3),
                          ),
                          borderRadius: BorderRadius.circular(16),
                        ),
                        child: Column(
                          children: [
                            Icon(
                              Icons.photo_library,
                              size: 48,
                              color: Theme.of(context).colorScheme.primary,
                            ),
                            const SizedBox(height: 12),
                            Text(
                              'Galeria',
                              style: TextStyle(
                                fontSize: 16,
                                fontWeight: FontWeight.w500,
                                color: Theme.of(context).colorScheme.onSurface,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 32),
            ],
          ),
        );
      },
    );
  }

  Future<void> _pickImage(ImageSource source) async {
    final picker = ImagePicker();
    final pickedFile = await picker.pickImage(source: source);

    if (pickedFile != null) {
      await _saveImagePath(pickedFile.path);
      
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(
          content: Text('Zdjęcie zostało zapisane'),
          duration: Duration(seconds: 2),
        ),
      );
    }
  }

  Widget _buildGalleryTab() {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Galeria', style: TextStyle(fontWeight: FontWeight.w600)),
        elevation: 0,
        backgroundColor: Theme.of(context).colorScheme.surface,
        foregroundColor: Theme.of(context).colorScheme.onSurface,
        centerTitle: true,
        actions: [
          IconButton(
            icon: const Icon(Icons.add_a_photo),
            onPressed: _showImagePickerModal,
            tooltip: 'Dodaj nowe zdjęcie',
          ),
        ],
      ),
      body: savedImages.isEmpty
          ? Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Icon(
                    Icons.photo_library_outlined,
                    size: 80,
                    color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
                  ),
                  const SizedBox(height: 16),
                  Text(
                    'Brak zdjęć',
                    style: TextStyle(
                      fontSize: 22,
                      fontWeight: FontWeight.bold,
                      color: Theme.of(context).colorScheme.onSurface,
                    ),
                  ),
                  const SizedBox(height: 8),
                  Text(
                    'Dodaj pierwsze zdjęcie używając przycisku poniżej',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      fontSize: 16,
                      color: Theme.of(context).colorScheme.onSurfaceVariant,
                    ),
                  ),
                  const SizedBox(height: 24),
                  ElevatedButton.icon(
                    icon: const Icon(Icons.add_photo_alternate),
                    label: const Text('Dodaj zdjęcie'),
                    style: ElevatedButton.styleFrom(
                      padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
                    ),
                    onPressed: _showImagePickerModal,
                  ),
                ],
              ),
            )
          : Padding(
              padding: const EdgeInsets.all(16),
              child: GridView.builder(
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  mainAxisSpacing: 16,
                  crossAxisSpacing: 16,
                ),
                itemCount: savedImages.length,
                itemBuilder: (context, index) {
                  return Hero(
                    tag: 'image_$index',
                    child: GestureDetector(
                      onTap: () => _showFullScreenImage(savedImages[index], index),
                      child: Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(16),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.black.withOpacity(0.1),
                              spreadRadius: 1,
                              blurRadius: 10,
                              offset: const Offset(0, 4),
                            ),
                          ],
                        ),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(16),
                          child: Image.file(
                            File(savedImages[index]),
                            fit: BoxFit.cover,
                          ),
                        ),
                      ),
                    ),
                  );
                },
              ),
            ),
      floatingActionButton: savedImages.isNotEmpty
          ? FloatingActionButton(
              onPressed: _showImagePickerModal,
              backgroundColor: Theme.of(context).colorScheme.primary,
              foregroundColor: Theme.of(context).colorScheme.onPrimary,
              elevation: 4,
              child: const Icon(Icons.add_a_photo),
            )
          : null,
    );
  }

  void _showFullScreenImage(String imagePath, int index) {
    showDialog(
      context: context,
      useSafeArea: false,
      builder: (context) => Material(
        color: Colors.black,
        child: SafeArea(
          child: Stack(
            fit: StackFit.expand,
            children: [
              Hero(
                tag: 'image_$index',
                child: InteractiveViewer(
                  panEnabled: true,
                  minScale: 0.5,
                  maxScale: 4.0,
                  child: Center(
                    child: Image.file(
                      File(imagePath),
                      fit: BoxFit.contain,
                    ),
                  ),
                ),
              ),
              Positioned(
                top: 20,
                right: 20,
                child: CircleAvatar(
                  backgroundColor: Colors.black.withOpacity(0.5),
                  child: IconButton(
                    icon: const Icon(Icons.close, color: Colors.white),
                    onPressed: () => Navigator.pop(context),
                  ),
                ),
              ),
              Positioned(
                bottom: 20,
                left: 0,
                right: 0,
                child: Container(
                  padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.bottomCenter,
                      end: Alignment.topCenter,
                      colors: [
                        Colors.black.withOpacity(0.7),
                        Colors.transparent,
                      ],
                    ),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      CircleAvatar(
                        backgroundColor: Colors.red.withOpacity(0.8),
                        child: IconButton(
                          icon: const Icon(Icons.delete, color: Colors.white),
                          onPressed: () => _confirmDeleteImage(imagePath),
                          tooltip: 'Usuń zdjęcie',
                        ),
                      ),
                      CircleAvatar(
                        backgroundColor: Colors.white.withOpacity(0.2),
                        child: IconButton(
                          icon: const Icon(Icons.share, color: Colors.white),
                          onPressed: () {
                            // Funkcja udostępniania
                          },
                          tooltip: 'Udostępnij',
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildMainTab() {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildProgressCard(),
          const SizedBox(height: 20),
          _buildCurrentPhaseCard(),
          const SizedBox(height: 20),
          _buildUpcomingGoals(),
          const SizedBox(height: 20),
          _buildMotivationalQuote(),
        ],
      ),
    );
  }

  Widget _buildProgressCard() {
    return Card(
      margin: const EdgeInsets.symmetric(vertical: 8),
      child: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  'Dzień ${daysPassed.inDays + 1} z ${endDate.difference(startDate).inDays}',
                  style: const TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.w700,
                  ),
                ),
                Text(
                  "${(totalProgress * 100).toStringAsFixed(1)}%",
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.w800,
                    color: _getProgressColor(totalProgress),
                  ),
                ),
              ],
            ),
            const SizedBox(height: 16),
            LinearPercentIndicator(
              animation: true,
              lineHeight: 14.0,
              animationDuration: 1500,
              percent: totalProgress.clamp(0.0, 1.0),
              barRadius: const Radius.circular(10),
              progressColor: _getProgressColor(totalProgress),
              backgroundColor: Colors.grey.shade200,
            ),
            const SizedBox(height: 16),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
              decoration: BoxDecoration(
                color: Colors.blue.shade50,
                borderRadius: BorderRadius.circular(12),
                border: Border.all(
                  color: Colors.blue.shade200,
                  width: 1,
                ),
              ),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(
                    Icons.event,
                    size: 18,
                    color: Colors.blue.shade700,
                  ),
                  const SizedBox(width: 8),
                  Text(
                    'Pozostało: ${daysToGo.inDays} dni',
                    style: TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.w600,
                      color: Colors.blue.shade700,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Color _getProgressColor(double progress) {
    if (progress < 0.3) return Colors.red;
    if (progress < 0.7) return Colors.orange;
    return Colors.green;
  }

  Widget _buildCurrentPhaseCard() {
    Phase currentPhase = phases[currentPhaseIndex];
    double phaseProgress = _calculatePhaseProgress(currentPhaseIndex);

    return Card(
      elevation: 4,
      color: Colors.blue.shade50,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                const Icon(Icons.flag, color: Colors.blue),
                const SizedBox(width: 8),
                Text(
                  'Aktualna faza: ${currentPhase.title}',
                  style: const TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                    color: Colors.blue,
                  ),
                ),
              ],
            ),
            const SizedBox(height: 12),
            LinearPercentIndicator(
              animation: true,
              lineHeight: 10.0,
              animationDuration: 500,
              percent: phaseProgress.clamp(0.0, 1.0),
              barRadius: const Radius.circular(5),
              progressColor: _getProgressColor(phaseProgress),
              backgroundColor: Colors.grey.shade300,
            ),
            const SizedBox(height: 4),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  DateFormat('dd.MM.yyyy', 'pl_PL').format(currentPhase.startDate),
                ),
                Text(
                  DateFormat('dd.MM.yyyy', 'pl_PL').format(currentPhase.endDate),
                ),
                Text(
                  '${(phaseProgress * 100).toStringAsFixed(0)}%',
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  double _calculatePhaseProgress(int phaseIndex) {
    Phase phase = phases[phaseIndex];
    if (currentDate.isBefore(phase.startDate)) return 0.0;
    if (currentDate.isAfter(phase.endDate)) return 1.0;
    
    return currentDate.difference(phase.startDate).inDays / 
           phase.endDate.difference(phase.startDate).inDays;
  }

  Widget _buildUpcomingGoals() {
    if (phases[currentPhaseIndex].goals.isEmpty) {
      return Card(
        child: Padding(
          padding: const EdgeInsets.all(20),
          child: Center(
            child: Column(
              children: [
                Icon(
                  Icons.add_task,
                  size: 48,
                  color: Colors.grey.shade400,
                ),
                const SizedBox(height: 12),
                Text(
                  'Brak celów w tej fazie',
                  style: TextStyle(
                    fontSize: 16,
                    color: Colors.grey.shade600,
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    }

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          'Cele:',
          style: TextStyle(
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
        ),
        const SizedBox(height: 10),
        ...phases[currentPhaseIndex].goals.map((goal) {
          double progress = goal.progress / goal.maxProgress;
          return _buildGoalProgressTile(goal, progress);
        }).toList(),
      ],
    );
  }

  Widget _buildGoalProgressTile(Goal goal, double progress) {
    final bool isComplete = progress >= 1.0;
    
    return Card(
      margin: const EdgeInsets.only(bottom: 12),
      elevation: 2,
      child: InkWell(
        borderRadius: BorderRadius.circular(16),
        onTap: () {
          _showGoalUpdateDialog(
            currentPhaseIndex,
            phases[currentPhaseIndex].goals.indexOf(goal),
            goal,
          );
        },
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    width: 36,
                    height: 36,
                    decoration: BoxDecoration(
                      color: isComplete 
                        ? Colors.green.withOpacity(0.15) 
                        : Theme.of(context).colorScheme.primaryContainer.withOpacity(0.7),
                      shape: BoxShape.circle,
                    ),
                    child: Center(
                      child: Icon(
                        isComplete ? Icons.check : Icons.flag,
                        color: isComplete 
                          ? Colors.green 
                          : Theme.of(context).colorScheme.primary,
                        size: 18,
                      ),
                    ),
                  ),
                  const SizedBox(width: 12),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          goal.title,
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 16,
                            color: isComplete 
                              ? Colors.green 
                              : Theme.of(context).colorScheme.onSurface,
                          ),
                        ),
                        const SizedBox(height: 2),
                        Text(
                          goal.description,
                          style: TextStyle(
                            fontSize: 13,
                            color: Theme.of(context).colorScheme.onSurfaceVariant,
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                    decoration: BoxDecoration(
                      color: isComplete 
                        ? Colors.green.withOpacity(0.15) 
                        : Theme.of(context).colorScheme.primaryContainer.withOpacity(0.5),
                      borderRadius: BorderRadius.circular(16),
                    ),
                    child: Text(
                      '${goal.progress.toStringAsFixed(0)}/${goal.maxProgress.toStringAsFixed(0)}',
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 13,
                        color: isComplete 
                          ? Colors.green 
                          : Theme.of(context).colorScheme.primary,
                      ),
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 12),
              LinearPercentIndicator(
                lineHeight: 8.0,
                percent: progress.clamp(0.0, 1.0),
                progressColor: isComplete ? Colors.green : _getProgressColor(progress),
                backgroundColor: Colors.grey.shade200,
                padding: EdgeInsets.zero,
                barRadius: const Radius.circular(4),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildMotivationalQuote() {
    return Card(
      elevation: 3,
      color: Theme.of(context).colorScheme.secondaryContainer.withOpacity(0.7),
      child: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            Container(
              width: 50,
              height: 50,
              decoration: BoxDecoration(
                color: Theme.of(context).colorScheme.secondary.withOpacity(0.2),
                shape: BoxShape.circle,
              ),
              child: Icon(
                Icons.lightbulb_outline,
                color: Theme.of(context).colorScheme.secondary,
                size: 28,
              ),
            ),
            const SizedBox(height: 16),
            Text(
              '""', // TUTAJ MOŻESZ DODAĆ WŁASNY CYTAT
              style: TextStyle(
                fontSize: 20,
                fontStyle: FontStyle.italic,
                fontWeight: FontWeight.bold,
                color: Theme.of(context).colorScheme.onSecondaryContainer,
              ),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildPhaseTab(int phaseIndex) {
    Phase phase = phases[phaseIndex];
    double phaseProgress = _calculatePhaseProgress(phaseIndex);
    
    return SingleChildScrollView(
      padding: const EdgeInsets.all(16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Card(
            elevation: 4,
            color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
            child: Padding(
              padding: const EdgeInsets.all(20),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
                    decoration: BoxDecoration(
                      color: Theme.of(context).colorScheme.primary.withOpacity(0.2),
                      borderRadius: BorderRadius.circular(12),
                      border: Border.all(
                        color: Theme.of(context).colorScheme.primary.withOpacity(0.3),
                      ),
                    ),
                    child: Text(
                      phase.title,
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: Theme.of(context).colorScheme.primary,
                      ),
                    ),
                  ),
                  const SizedBox(height: 20),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        'Okres: ${DateFormat('d MMM', 'pl_PL').format(phase.startDate)} - ${DateFormat('d MMM', 'pl_PL').format(phase.endDate)}',
                        style: TextStyle(
                          fontWeight: FontWeight.w500,
                          fontSize: 14,
                          color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
                        ),
                      ),
                      Text(
                        '${(phaseProgress * 100).toStringAsFixed(0)}%',
                        style: const TextStyle(fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
          const SizedBox(height: 20),
          if (phase.goals.isEmpty)
            Center(
              child: Card(
                child: Padding(
                  padding: const EdgeInsets.all(40),
                  child: Column(
                    children: [
                      Icon(
                        Icons.add_circle_outline,
                        size: 64,
                        color: Colors.grey.shade400,
                      ),
                      const SizedBox(height: 16),
                      Text(
                        'Brak celów',
                        style: TextStyle(
                          fontSize: 18,
                          color: Colors.grey.shade600,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            )
          else
            ...phase.goals.asMap().entries.map((entry) {
              int goalIndex = entry.key;
              Goal goal = entry.value;
              double progress = goal.progress / goal.maxProgress;
              
              return Card(
                margin: const EdgeInsets.only(bottom: 10),
                child: InkWell(
                  onTap: () => _showGoalUpdateDialog(phaseIndex, goalIndex, goal),
                  child: Padding(
                    padding: const EdgeInsets.all(12),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          goal.title,
                          style: const TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        const SizedBox(height: 4),
                        Text(
                          goal.description,
                          style: const TextStyle(fontSize: 14),
                        ),
                        const SizedBox(height: 8),
                        LinearPercentIndicator(
                          animation: true,
                          lineHeight: 20.0,
                          animationDuration: 500,
                          percent: progress.clamp(0.0, 1.0),
                          center: Text("${(progress * 100).toStringAsFixed(0)}%"),
                          barRadius: const Radius.circular(10),
                          progressColor: _getProgressColor(progress),
                        ),
                        const SizedBox(height: 8),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            ElevatedButton(
                              onPressed: () {
                                _showGoalUpdateDialog(phaseIndex, goalIndex, goal);
                              },
                              child: const Text('Aktualizuj'),
                            ),
                            Text(
                              '${goal.progress.toStringAsFixed(0)}/${goal.maxProgress.toStringAsFixed(0)}',
                              style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: progress >= 1.0 ? Colors.green : Colors.blue,
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              );
            }).toList(),
        ],
      ),
    );
  }

  void _confirmDeleteImage(String imagePath) async {
    final shouldDelete = await showDialog<bool>(
      context: context,
      builder: (context) => AlertDialog(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
        title: const Text('Usunąć zdjęcie?'),
        content: const Text('Czy na pewno chcesz usunąć to zdjęcie? Tej operacji nie można cofnąć.'),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context, false),
            child: Text(
              'Anuluj',
              style: TextStyle(color: Theme.of(context).colorScheme.primary),
            ),
          ),
          ElevatedButton(
            onPressed: () => Navigator.pop(context, true),
            style: ElevatedButton.styleFrom(
              backgroundColor: Colors.red,
              foregroundColor: Colors.white,
            ),
            child: const Text('Usuń'),
          ),
        ],
      ),
    );
    
    if (shouldDelete ?? false) {
      final prefs = await SharedPreferences.getInstance();
      setState(() {
        savedImages.remove(imagePath);
      });
      await prefs.setStringList('saved_images', savedImages);
      
      try {
        final file = File(imagePath);
        if (await file.exists()) {
          await file.delete();
        }
      } catch (e) {
        debugPrint('Błąd podczas usuwania pliku: $e');
      }
      
      Navigator.pop(context);
      
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: const Row(
            children: [
              Icon(Icons.check_circle, color: Colors.white),
              SizedBox(width: 12),
              Text('Zdjęcie zostało usunięte'),
            ],
          ),
          behavior: SnackBarBehavior.floating,
          backgroundColor: Theme.of(context).colorScheme.secondary,
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
          margin: const EdgeInsets.all(16),
          duration: const Duration(seconds: 2),
        ),
      );
    }
  }

  void _showGoalUpdateDialog(int phaseIndex, int goalIndex, Goal goal) {
    double newProgress = goal.progress;
    bool isBinaryGoal = goal.maxProgress == 1;

    showDialog(
      context: context,
      builder: (context) {
        return StatefulBuilder(
          builder: (context, setState) {
            return AlertDialog(
              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
              backgroundColor: Colors.white,
              title: Text(
                'Aktualizuj - ${goal.title}',
                style: const TextStyle(fontWeight: FontWeight.bold),
              ),
              content: SingleChildScrollView(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      goal.description,
                      style: const TextStyle(fontSize: 14),
                    ),
                    const SizedBox(height: 20),
                    if (isBinaryGoal)
                      SwitchListTile(
                        title: const Text('Cel osiągnięty'),
                        value: newProgress >= 1,
                        onChanged: (value) {
                          setState(() {
                            newProgress = value ? 1 : 0;
                          });
                        },
                      )
                    else
                      Column(
                        children: [
                          Row(
                            children: [
                              const Text('Postęp: '),
                              Expanded(
                                child: Slider(
                                  value: newProgress,
                                  min: 0,
                                  max: goal.maxProgress,
                                  divisions: goal.maxProgress.toInt(),
                                  label: newProgress.toStringAsFixed(0),
                                  onChanged: (value) {
                                    setState(() {
                                      newProgress = value;
                                    });
                                  },
                                ),
                              ),
                              Text(newProgress.toStringAsFixed(0)),
                            ],
                          ),
                          const SizedBox(height: 10),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              IconButton(
                                icon: const Icon(Icons.remove),
                                onPressed: () {
                                  setState(() {
                                    newProgress = (newProgress - 1).clamp(0, goal.maxProgress);
                                  });
                                },
                              ),
                              IconButton(
                                icon: const Icon(Icons.add),
                                onPressed: () {
                                  setState(() {
                                    newProgress = (newProgress + 1).clamp(0, goal.maxProgress);
                                  });
                                },
                              ),
                            ],
                          ),
                        ],
                      ),
                  ],
                ),
              ),
              actions: [
                TextButton(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('Anuluj'),
                ),
                ElevatedButton(
                  onPressed: () {
                    _updateGoalProgress(phaseIndex, goalIndex, newProgress);
                    Navigator.pop(context);
                  },
                  child: const Text('Zapisz'),
                ),
              ],
            );
          },
        );
      },
    );
  }
}

class Phase {
  final String title;
  final DateTime startDate;
  final DateTime endDate;
  final String description;
  final List<Goal> goals;

  Phase({
    required this.title,
    required this.startDate,
    required this.endDate,
    required this.description,
    required this.goals,
  });
}

class Goal {
  final String title;
  final String description;
  double progress;
  final double maxProgress;

  Goal({
    required this.title,
    required this.description,
    this.progress = 0,
    required this.maxProgress,
  });
}