import 'package:flutter/material.dart';
import 'package:lba/res/colors.dart';
import 'package:lba/widgets/profile_app_bar.dart';

class LegalAndPoliciesPage extends StatelessWidget {
  const LegalAndPoliciesPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const ProfileAppBar(
        title: 'Legal & Policies',
        showBackButton: true,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16.0),
        child: RichText(
          text: TextSpan(
            style: TextStyle(
              fontSize: 16.0,
              color: AppColors.textPrimary,
              fontFamily: 'Roboto',
              height: 1.5,
            ),
            children: [
              _buildTitle('1. User Agreement\n'),
              _buildContent(
                  'By using Proxibuy, you agree to comply with all the terms and conditions set forth in this agreement. These terms govern your use of the services provided by Proxibuy, including the app and any related content. If you do not agree with these terms, you should not use the app.\n\n'),
              _buildTitle('2. Privacy Policy\n'),
              _buildContent(
                  'Proxibuy values your privacy. We collect, store, and use your personal information only as necessary to provide you with the best service. Your data will not be shared with third parties without your consent, unless required by law. Please review our full Privacy Policy to understand how we handle your data.\n\n'),
              _buildTitle('3. Copyright Notice\n'),
              _buildContent(
                  'All content available on Proxibuy, including text, images, logos, and other media, is protected by copyright laws. You may not use, copy, distribute, or reproduce any content from the app without proper authorization from Proxibuy.\n\n'),
              _buildTitle('4. Limitation of Liability\n'),
              _buildContent(
                  'To the fullest extent permitted by law, Proxibuy is not liable for any direct, indirect, incidental, or consequential damages arising from the use or inability to use the app. By using Proxibuy, you agree to indemnify and hold harmless Proxibuy from any claims or damages arising from your use of the app.\n\n'),
              _buildTitle('5. Payment Policy\n'),
              _buildContent(
                  'When making purchases through Proxibuy, you agree to the payment terms specified within the app. Payments are processed securely, and any cancellations or refunds will be handled according to the policy outlined in the app. Please refer to our Payment Policy for detailed information regarding refunds, cancellations, and billing.\n\n'),
              _buildTitle('6. Changes to Policies\n'),
              _buildContent(
                  'Proxibuy reserves the right to update or change these policies at any time. We will notify users of any significant changes, and continued use of the app after such changes indicates your acceptance of the updated policies.'),
            ],
          ),
        ),
      ),
    );
  }

  TextSpan _buildTitle(String text) {
    return TextSpan(
      text: text,
      style: TextStyle(
        color: AppColors.primary,
        fontWeight: FontWeight.normal,
        fontSize: 18.0,
      ),
    );
  }

  TextSpan _buildContent(String text) {
    List<TextSpan> spans = [];
    final parts = text.split('Proxibuy');
    for (int i = 0; i < parts.length; i++) {
      spans.add(TextSpan(text: parts[i]));
      if (i < parts.length - 1) {
        spans.add(
          TextSpan(
            text: 'Proxibuy',
            style: TextStyle(
              color: AppColors.confirmButton,
              fontWeight: FontWeight.normal,
            ),
          ),
        );
      }
    }
    return TextSpan(children: spans);
  }
}