<div>
    <div class="page-header">
        <h1 class="page-title">{{ __('General Settings') }}</h1>
        <p class="text-muted mb-0">{{ __('Configure your shop and system preferences') }}</p>
    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    @if(session('error'))
        <div class="alert alert-danger alert-dismissible fade show">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    <form wire:submit="save">
        <div class="row">
            <!-- Shop Information -->
            <div class="col-lg-6 mb-4">
                <div class="card h-100">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0"><i class="fas fa-store me-2"></i>{{ __('Shop Information') }}</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">{{ __('Shop Name') }} <span class="text-danger">*</span></label>
                            <input type="text" class="form-control @error('shop_name') is-invalid @enderror" 
                                   wire:model="shop_name">
                            @error('shop_name') <div class="invalid-feedback">{{ $message }}</div> @enderror
                        </div>
                        <div class="mb-3">
                            <label class="form-label">{{ __('Shop Name (Arabic)') }}</label>
                            <input type="text" class="form-control" wire:model="shop_name_ar" dir="rtl">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">{{ __('Address') }}</label>
                            <textarea class="form-control" rows="2" wire:model="shop_address"></textarea>
                        </div>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">{{ __('Phone') }}</label>
                                <input type="text" class="form-control" wire:model="shop_phone">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">{{ __('Email') }}</label>
                                <input type="email" class="form-control @error('shop_email') is-invalid @enderror" 
                                       wire:model="shop_email">
                                @error('shop_email') <div class="invalid-feedback">{{ $message }}</div> @enderror
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">{{ __('Tax Number') }}</label>
                            <input type="text" class="form-control" wire:model="tax_number">
                        </div>
                        <div class="mb-3">
                            <label class="form-label">{{ __('Logo') }}</label>
                            <input type="file" class="form-control" wire:model="logo" accept="image/*">
                            @if($currentLogo)
                                <img src="{{ $currentLogo }}" alt="Logo" class="mt-2" style="max-height: 60px;">
                            @endif
                        </div>
                    </div>
                </div>
            </div>

            <!-- Regional Settings -->
            <div class="col-lg-6 mb-4">
                <div class="card h-100">
                    <div class="card-header bg-info text-white">
                        <h5 class="mb-0"><i class="fas fa-globe me-2"></i>{{ __('Regional Settings') }}</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">{{ __('Currency') }}</label>
                                <select class="form-select" wire:model="default_currency">
                                    <option value="EGP">EGP - Egyptian Pound</option>
                                    <option value="USD">USD - US Dollar</option>
                                    <option value="EUR">EUR - Euro</option>
                                    <option value="SAR">SAR - Saudi Riyal</option>
                                    <option value="AED">AED - UAE Dirham</option>
                                </select>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">{{ __('Default Language') }}</label>
                                <select class="form-select" wire:model="default_language">
                                    <option value="en">English</option>
                                    <option value="ar">العربية</option>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">{{ __('Timezone') }}</label>
                                <select class="form-select" wire:model="timezone">
                                    <option value="Africa/Cairo">Cairo (UTC+2)</option>
                                    <option value="Asia/Riyadh">Riyadh (UTC+3)</option>
                                    <option value="Asia/Dubai">Dubai (UTC+4)</option>
                                    <option value="UTC">UTC</option>
                                </select>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">{{ __('Date Format') }}</label>
                                <select class="form-select" wire:model="date_format">
                                    <option value="Y-m-d">2026-01-31</option>
                                    <option value="d/m/Y">31/01/2026</option>
                                    <option value="m/d/Y">01/31/2026</option>
                                    <option value="d-M-Y">31-Jan-2026</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Sales Settings -->
            <div class="col-lg-12 mb-4">
                <div class="card h-100">
                     <div class="card-header bg-success text-white">
                        <h5 class="mb-0"><i class="fas fa-cash-register me-2"></i>{{ __('Sales Settings') }}</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">{{ __('Sales Mode') }}</label>
                            <select wire:model="sales_mode" class="form-select">
                                <option value="item">{{ __('Item Sales (Standard)') }}</option>
                                <option value="daily">{{ __('Daily Aggregate Sales') }}</option>
                            </select>
                            <small class="text-muted">{{ __('Choose between detailed item-level sales or daily aggregate sales by payment method.') }}</small>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">{{ __('POS Selling Locations') }}</label>
                            <div class="bg-light p-3 border rounded">
                                @foreach($locations as $loc)
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" 
                                               value="{{ $loc->id }}" 
                                               id="loc_{{ $loc->id }}"
                                               wire:model="pos_selling_locations">
                                        <label class="form-check-label" for="loc_{{ $loc->id }}">
                                            {{ $loc->name }}
                                        </label>
                                    </div>
                                @endforeach
                                @if($locations->isEmpty())
                                    <p class="text-muted small mb-0">{{ __('No active locations found.') }}</p>
                                @endif
                            </div>
                            <small class="text-muted">{{ __('Select locations POS can pull stock from (in order).') }}</small>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Receipt Settings -->
            <div class="col-lg-6 mb-4">
                <div class="card h-100">
                    <div class="card-header bg-secondary text-white">
                        <h5 class="mb-0"><i class="fas fa-receipt me-2"></i>{{ __('Receipt Settings') }}</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">{{ __('Receipt Header') }}</label>
                            <textarea class="form-control" rows="2" wire:model="receipt_header" 
                                      placeholder="{{ __('Text to show at top of receipt') }}"></textarea>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">{{ __('Receipt Footer') }}</label>
                            <textarea class="form-control" rows="2" wire:model="receipt_footer"
                                      placeholder="{{ __('Thank you message, return policy, etc.') }}"></textarea>
                        </div>
                        <div class="mb-3">
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" wire:model="print_receipt_auto" id="autoPrint">
                                <label class="form-check-label" for="autoPrint">{{ __('Auto Print Receipt') }}</label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Security Settings (Super Admin Only) -->
            @if(auth()->user()->isSuperAdmin())
                <div class="col-lg-6 mb-4">
                    <div class="card h-100">
                        <div class="card-header bg-danger text-white">
                            <h5 class="mb-0"><i class="fas fa-lock me-2"></i>{{ __('Security Settings') }}</h5>
                        </div>
                        <div class="card-body">
                            <div class="mb-3">
                                <label class="form-label">{{ __('POS Discount Password') }}</label>
                                <input type="text" class="form-control" wire:model="pos_discount_password" 
                                       placeholder="Enter password to authorize discounts">
                                <small class="text-muted">{{ __('Required to authorize discounts in POS.') }}</small>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">{{ __('Inventory Adjustment Password') }}</label>
                                <input type="text" class="form-control" wire:model="inventory_adjustment_password" 
                                       placeholder="Enter password to authorize adjustments">
                                <small class="text-muted">{{ __('Required to submit inventory adjustments.') }}</small>
                            </div>
                        </div>
                    </div>
                </div>
            @endif
        </div>

        <div class="text-end mb-4">
            <button type="submit" class="btn btn-primary btn-lg">
                <i class="fas fa-save me-2"></i>{{ __('Save Settings') }}
            </button>
        </div>
    </form>
</div>
