@extends('layouts.dashboard') @section('title', trans('dashboard.nav_settings')) @section('header_title', trans('dashboard.nav_settings')) @section('content') @php $isAr = app()->getLocale() === 'ar'; $isSandbox = (bool) ($tenant->is_sandbox ?? true); $invoicePref = $tenant->settings['invoice_type_preference'] ?? 'both'; $taxTreatment = $tenant->settings['tax_treatment'] ?? 'standard_15'; $brandColor = $tenant->settings['brand_color'] ?? '#1D4ED8'; $currentTemplate = $tenant->settings['template'] ?? 'classic'; $savedDesigns = $tenant->settings['saved_designs'] ?? []; $logoPath = $tenant->settings['logo_path'] ?? null; $footerText = $tenant->settings['footer_text'] ?? ''; $showFooterContact = $tenant->settings['show_footer_contact'] ?? false; $showFooterTerms = $tenant->settings['show_footer_terms'] ?? false; $tabs = [ 'profile' => ['ar' => 'ملف المنشأة', 'en' => 'Company Profile', 'icon' => 'fa-building'], 'certificate' => ['ar' => 'الربط والشهادة', 'en' => 'Connection & Certificate', 'icon' => 'fa-certificate'], 'stores' => ['ar' => 'ربط المتاجر', 'en' => 'Store Integration', 'icon' => 'fa-store'], 'template' => ['ar' => 'قالب الفاتورة', 'en' => 'Invoice Template', 'icon' => 'fa-file-invoice'], 'users' => ['ar' => 'المستخدمون', 'en' => 'Users', 'icon' => 'fa-users'], 'api' => ['ar' => 'واجهة API', 'en' => 'API Interface', 'icon' => 'fa-code'], ]; @endphp
{{-- ===== SIDEBAR NAV ===== --}} {{-- ===== MOBILE TAB SELECT ===== --}}
{{-- ===== CONTENT AREA ===== --}}
{{-- Global success / error --}} @if(session('success'))
{{ session('success') }}
@endif @if($errors->any())
    @foreach($errors->all() as $e)
  • {{ $e }}
  • @endforeach
@endif {{-- ============================================================ TAB 1: ملف المنشأة ============================================================ --}} @if($activeTab === 'profile') {{-- Sandbox warning --}} @if($isSandbox)
{{ $isAr ? 'أنت في البيئة التجريبية — الفواتير لا تُرسل إلى فاتورة الفعلي.' : 'You are in sandbox mode — invoices are not sent to the live Fatoora platform.' }}
@endif {{-- Missing-fields pills --}} @if(count($missingFields) > 0)

{{ $isAr ? 'حقول مطلوبة لتفعيل الربط:' : 'Required fields for connection:' }}

@foreach($missingFields as $field) {{ $field }} @endforeach
@endif
@csrf @method('PUT') {{-- اسم المنشأة --}}
{{-- VAT + Org Identifier --}}
@if($tenant->vat_number)
{{ $tenant->vat_number }} {{ $isAr ? 'لا يمكن تغييره' : 'Cannot change' }}
@else @endif

{{ $isAr ? 'رقم السجل التجاري 10 أرقام' : 'CR number is 10 digits' }}

{{-- النشاط التجاري --}}
{{-- العنوان الوطني المختصر --}}

{{ $isAr ? 'اضغط «جلب العنوان» لتعبئة الشارع والمدينة والرمز البريدي تلقائياً' : 'Click "Fetch Address" to auto-fill address fields' }}

{{-- الشارع + رقم المبنى --}}
{{-- المدينة + الحي --}}
{{-- الرمز البريدي --}}

{{-- نوع الفواتير --}}

{{ $isAr ? 'تغيير نوع الفواتير يتطلب إعادة إصدار الشهادة ليسري على الربط' : 'Changing invoice type requires re-issuing the certificate' }}

{{-- المعاملات الضريبية --}}
{{-- ===== BRANCHES SECTION ===== --}}

{{ $isAr ? 'الفروع' : 'Branches' }}

{{ $isAr ? 'أضف فروع منشأتك إذا كانت لديك أكثر من موقع. كل فرع يظهر كخيار عند إنشاء الفاتورة.' : 'Add branches for multiple locations. Each branch appears as an option when creating invoices.' }}

