import 'package:flutter/material.dart';
import 'package:niogu_app/core/constants/app_color.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:niogu_app/core/widgets/custom_form_input.dart';
import 'package:niogu_app/core/widgets/custom_text_form_field.dart';
import 'package:niogu_app/features/outlets/presentation/screens/add_outlet_screen.dart';
import 'package:niogu_app/core/widgets/custom_time_picker.dart';
import 'package:sizer/sizer.dart';

class StafAdmin extends StatelessWidget {
  final int stafAdminNumber;
  final bool isFormVisible;
  final StaffAdminInformation stafAdmin;
  final VoidCallback passwordSuffixPressed;
  final VoidCallback passwordConfirmSuffixPressed;
  final VoidCallback onTap;
  final VoidCallback onStartTimeTap;
  final VoidCallback onEndTimeTap;
  final String? Function(String?)? nameValidator;
  final String? Function(String?)? phoneNumberValidator;
  final String? Function(String?)? emailValidator;
  final String? Function(String?)? passwordValidator;
  final String? Function(String?)? passwordConfirmValidator;
  final String? Function(String?)? shiftNameValidator;
  const StafAdmin({
    super.key,
    required this.stafAdminNumber,
    required this.isFormVisible,
    required this.stafAdmin,
    required this.passwordSuffixPressed,
    required this.passwordConfirmSuffixPressed,
    required this.onTap,
    required this.onStartTimeTap,
    required this.onEndTimeTap,
    this.nameValidator,
    this.phoneNumberValidator,
    this.emailValidator,
    this.passwordValidator,
    this.passwordConfirmValidator,
    this.shiftNameValidator,
  });

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(2.5.w),
        border: Border.all(color: Colors.grey.shade300),
      ),
      child: Column(
        children: [
          InkWell(
            onTap: onTap,
            borderRadius: BorderRadius.vertical(
              top: Radius.circular(2.5.w),
              bottom: Radius.circular(isFormVisible ? 0 : 2.5.w),
            ),
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.5.h),
              child: Row(
                children: [
                  Container(
                    padding: EdgeInsets.all(1.5.w),
                    decoration: BoxDecoration(
                      color: isFormVisible
                          ? AppColor.primaryColor.withOpacity(0.1)
                          : Colors.grey.shade100,
                      shape: BoxShape.circle,
                    ),
                    child: Icon(
                      Icons.info_outlined,
                      color: isFormVisible
                          ? AppColor.primaryColor
                          : Colors.grey,
                      size: 5.w,
                    ),
                  ),
                  SizedBox(width: 3.w),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "Informasi Staf Admin ($stafAdminNumber)",
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: isTablet
                                ? AppFontSize.medium.sp
                                : AppFontSize.small.sp,
                            color: Colors.black87,
                          ),
                        ),
                        SizedBox(height: 1.h),
                        Text(
                          stafAdminNumber > 1 ? "Opsional" : "Wajib",
                          style: TextStyle(
                            fontSize: isTablet
                                ? AppFontSize.medium.sp
                                : AppFontSize.small.sp,
                            color: Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  ),
                  Icon(
                    isFormVisible
                        ? Icons.keyboard_arrow_up_rounded
                        : Icons.keyboard_arrow_down_rounded,
                    color: Colors.grey,
                    size: 6.w,
                  ),
                ],
              ),
            ),
          ),

          if (isFormVisible) ...[
            Divider(height: 1, color: Colors.grey.shade200),
            Padding(
              padding: EdgeInsets.all(4.w),
              child: Column(
                children: [
                  CustomFormInput(
                    label: "Nama",
                    icon: Icons.person_outlined,
                    controller: stafAdmin.nameController,
                    inputType: TextInputType.text,
                    validator: nameValidator,
                  ),
                  SizedBox(height: 1.5.h),
                  CustomFormInput(
                    label: "No. Handpone / WA",
                    icon: Icons.phone_android_outlined,
                    controller: stafAdmin.phoneNumberController,
                    inputType: TextInputType.phone,
                    validator: phoneNumberValidator,
                  ),
                  SizedBox(height: 1.5.h),
                  CustomFormInput(
                    label: "Email",
                    icon: Icons.email_outlined,
                    controller: stafAdmin.emailController,
                    inputType: TextInputType.emailAddress,
                    validator: emailValidator,
                  ),
                  SizedBox(height: 1.5.h),
                  CustomFormInput(
                    label: "Password",
                    icon: Icons.lock_outline,
                    controller: stafAdmin.passwordController,
                    inputType: TextInputType.text,
                    obscureText: stafAdmin.obsecurePassword,
                    suffixIcon: stafAdmin.obsecurePassword
                        ? Icons.visibility_off_outlined
                        : Icons.visibility_outlined,
                    suffixPressed: passwordSuffixPressed,
                    validator: passwordValidator,
                  ),
                  SizedBox(height: 1.5.h),
                  CustomFormInput(
                    label: "Konfirmasi Password",
                    icon: Icons.lock_reset_outlined,
                    controller: stafAdmin.passwordConfirmController,
                    inputType: TextInputType.text,
                    obscureText: stafAdmin.obsecurePasswordConfirm,
                    suffixIcon: stafAdmin.obsecurePasswordConfirm
                        ? Icons.visibility_off_outlined
                        : Icons.visibility_outlined,
                    suffixPressed: passwordConfirmSuffixPressed,
                    validator: passwordConfirmValidator,
                  ),
                  SizedBox(height: 2.h),
                  CustomTextFormField(
                    label: "Pengaturan Shift Kerja",
                    hint: "Contoh: Shift Pagi atau Shift 1",
                    controller: stafAdmin.shiftNameController,
                    validator: shiftNameValidator,
                  ),
                  SizedBox(height: 1.5.h),
                  Row(
                    children: [
                      Expanded(
                        child: CustomTimePicker(
                          label: "Jam Mulai",
                          time: stafAdmin.startTime,
                          onTap: onStartTimeTap,
                        ),
                      ),
                      SizedBox(width: 3.w),
                      Expanded(
                        child: CustomTimePicker(
                          label: "Jam Selesai",
                          time: stafAdmin.endTime,
                          onTap: onEndTimeTap,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ],
      ),
    );
  }
}
