import 'package:flutter/material.dart';
import 'response_dialog.dart'; // Not used here, just referencing
import '../../plugins/api.dart'; // Not used here, just referencing
import '../config/config.dart';

class UserInfoFinishDialog extends StatelessWidget {
  final Map<String, dynamic> userData;  
  // 유저 데이터

  const UserInfoFinishDialog({Key? key, required this.userData}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // e.g. { "nickname": "testuser4", "profile_img": "...", "introduce_myself": "..." }
    final nickname   = (userData['nickname'] ?? '').toString();
    // 닉네임
    final profileImg = (userData['profile_img'] ?? '').toString();
    // 프로필 이미지 경로
    final intro      = (userData['introduce_myself'] ?? '').toString().trim();
    // 자기소개

    // 서버 주소
    final baseUrl = Config.baseUrl;

    return Dialog(
      backgroundColor: Colors.white,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
      child: Padding(
        // Give more horizontal/vertical padding
        // 좌우여백 좀 더 주고, 세로도 여유롭게
        padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // (A) Top Title
            // 상단 타이틀
            const Text(
              'User Info',
              // 유저 정보
              style: TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 16),

            // (B) Profile Image
            // 프로필 이미지
            Container(
              width: 100,
              height: 100,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                border: Border.all(color: Colors.black26, width: 1.5),
              ),
              child: ClipOval(
                child: (profileImg.isNotEmpty)
                    ? Image.network(
                        '$baseUrl/images$profileImg',
                        fit: BoxFit.cover,
                        errorBuilder: (ctx, err, st) => const Center(
                          child: Text(
                            'Image\nError',
                            // '이미지\n오류'
                            textAlign: TextAlign.center,
                            style: TextStyle(fontSize: 12),
                          ),
                        ),
                      )
                    : const Center(
                        child: Text(
                          'No\nImage',
                          // '이미지\n없음'
                          textAlign: TextAlign.center,
                          style: TextStyle(fontSize: 12),
                        ),
                      ),
              ),
            ),
            const SizedBox(height: 16),

            // (C) Nickname
            // 닉네임
            Text(
              nickname.isNotEmpty ? nickname : 'User',
              // if empty => '유저'
              style: const TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.bold,
              ),
            ),

            const SizedBox(height: 20),

            // (D) Introduction label
            // 소개 라벨
            const Align(
              alignment: Alignment.centerLeft,
              child: Text(
                'Introduction',
                // '소개'
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 14,
                ),
              ),
            ),
            const SizedBox(height: 6),

            // (E) Introduction Content
            // 소개 내용 (길이에 맞춰 자연스럽게 높이 확장)
            Container(
              width: double.infinity,
              constraints: const BoxConstraints(
                minHeight: 60,
                maxHeight: 200,
              ),
              decoration: BoxDecoration(
                border: Border.all(color: Colors.black26),
                borderRadius: BorderRadius.circular(8),
              ),
              padding: const EdgeInsets.all(8),
              child: SingleChildScrollView(
                child: Text(
                  intro.isNotEmpty ? intro : 'No introduction.',
                  // '소개글이 없습니다.'
                  style: const TextStyle(fontSize: 14),
                ),
              ),
            ),

            const SizedBox(height: 24),

            // (F) OK button
            // 확인 버튼
            SizedBox(
              width: 100,
              child: ElevatedButton(
                onPressed: () => Navigator.pop(context),
                style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.black,
                  foregroundColor: Colors.white,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
                  padding: const EdgeInsets.symmetric(vertical: 12),
                ),
                child: const Text(
                  'OK'
                  /* '확인' */,
                  style: TextStyle(fontSize: 14),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
