import 'package:flutter/material.dart';
import 'customer_master_screen.dart';
import 'department_master_screen.dart';
import 'product_master_screen.dart';
import 'settings_screen.dart';
import 'staff_master_screen.dart';
import 'supplier_master_screen.dart';
import 'tax_setting_screen.dart';

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

  @override
  Widget build(BuildContext context) {
    final items = <MasterEntry>[
      MasterEntry(
        title: '顧客マスター',
        description: '顧客情報の管理・編集',
        icon: Icons.people,
        builder: (_) => const CustomerMasterScreen(),
      ),
      MasterEntry(
        title: '仕入先マスター',
        description: '仕入先・支払条件の管理',
        icon: Icons.factory,
        builder: (_) => const SupplierMasterScreen(),
      ),
      MasterEntry(
        title: '商品マスター',
        description: '商品情報の管理・編集',
        icon: Icons.inventory_2,
        builder: (_) => const ProductMasterScreen(),
      ),
      MasterEntry(
        title: '部門マスター',
        description: '部門・部署構成を管理',
        icon: Icons.apartment,
        builder: (_) => const DepartmentMasterScreen(),
      ),
      MasterEntry(
        title: '担当者マスター',
        description: '社内スタッフと権限を管理',
        icon: Icons.badge,
        builder: (_) => const StaffMasterScreen(),
      ),
      MasterEntry(
        title: '消費税・端数設定',
        description: '税率と端数処理ルールを設定',
        icon: Icons.calculate,
        builder: (_) => const TaxSettingScreen(),
      ),
      MasterEntry(
        title: '設定',
        description: 'アプリ設定・メニュー管理',
        icon: Icons.settings,
        builder: (_) => const SettingsScreen(),
      ),
    ];

    return Scaffold(
      appBar: AppBar(
        leading: const BackButton(),
        title: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: const [
            Text('M3:マスター管理'),
            Text('ScreenID: M3', style: TextStyle(fontSize: 11, color: Colors.white70)),
          ],
        ),
      ),
      body: ListView.separated(
        padding: const EdgeInsets.all(16),
        itemBuilder: (context, index) {
          final item = items[index];
          return Card(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
            elevation: 1,
            child: ListTile(
              leading: CircleAvatar(
                backgroundColor: Colors.indigo.shade50,
                foregroundColor: Colors.indigo.shade700,
                child: Icon(item.icon),
              ),
              title: Text(item.title, style: const TextStyle(fontWeight: FontWeight.bold)),
              subtitle: Text(item.description),
              trailing: const Icon(Icons.chevron_right),
              onTap: () => Navigator.push(context, MaterialPageRoute(builder: item.builder)),
            ),
          );
        },
        separatorBuilder: (context, _) => const SizedBox(height: 12),
        itemCount: items.length,
      ),
    );
  }
}

class MasterEntry {
  final String title;
  final String description;
  final IconData icon;
  final WidgetBuilder builder;
  const MasterEntry({
    required this.title,
    required this.description,
    required this.icon,
    required this.builder,
  });
}