@csrf

{{ $isAr ? 'الشارع والحي والمدينة والرمز البريدي أُستخرج منه تلقائياً' : 'Street, district, city and postal code extracted automatically' }}

@if(count($branches) > 0)
@foreach($branches as $branch)

{{ $branch['name'] }}

@if(!empty($branch['cr_number']))

{{ $branch['cr_number'] }}

@endif @if(!empty($branch['short_address']))

{{ $branch['short_address'] }}

@endif
@csrf @method('DELETE')
@endforeach
@endif
@endif {{-- ============================================================ TAB 2: الربط والشهادة ============================================================ --}} @if($activeTab === 'certificate') @if($isSandbox)

{{ $isAr ? 'أنت في وضع التجربة' : 'You are in Sandbox Mode' }}

{{ $isAr ? 'بيئة الاختبار تتيح لك إنشاء فواتير وإرسالها دون أثر قانوني. عند الجاهزية، حوّل إلى التشغيل الفعلي.' : 'The sandbox lets you create and submit invoices with no legal effect. When ready, switch to production.' }}

@endif @if($device)
{{-- Connection status --}}

{{ $isAr ? 'حالة الاتصال' : 'Connection Status' }}

{{ $isAr ? 'منصة فاتورة' : 'Fatoora Platform' }} {{ $isAr ? '✓ متصلة' : '✓ Connected' }}
{{ $isAr ? 'البيئة' : 'Environment' }} {{ ! $tenant->is_sandbox ? ($isAr ? 'الإنتاج' : 'Production') : ($isAr ? 'البيئة التجريبية' : 'Sandbox') }}
{{ $isAr ? 'نوع الحل' : 'Solution Type' }} ZATCA Tools Cloud
{{ $isAr ? 'معرّف الجهاز' : 'Device ID' }} {{ Str::limit($device->uuid ?? $device->id, 18, '…') }}
{{-- Certificate status --}}

{{ $isAr ? 'شهادة الإنتاج (PCSID)' : 'Production Certificate (PCSID)' }}

@php $hasCert = filled($device->certificate_pem); $certExpiry = $device->certificate_expires_at ?? null; $isExpired = $certExpiry && now()->greaterThan($certExpiry); @endphp
@if($hasCert && !$isExpired) {{ $isAr ? '✓ صالحة' : '✓ Valid' }} @elseif($isExpired) {{ $isAr ? '✗ منتهية' : '✗ Expired' }} @else {{ $isAr ? '— لا توجد شهادة' : '— No Certificate' }} @endif
@if($device->created_at)
{{ $isAr ? 'تاريخ الربط' : 'Linked On' }} {{ $device->created_at->format('Y/m/d') }}
@endif @if($certExpiry)
{{ $isAr ? 'تنتهي في' : 'Expires' }} {{ \Carbon\Carbon::parse($certExpiry)->format('Y/m/d') }}
@endif
@else
{{ $isAr ? 'لا يوجد جهاز مسجل بعد. أكمل خطوات الربط.' : 'No device registered yet. Complete the connection steps.' }}
@endif @endif {{-- ============================================================ TAB 3: ربط المتاجر ============================================================ --}} @if($activeTab === 'stores')

{{ $isAr ? 'ربط المتاجر' : 'Store Integration' }}

{{ $isAr ? 'قريباً — سيتمكن كل متجر إلكتروني من إرسال طلباته مباشرةً لإنشاء الفاتورة تلقائياً.' : 'Coming soon — your online stores will be able to send orders directly to auto-generate invoices.' }}

