import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../../../../application/auth/auth_bloc.dart';
import '../../../../../../common/extension/extension.dart';
import '../../../../../../common/theme/theme.dart';
import '../../../../../components/dialog/dialog.dart';
import '../../../../../components/field/field.dart';
import '../../../../../components/spaces/space.dart';

class HomeTitle extends StatelessWidget {
  final TextEditingController controller;
  final Function(String value)? onChanged;
  const HomeTitle({super.key, required this.controller, this.onChanged});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: context.deviceHeight * 0.1,
      padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
      decoration: BoxDecoration(color: AppColor.white),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          BlocBuilder<AuthBloc, AuthState>(
            builder: (context, state) {
              return GestureDetector(
                onTap: () => showDialog(
                  context: context,
                  builder: (context) => OutletDialog(),
                ),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(
                      state.outlet.name,
                      style: AppStyle.xl.copyWith(
                        color: AppColor.primary,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                    SpaceWidth(2),
                    Icon(
                      Icons.keyboard_arrow_down,
                      color: AppColor.primary,
                      size: 18,
                    ),
                  ],
                ),
              );
            },
          ),
          SizedBox(
            width: context.deviceWidth * 0.2,
            child: SearchTextFormField(
              controller: controller,
              onChanged: onChanged,
              hintText: 'Search..',
            ),
          ),
        ],
      ),
    );
  }
}
