import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; // SharedPreferences 임포트
import '../views/login/login_page.dart'; // 로그인 페이지 임포트 (상위 디렉토리로 이동)
import '../views/user/my_page.dart';     // 마이페이지 임포트 (상위 디렉토리로 이동)
import '../views/inquiry/inquiry_to_manager_page.dart'; // 문의하기 페이지 임포트 (상위 디렉토리로 이동)

void showSettingsDialog(BuildContext context) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        backgroundColor: Colors.white,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              width: MediaQuery.of(context).size.width * 0.1,
              child: const Text(
                '',
                // 공백 (디자인용)
                style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                ),
              ),
            ),
            Container(
              width: MediaQuery.of(context).size.width * 0.3,
              child: const Text(
                'Settings', 
                // '설정'
                style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                ),
              ),
            ),
            IconButton(
              icon: const Icon(Icons.close, color: Colors.black),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        ),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const SizedBox(height: 10),
            SizedBox(
              width: double.infinity,
              child: TextButton(
                onPressed: () {
                  // Navigate to My Page
                  // '내 정보 관리' 페이지로 이동
                  Navigator.of(context).push(
                    MaterialPageRoute(builder: (context) => const MyPage()),
                  );
                },
                style: ButtonStyle(
                  side: MaterialStateProperty.all(const BorderSide(color: Colors.black)),
                  foregroundColor: MaterialStateProperty.all(Colors.black),
                ),
                child: const Text(
                  'Manage My Info',
                  // '내 정보 관리'
                ),
              ),
            ),
            const SizedBox(height: 10),
            SizedBox(
              width: double.infinity,
              child: TextButton(
                onPressed: () {
                  // Navigate to Inquiry Page
                  // '문의하기' 페이지로 이동
                  Navigator.of(context).push(
                    MaterialPageRoute(builder: (context) => const InquiryToManagerPage()),
                  );
                },
                style: ButtonStyle(
                  side: MaterialStateProperty.all(const BorderSide(color: Colors.black)),
                  foregroundColor: MaterialStateProperty.all(Colors.black),
                ),
                child: const Text(
                  'Contact Us', 
                  // '문의하기'
                ),
              ),
            ),
            const SizedBox(height: 10),
            SizedBox(
              width: double.infinity,
              child: TextButton(
                onPressed: () async {
                  // Logout
                  // '로그아웃' 클릭 시 동작
                  SharedPreferences prefs = await SharedPreferences.getInstance();
                  await prefs.setString('auth_token', ''); 
                  // auth_token 초기화
                  await prefs.setBool('auto_login', false); 
                  // auto_login 초기화

                  Navigator.pushAndRemoveUntil(
                    context,
                    MaterialPageRoute(builder: (context) => const LoginPage()),
                    // 로그인 페이지로 이동
                    (route) => false,
                  );
                },
                style: ButtonStyle(
                  side: MaterialStateProperty.all(const BorderSide(color: Colors.black)),
                  foregroundColor: MaterialStateProperty.all(Colors.black),
                ),
                child: const Text(
                  'Logout', 
                  // '로그아웃'
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}
