import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:krow/core/application/common/map_utils.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
import 'package:krow/features/shifts/data/models/staff_shift.dart';
import 'package:krow/features/shifts/domain/shift_entity.dart';

class ShiftLocationWidget extends StatelessWidget {
  final ShiftEntity viewModel;

  const ShiftLocationWidget({super.key, required this.viewModel});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 8, left: 16, right: 16),
      padding: const EdgeInsets.all(12),
      decoration: KwBoxDecorations.primaryLight12,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'location'.tr().toUpperCase(),
            style: AppTextStyles.captionReg
                .copyWith(color: AppColors.blackCaptionText),
          ),
          const Gap(16),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Expanded(
                child: Padding(
                  padding: const EdgeInsets.symmetric(vertical: 4),
                  child: Text(
                    viewModel.locationName,
                    style: AppTextStyles.headingH3.copyWith(height: 1),
                  ),
                ),
              ),
              const Gap(16),
              KwButton.outlinedPrimary(
                label: 'get_direction'.tr(),
                leftIcon: Assets.images.icons.routing,
                onPressed: () {
                  MapUtils.openMapByLatLon(
                    viewModel.locationLat,
                    viewModel.locationLon,
                  );
                },
              ),
            ],
          ),
          if (viewModel.status != EventShiftRoleStaffStatus.completed)
            _buildMap(),
        ],
      ),
    );
  }

  Widget _buildMap() {
    if (viewModel.locationLat == 0 && viewModel.locationLon == 0) {
      return Container(
        height: 166,
        margin: const EdgeInsets.only(top: 16),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
        ),
      );
    }
    return Container(
      margin: const EdgeInsets.only(top: 16),
      height: 166,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8),
      ),
      child: Center(
        child: GoogleMap(
          rotateGesturesEnabled: false,
          compassEnabled: false,
          zoomControlsEnabled: false,
          scrollGesturesEnabled: false,
          zoomGesturesEnabled: false,
          tiltGesturesEnabled: false,
          mapToolbarEnabled: false,
          myLocationButtonEnabled: false,
          markers: {
            Marker(
              markerId: const MarkerId('1'),
              position: LatLng(viewModel.locationLat, viewModel.locationLon),
            ),
          },
          initialCameraPosition: CameraPosition(
            target: LatLng(viewModel.locationLat, viewModel.locationLon),
            zoom: 12,
          ),
        ),
      ),
    );
  }
}