{{ $isAr ? 'قريباً' : 'Coming Soon' }}
@endif {{-- ============================================================ TAB 4: قالب الفاتورة ============================================================ --}} @if($activeTab === 'template') @php $templates = [ 'classic' => ['ar' => 'كلاسيكي', 'en' => 'Classic', 'desc_ar' => 'خطوط رفيعة وخط مطبعة هادئ — أقرب لورق الفاتورة التقليدي.', 'desc_en' => 'Thin lines and calm typeface — closest to traditional paper receipts.'], 'modern' => ['ar' => 'حديث', 'en' => 'Modern', 'desc_ar' => 'جداول ملونة وخط واضح — التصميم الافتراضي المعتمد.', 'desc_en' => 'Coloured tables and clear text — the modern default design.'], 'bold' => ['ar' => 'جريء', 'en' => 'Bold', 'desc_ar' => 'شريط علوي عريض بلون هويتك يحمل الشعار والعنوان.', 'desc_en' => 'Bold brand-colour header bar with logo and address.'], 'simple' => ['ar' => 'بسيط', 'en' => 'Simple', 'desc_ar' => 'أبيض وأسود بلا زخرفة — مساحات واسعة، أرقام فقط.', 'desc_en' => 'Black & white, no decoration — clean spaces, numbers only.'], 'formal' => ['ar' => 'رسمي', 'en' => 'Formal', 'desc_ar' => 'إطار رسمي وجداول محددة وصناديق معتمدة للأطراف.', 'desc_en' => 'Formal bordered layout with distinct party boxes and grid.'], ]; $curatedPresets = [ 'كلاسيكي ملكي' => [ 'template' => 'classic', 'brand_color' => '#1D4ED8', 'name_ar' => 'كلاسيكي ملكي', 'name_en' => 'Royal Classic', 'desc' => $isAr ? 'أزرق ملكي متزن وخطوط واضحة' : 'Royal blue balanced layout', ], 'حديث بترولي' => [ 'template' => 'modern', 'brand_color' => '#0D9488', 'name_ar' => 'حديث بترولي', 'name_en' => 'Modern Teal', 'desc' => $isAr ? 'عصري هادئ برأسية بترولية' : 'Calm teal header bar', ], 'جريء زمردي' => [ 'template' => 'bold', 'brand_color' => '#16A34A', 'name_ar' => 'جريء زمردي', 'name_en' => 'Bold Emerald', 'desc' => $isAr ? 'شريط عريض بلون أخضر رسمي' : 'Prominent brand top header', ], 'بسيط نقي' => [ 'template' => 'simple', 'brand_color' => '#0F172A', 'name_ar' => 'بسيط نقي', 'name_en' => 'Simple Minimal', 'desc' => $isAr ? 'أبيض وأسود صريح بلا زخارف' : 'Clean black & white format', ], 'رسمي عنابي' => [ 'template' => 'formal', 'brand_color' => '#DC2626', 'name_ar' => 'رسمي عنابي', 'name_en' => 'Formal Crimson', 'desc' => $isAr ? 'إطار رسمي وجداول تعاقدية' : 'Official bordered contract grid', ], ]; @endphp
{{-- Left: Preview + Template picker --}}
{{-- Preview box --}}
{{ $isAr ? 'معاينة حية للمستند' : 'Live Document Preview' }}

{{ $isAr ? 'المعاينة تُبيّن بالضبط الشكل الذي يصدر الفاتورة الحقيقية — اختر قالباً ولوناً واضغط حفظ لتطبيقه على الفواتير الجديدة.' : 'Preview shows exactly how real invoices look. Pick a template and color, then save.' }}

{{-- Template cards --}}
@csrf @method('PUT')

{{ $isAr ? 'قالب الفاتورة' : 'Invoice Template' }}

{{ $isAr ? 'الشكل الذي تصل به فاتورتك للعميل في الـ PDF والمطبوعات. محتوى البيانات الضريبية ثابت وفق متطلبات هيئة الزكاة والضريبة والجمارك.' : 'The look of your invoice in PDF and printouts. Tax data conforms to ZATCA rules.' }}

@foreach($templates as $tKey => $tData) @endforeach
{{-- Branding section --}}

{{ $isAr ? 'هويتك وألوانك' : 'Your Brand & Colors' }}

{{-- Brand color --}}
@foreach(['#0F172A','#DC2626','#B45309','#7C3AED','#2563EB','#0D9488','#16A34A'] as $presetColor) @endforeach
{{-- Logo --}}
@if($logoPath) Logo @else @endif

{{ $isAr ? 'PNG أو JPG · بحد أقصى 1 ميجابايت · يفضّل خلفية شفافة' : 'PNG or JPG · max 1MB · transparent background preferred' }}

@if($logoPath) @endif
{{-- Footer details accordion --}}
{{ $isAr ? 'نصوص وخيارات أسفل الفاتورة (التواصل، الشروط، الملاحظات)' : 'Footer details (contact info, terms, notes)' }}

