@extends('dashboard') {{-- Apnar layout onujayi change kore nin --}}
@section('title','Admin Settings')
@section('page_content')
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-dark">
                    <h5 class="mb-0">System Settings</h5>
                </div>
                <div class="card-body">
                    @if(session('success'))
                        <div class="alert alert-success">{{ session('success') }}</div>
                    @endif

                    <form action="{{ route('settings.update') }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        
                        <div class="mb-3">
                            <label class="form-label">Company Name <span class="text-danger">*</span></label>
                            <input type="text" name="company_name" class="form-control @error('company_name') is-invalid @enderror" value="{{ old('company_name', $setting->company_name ?? '') }}" required>
                            @error('company_name') <span class="text-danger small">{{ $message }}</span> @enderror
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Address <span class="text-danger">*</span></label>
                            <textarea name="address" class="form-control @error('address') is-invalid @enderror" rows="2" required>{{ old('address', $setting->address ?? '') }}</textarea>
                            @error('address') <span class="text-danger small">{{ $message }}</span> @enderror
                        </div>

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Mobile Number <span class="text-danger">*</span></label>
                                <input type="text" name="mobile_number" class="form-control @error('mobile_number') is-invalid @enderror" value="{{ old('mobile_number', $setting->mobile_number ?? '') }}" required>
                                @error('mobile_number') <span class="text-danger small">{{ $message }}</span> @enderror
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Mobile Number (Optional)</label>
                                <input type="text" name="mobile_number_optional" class="form-control" value="{{ old('mobile_number_optional', $setting->mobile_number_optional ?? '') }}">
                            </div>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Location (Google Map Link)</label>
                            <input type="url" name="location" class="form-control @error('location') is-invalid @enderror" value="{{ old('location', $setting->location ?? '') }}">
                            @error('location') <span class="text-danger small">{{ $message }}</span> @enderror
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Login Image</label>
                            <input type="file" name="login_image" class="form-control @error('login_image') is-invalid @enderror" accept="image/*">
                            @error('login_image') <span class="text-danger small">{{ $message }}</span> @enderror
                            
                            {{-- Image Preview --}}
                            @if(isset($setting) && $setting->login_image)
                                <div class="mt-2">
                                    <p class="small text-muted mb-1">Current Image:</p>
                                    <img src="{{ asset('uploads/login/' . $setting->login_image) }}" alt="Login Image" class="img-thumbnail" width="150">
                                </div>
                            @endif
                        </div>

                        <div class="text-end">
                            <button type="submit" class="btn btn-primary px-4">Save Settings</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection