<div class="tab-pane fade" id="client" role="tabpanel">
    <div class="card">
        <div class="card-body">
            <div class="row mb-2">
                <label for="admin_client_display_format" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_admin_client_display_format') }}</label>
                <div class="col-sm-8">
                    <select class="form-control w-50 d-inline-block" id="admin_client_display_format" name="admin_client_display_format">
                        <option value="firstname_lastname" {{ old('admin_client_display_format', $settings['admin_client_display_format'] ?? '') == 'firstname_lastname' ? 'selected' : '' }}>
                            {{ __('admin/settings.options_show_firstname_lastname_only') }}
                        </option>
                        <option value="company_or_name" {{ old('admin_client_display_format', $settings['admin_client_display_format'] ?? '') == 'company_or_name' ? 'selected' : '' }}>
                            {{ __('admin/settings.options_show_company_if_set_otherwise_name') }}
                        </option>
                        <option value="full_name_and_company" {{ old('admin_client_display_format', $settings['admin_client_display_format'] ?? '') == 'full_name_and_company' ? 'selected' : '' }}>
                            {{ __('admin/settings.options_show_full_name_and_company_if_set') }}
                        </option>
                    </select>
                </div>
            </div>
            <div class="row mb-2 align-items-center">
                <label for="allow_client_registration" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_allow_client_registration') }}</label>
                <div class="col-sm-8">
                    <div class="form-check form-switch d-flex align-items-center gap-2">
                        <input class="form-check-input d-inline-block" type="checkbox" id="allow_client_registration" name="allow_client_registration" value="1" {{ old('allow_client_registration', $settings['allow_client_registration'] ?? false) ? 'checked' : '' }}>
                        <span class="form-text mb-0">{{ __('admin/settings.fields_allow_client_registration_description') }}</span>
                    </div>
                </div>
            </div>
            <div class="row mb-2 align-items-center">
                <label for="client_email_preferences" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_client_email_preferences') }}</label>
                <div class="col-sm-8">
                    <div class="form-check form-switch d-flex align-items-center gap-2">
                        <input class="form-check-input d-inline-block" type="checkbox" id="client_email_preferences" name="client_email_preferences" value="1" {{ old('client_email_preferences', $settings['client_email_preferences'] ?? false) ? 'checked' : '' }}>
                        <span class="form-text mb-0">{{ __('admin/settings.fields_client_email_preferences_description') }}</span>
                    </div>
                </div>
            </div>

            
            <div class="row mb-2">
                <label class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_optional_client_profile_fields') }}</label>
                <div class="col-sm-8">
                    <div class="mb-2">
                        <small class="text-muted">{{ __('admin/settings.fields_optional_client_profile_fields_description') }}</small>
                    </div>
                    @php
                        $selectedFields = old('optional_client_profile_fields', $settings['optional_client_profile_fields'] ?? '');
                        $selectedArray = !empty($selectedFields) ? (is_string($selectedFields)?explode(',', $selectedFields):$selectedFields) : [];
                    @endphp
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_firstname" name="optional_client_profile_fields[]" value="firstname" {{ in_array('firstname', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_firstname">
                                    {{ __('admin/settings.options_first_name') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_lastname" name="optional_client_profile_fields[]" value="lastname" {{ in_array('lastname', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_lastname">
                                    {{ __('admin/settings.options_last_name') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_company" name="optional_client_profile_fields[]" value="company" {{ in_array('company', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_company">
                                    {{ __('admin/settings.options_company_name') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_address1" name="optional_client_profile_fields[]" value="address1" {{ in_array('address1', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_address1">
                                    {{ __('admin/settings.options_address_1') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_city" name="optional_client_profile_fields[]" value="city" {{ in_array('city', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_city">
                                    {{ __('admin/settings.options_city') }}
                                </label>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_state" name="optional_client_profile_fields[]" value="state" {{ in_array('state', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_state">
                                    {{ __('admin/settings.options_state_region') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_postcode" name="optional_client_profile_fields[]" value="postcode" {{ in_array('postcode', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_postcode">
                                    {{ __('admin/settings.options_postcode') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="optional_phone" name="optional_client_profile_fields[]" value="phone" {{ in_array('phone', $selectedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="optional_phone">
                                    {{ __('admin/settings.options_phone_number') }}
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row mb-2">
                <label class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_locked_client_user_profile_fields') }}</label>
                <div class="col-sm-8">
                    <div class="mb-2">
                        <small class="text-muted">{{ __('admin/settings.fields_locked_client_user_profile_fields_description') }}</small>
                    </div>
                    @php
                        $lockedFields = old('locked_client_user_profile_fields', $settings['locked_client_user_profile_fields'] ?? '');
                        $lockedArray = !empty($lockedFields) ? (is_string($lockedFields)?explode(',', $lockedFields):$lockedFields)  : [];
                    @endphp
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_firstname" name="locked_client_user_profile_fields[]" value="firstname" {{ in_array('firstname', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_firstname">
                                    {{ __('admin/settings.options_first_name') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_lastname" name="locked_client_user_profile_fields[]" value="lastname" {{ in_array('lastname', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_lastname">
                                    {{ __('admin/settings.options_last_name') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_company" name="locked_client_user_profile_fields[]" value="company" {{ in_array('company', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_company">
                                    {{ __('admin/settings.options_company_name') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_email" name="locked_client_user_profile_fields[]" value="email" {{ in_array('email', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_email">
                                    {{ __('admin/settings.options_email_address') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_address1" name="locked_client_user_profile_fields[]" value="address1" {{ in_array('address1', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_address1">
                                    {{ __('admin/settings.options_address_1') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_address2" name="locked_client_user_profile_fields[]" value="address2" {{ in_array('address2', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_address2">
                                    {{ __('admin/settings.options_address_2') }}
                                </label>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_city" name="locked_client_user_profile_fields[]" value="city" {{ in_array('city', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_city">
                                    {{ __('admin/settings.options_city') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_state" name="locked_client_user_profile_fields[]" value="state" {{ in_array('state', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_state">
                                    {{ __('admin/settings.options_state_region') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_postcode" name="locked_client_user_profile_fields[]" value="postcode" {{ in_array('postcode', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_postcode">
                                    {{ __('admin/settings.options_postcode') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_country" name="locked_client_user_profile_fields[]" value="country" {{ in_array('country', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_country">
                                    {{ __('admin/settings.options_country') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_phone" name="locked_client_user_profile_fields[]" value="phone" {{ in_array('phone', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_phone">
                                    {{ __('admin/settings.options_phone_number') }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="locked_tax_id" name="locked_client_user_profile_fields[]" value="tax_id" {{ in_array('tax_id', $lockedArray) ? 'checked' : '' }}>
                                <label class="form-check-label" for="locked_tax_id">
                                    {{ __('admin/settings.options_tax_id') }}
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="row mb-2 align-items-center">
                <label for="show_cancellation_link" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_show_cancellation_link') }}</label>
                <div class="col-sm-8">
                    <div class="form-check form-switch d-flex align-items-center gap-2">
                        <input class="form-check-input d-inline-block" type="checkbox" id="show_cancellation_link" name="show_cancellation_link" value="1" {{ old('show_cancellation_link', $settings['show_cancellation_link'] ?? false) ? 'checked' : '' }}>
                        <span class="form-text mb-0">{{ __('admin/settings.fields_show_cancellation_link_description') }}</span>
                    </div>
                </div>
            </div>
            <div class="row mb-2 align-items-center">
                <label for="cancellation_reason_required" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_cancellation_reason_required') }}</label>
                <div class="col-sm-8">
                    <div class="form-check form-switch d-flex align-items-center gap-2">
                        <input class="form-check-input d-inline-block" type="checkbox" id="cancellation_reason_required" name="cancellation_reason_required" value="1" {{ old('cancellation_reason_required', $settings['cancellation_reason_required'] ?? true) ? 'checked' : '' }}>
                        <span class="form-text mb-0">{{ __('admin/settings.fields_cancellation_reason_required_description') }}</span>
                    </div>
                </div>
            </div>
            <div class="row mb-2 align-items-center">
                <label for="cancellation_allow_immediate" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_cancellation_allow_immediate') }}</label>
                <div class="col-sm-8">
                    <div class="form-check form-switch d-flex align-items-center gap-2">
                        <input class="form-check-input d-inline-block" type="checkbox" id="cancellation_allow_immediate" name="cancellation_allow_immediate" value="1" {{ old('cancellation_allow_immediate', $settings['cancellation_allow_immediate'] ?? true) ? 'checked' : '' }}>
                        <span class="form-text mb-0">{{ __('admin/settings.fields_cancellation_allow_immediate_description') }}</span>
                    </div>
                </div>
            </div>
            <div class="row mb-2 align-items-center">
                <label for="cancellation_allow_end_of_period" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_cancellation_allow_end_of_period') }}</label>
                <div class="col-sm-8">
                    <div class="form-check form-switch d-flex align-items-center gap-2">
                        <input class="form-check-input d-inline-block" type="checkbox" id="cancellation_allow_end_of_period" name="cancellation_allow_end_of_period" value="1" {{ old('cancellation_allow_end_of_period', $settings['cancellation_allow_end_of_period'] ?? true) ? 'checked' : '' }}>
                        <span class="form-text mb-0">{{ __('admin/settings.fields_cancellation_allow_end_of_period_description') }}</span>
                    </div>
                </div>
            </div>

            <!-- Social Media Authentication Settings -->
            <hr class="my-4">
            <h5 class="mb-3">{{ __('admin/settings.social_media_authentication') }}</h5>

            
            @php
                $socialProviders = [
                    ['slug' => 'facebook',  'label' => 'Facebook',    'icon' => 'fab fa-facebook-f'],
                    ['slug' => 'google',    'label' => 'Google',      'icon' => 'fab fa-google'],
                    ['slug' => 'twitter',   'label' => 'X (Twitter)', 'icon' => 'fab fa-x-twitter'],
                    ['slug' => 'linkedin',  'label' => 'LinkedIn',    'icon' => 'fab fa-linkedin-in'],
                    ['slug' => 'bitbucket', 'label' => 'Bitbucket',   'icon' => 'fab fa-bitbucket'],
                    ['slug' => 'microsoft', 'label' => 'Microsoft',   'icon' => 'fab fa-microsoft'], // PRC-780
                ];
            @endphp

            <ul class="nav nav-pills mb-3 gap-1 flex-wrap" id="socialAuthTabs" role="tablist">
                @foreach($socialProviders as $sp)
                    @php $spEnabled = old('social_'.$sp['slug'].'_enabled', $settings['social_'.$sp['slug'].'_enabled'] ?? false); @endphp
                    <li class="nav-item" role="presentation">
                        <button class="nav-link {{ $loop->first ? 'active' : '' }}" id="social-{{ $sp['slug'] }}-tab"
                                data-bs-toggle="pill" data-bs-target="#social-{{ $sp['slug'] }}-pane"
                                type="button" role="tab" aria-controls="social-{{ $sp['slug'] }}-pane"
                                aria-selected="{{ $loop->first ? 'true' : 'false' }}">
                            <i class="{{ $sp['icon'] }} me-1"></i>{{ $sp['label'] }}
                            <span class="badge rounded-pill bg-{{ $spEnabled ? 'success' : 'secondary' }} ms-1">
                                {{ $spEnabled ? __('admin/settings.social_status_on') : __('admin/settings.social_status_off') }}
                            </span>
                        </button>
                    </li>
                @endforeach
            </ul>

            <div class="tab-content" id="socialAuthTabContent">
                @foreach($socialProviders as $sp)
                    @php $slug = $sp['slug']; @endphp
                    <div class="tab-pane fade {{ $loop->first ? 'show active' : '' }}" id="social-{{ $slug }}-pane"
                         role="tabpanel" aria-labelledby="social-{{ $slug }}-tab" tabindex="0">
                        <div class="row mb-2 align-items-center">
                            <label for="social_{{ $slug }}_enabled" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_social_'.$slug.'_enabled') }}</label>
                            <div class="col-sm-8">
                                <div class="form-check form-switch d-flex align-items-center gap-2">
                                    <input class="form-check-input d-inline-block" type="checkbox" id="social_{{ $slug }}_enabled" name="social_{{ $slug }}_enabled" value="1" {{ old('social_'.$slug.'_enabled', $settings['social_'.$slug.'_enabled'] ?? false) ? 'checked' : '' }}>
                                    <span class="form-text mb-0">{{ __('admin/settings.fields_social_'.$slug.'_enabled_description') }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="row mb-2">
                            <label for="social_{{ $slug }}_client_id" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_social_'.$slug.'_client_id') }}</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control w-75 d-inline-block" id="social_{{ $slug }}_client_id" name="social_{{ $slug }}_client_id" value="{{ old('social_'.$slug.'_client_id', $settings['social_'.$slug.'_client_id'] ?? '') }}">
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label for="social_{{ $slug }}_client_secret" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_social_'.$slug.'_client_secret') }}</label>
                            <div class="col-sm-8">
                                <input type="password" class="form-control w-75 d-inline-block" id="social_{{ $slug }}_client_secret" name="social_{{ $slug }}_client_secret" value="{{ old('social_'.$slug.'_client_secret', $settings['social_'.$slug.'_client_secret'] ?? '') }}">
                            </div>
                        </div>
                        
                        @if($slug === 'microsoft')
                        <div class="row mb-3">
                            <label for="social_microsoft_tenant" class="col-sm-4 text-end col-form-label">{{ __('admin/settings.fields_social_microsoft_tenant') }}</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control w-75 d-inline-block" id="social_microsoft_tenant" name="social_microsoft_tenant" value="{{ old('social_microsoft_tenant', $settings['social_microsoft_tenant'] ?? 'common') }}" placeholder="common">
                                <div class="form-text small">{{ __('admin/settings.fields_social_microsoft_tenant_description') }}</div>
                            </div>
                        </div>
                        @endif
                        <x-admin.social-setup-help :provider="$slug" :setup-key="'social_'.$slug.'_setup'" />
                    </div>
                @endforeach
            </div>
        </div>
    </div>
</div>
