@extends('layouts.admin')
@section('title','Pengaturan Sistem')
@section('content')
<ul class="nav nav-tabs mb-3">
  <li class="nav-item"><a class="nav-link {{ !request()->routeIs('admin.settings.sla','admin.settings.activity')?'active':'' }}" href="{{ route('admin.settings.index') }}">Perusahaan</a></li>
  <li class="nav-item"><a class="nav-link {{ request()->routeIs('admin.settings.sla')?'active':'' }}" href="{{ route('admin.settings.sla') }}">SLA Config</a></li>
  <li class="nav-item"><a class="nav-link {{ request()->routeIs('admin.settings.activity')?'active':'' }}" href="{{ route('admin.settings.activity') }}">Activity Log</a></li>
</ul>
<form action="{{ route('admin.settings.update') }}" method="POST" enctype="multipart/form-data">@csrf
@foreach(['JPN','FixLab','Havva'] as $div)
@php $s = $settings[$div] ?? null; @endphp
<div class="card mb-3">
  <div class="card-header fw-bold">Divisi {{ $div }}</div>
  <div class="card-body">
    <div class="row g-3">
      <div class="col-md-6"><label class="form-label small fw-semibold">Nama Perusahaan</label><input type="text" name="{{ $div }}[company_name]" class="form-control form-control-sm" value="{{ old($div.'.company_name',$s->company_name??'') }}"></div>
      <div class="col-md-6"><label class="form-label small fw-semibold">Email</label><input type="email" name="{{ $div }}[email]" class="form-control form-control-sm" value="{{ old($div.'.email',$s->email??'') }}"></div>
      <div class="col-md-6"><label class="form-label small fw-semibold">Telepon</label><input type="text" name="{{ $div }}[phone]" class="form-control form-control-sm" value="{{ old($div.'.phone',$s->phone??'') }}"></div>
      <div class="col-12"><label class="form-label small fw-semibold">Alamat</label><textarea name="{{ $div }}[address]" class="form-control form-control-sm" rows="2">{{ old($div.'.address',$s->address??'') }}</textarea></div>
      <div class="col-md-4"><label class="form-label small fw-semibold">Nama Bank</label><input type="text" name="{{ $div }}[bank_name]" class="form-control form-control-sm" value="{{ old($div.'.bank_name',$s->bank_name??'') }}"></div>
      <div class="col-md-4"><label class="form-label small fw-semibold">No. Rekening</label><input type="text" name="{{ $div }}[bank_account]" class="form-control form-control-sm" value="{{ old($div.'.bank_account',$s->bank_account??'') }}"></div>
      <div class="col-md-4"><label class="form-label small fw-semibold">Atas Nama</label><input type="text" name="{{ $div }}[bank_account_name]" class="form-control form-control-sm" value="{{ old($div.'.bank_account_name',$s->bank_account_name??'') }}"></div>
      <div class="col-12"><label class="form-label small fw-semibold">Footer Invoice</label><textarea name="{{ $div }}[invoice_footer]" class="form-control form-control-sm" rows="2">{{ old($div.'.invoice_footer',$s->invoice_footer??'') }}</textarea></div>
      <div class="col-12"><label class="form-label small fw-semibold">Logo</label><input type="file" name="{{ $div }}[logo]" class="form-control form-control-sm" accept="image/*">@if($s?->logo_path)<div class="mt-1"><img src="{{ asset('storage/'.$s->logo_path) }}" style="height:40px"></div>@endif</div>
      <hr>
      <div class="col-12"><h6 class="fw-semibold mb-2">Pengaturan CSAT Survey</h6></div>
      <div class="col-md-6"><label class="form-label small fw-semibold">CSAT Auto-Send</label>
        <select name="{{ $div }}[csat_auto_send]" class="form-select form-select-sm">
          <option value="1" {{ old($div.'.csat_auto_send',$s->csat_auto_send??true)?'selected':'' }}>Otomatis (saat kunjungan selesai)</option>
          <option value="0" {{ !old($div.'.csat_auto_send',$s->csat_auto_send??true)?'selected':'' }}>Manual (kirim sesuai tombol)</option>
        </select>
      </div>
      <div class="col-md-6"><label class="form-label small fw-semibold">Channel Default</label>
        <select name="{{ $div }}[csat_default_channel]" class="form-select form-select-sm">
          <option value="whatsapp" {{ ($s->csat_default_channel??'whatsapp')==='whatsapp'?'selected':'' }}>WhatsApp</option>
          <option value="email" {{ ($s->csat_default_channel??'whatsapp')==='email'?'selected':'' }}>Email</option>
          <option value="telegram" {{ ($s->csat_default_channel??'whatsapp')==='telegram'?'selected':'' }}>Telegram</option>
        </select>
      </div>
    </div>
  </div>
</div>
@endforeach
<div class="d-flex justify-content-end"><button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>Simpan Pengaturan</button></div>
</form>
@endsection