{{ $isAr ? 'يسري على المستندات الجديدة — وما صدر قبل ذلك يحتفظ بتصميمه المعتمد.' : 'Applies to new documents — previously issued ones keep their original look.' }}

{{-- Right: Saved designs (Curated 5 + Custom) --}}
{{-- 5 Ready Presets Card --}}

{{ $isAr ? 'الأشكال الخمسة الجاهزة' : '5 Ready Styles' }}

{{ $isAr ? '5 قوالب' : '5 Styles' }}

{{ $isAr ? 'اضغط «معاينة وتطبيق» على أي شكل لتجربته حياً في المعاينة الفورية، ثم احفظ اختيارك:' : 'Click preview on any style to see it live, then save your choice:' }}

@foreach($curatedPresets as $presetKey => $preset)

{{ $isAr ? $preset['name_ar'] : $preset['name_en'] }}

{{ $preset['desc'] }}

@endforeach
{{-- Custom Saved Designs Card --}}

{{ $isAr ? 'تصاميمي المخصصة المحفوظة' : 'My Custom Saved Designs' }}

{{ $isAr ? 'يمكنك حفظ تشكيلتك الحالية كقالب مخصص باسم لتطبيقه في أي وقت.' : 'Save your current look by custom name to apply anytime.' }}

@if(count($savedDesigns) > 0)
@foreach($savedDesigns as $designName => $design)
{{ $designName }} {{ $design['template'] ?? 'classic' }}
@csrf
@csrf @method('DELETE')
@endforeach
@else
{{ $isAr ? 'لم تحفظ أي تصميم باسم بعد. اكتب اسماً بالأسفل لحفظ التصميم الحالي.' : 'No custom designs saved yet. Name the current look below.' }}
@endif
@csrf
{{-- ===== ENLARGE PREVIEW MODAL ===== --}} @endif {{-- ============================================================ TAB 5: المستخدمون ============================================================ --}} @if($activeTab === 'users')

{{ $isAr ? 'المستخدمون' : 'Team Members' }}

{{-- Invite form --}} @if($user->role === 'owner')
@csrf
@endif {{-- Members list --}}
@foreach($teamMembers as $member)
{{-- Avatar --}} @if($member->avatar) @else
{{ strtoupper(substr($member->name ?: $member->email, 0, 1)) }}
@endif

{{ $member->email }}

@if($member->name)

{{ $member->name }}

@endif
{{-- Role badge --}} {{ $member->role === 'owner' ? ($isAr ? 'مالك' : 'Owner') : ($isAr ? 'محاسب' : 'Accountant') }} {{-- Remove button (owner only, not self) --}} @if($user->role === 'owner' && $member->id !== $user->id && $member->role !== 'owner')
@csrf @method('DELETE')
@endif
@endforeach

{{ $isAr ? 'المستخدم المدعو يدخل بنفس بريده عبر رمز التحقق — بدون كلمات مرور.' : 'Invited users sign in with their email OTP — no passwords.' }}

@endif {{-- ============================================================ TAB 6: واجهة API ============================================================ --}} @if($activeTab === 'api')
@if(session('new_raw_key'))

{{ $isAr ? '⚠ انسخ المفتاح الآن — لن يظهر مجدداً' : '⚠ Copy the key now — it will never be shown again' }}

{{ session('new_raw_key') }}
@endif {{-- Create key form --}}
@csrf

{{ $isAr ? 'إنشاء مفتاح API جديد' : 'Create New API Key' }}

{{-- Keys list --}} @if($apiKeys->isNotEmpty())

{{ $isAr ? 'المفاتيح الحالية' : 'Current Keys' }}

@foreach($apiKeys as $key)

{{ $key->name }}

{{ $key->key_prefix }}

{{ $key->environment === 'production' ? ($isAr ? 'إنتاج' : 'Production') : ($isAr ? 'تجريبية' : 'Sandbox') }} {{ $key->is_active ? ($isAr ? 'نشط' : 'Active') : ($isAr ? 'معطل' : 'Disabled') }}
@endforeach
@endif
@endif
{{-- end content --}}
{{-- end flex --}} @push('scripts') @endpush @endsection