@extends('dashboard.layout')

@section('title', 'Support')

@section('content')
<style>
  body { background-color: var(--mob-bg); }
  
  @media (min-width: 768px) {
    body { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--mob-border); border-right: 1px solid var(--mob-border); box-shadow: 0 0 50px rgba(0,0,0,0.1); position: relative; min-height: 100vh; }
    .mob-bottom-nav, .modal-sheet, .toast-notif, .ios-modal-sheet { max-width: 480px; margin: 0 auto; left: 0; right: 0; }
  }
  
  .sup-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; padding-top: max(20px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 100; }
  .sup-header h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.5px; color: var(--mob-text); }

  .sup-hero-card { background: var(--mob-primary); border-radius: var(--mob-radius-lg); padding: 24px; margin: 10px 20px 24px 20px; color: white; box-shadow: var(--mob-shadow-md); }
  .sup-hero-card h2 { font-size: 24px; font-weight: 800; margin: 0 0 6px 0; letter-spacing: -0.5px; }
  .sup-hero-card p { font-size: 15px; color: rgba(255, 255, 255, 0.8); margin: 0; line-height: 1.4; }

  .compact-security-card { background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--mob-radius-md); margin: 0 20px 32px 20px; padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: var(--mob-shadow-sm); }
  
  .csc-left { display: flex; align-items: center; gap: 12px; flex: 1; }
  .csc-icon { color: #ef4444; display: flex; align-items: center; justify-content: center; }
  .csc-icon svg { width: 24px; height: 24px; stroke-width: 2px; }
  
  .csc-text h4 { margin: 0 0 2px 0; font-size: 15px; font-weight: 700; color: #991b1b; }
  
  .csc-text p { margin: 0; font-size: 13px; color: #b91c1c; font-weight: 500; line-height: 1.4; }
  
  .btn-csc-freeze { background: #ef4444; color: white; border: none; padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap; transition: transform 0.2s; }
  .btn-csc-freeze:active { transform: scale(0.96); }

  .sup-section-title { margin: 0 24px 12px 24px; font-size: 14px; font-weight: 700; color: var(--mob-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
  .sup-contact-grid { display: flex; flex-direction: column; gap: 16px; margin: 0 20px 32px 20px; }
  .sup-contact-card { background: var(--mob-surface); border: 1px solid var(--mob-border); border-radius: var(--mob-radius-lg); padding: 20px; display: flex; flex-direction: row; align-items: center; gap: 16px; box-shadow: var(--mob-shadow-sm); transition: transform 0.2s; cursor: pointer; text-align: left; width: 100%; }
  .sup-contact-card:active { transform: scale(0.96); }
  .sup-contact-icon { width: 48px; height: 48px; flex-shrink: 0; background: var(--mob-primary-dim); color: var(--mob-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
  .sup-contact-icon svg { width: 24px; height: 24px; stroke-width: 2.5px; }
  .sup-contact-card-text { flex: 1; }
  .sup-contact-card h4 { margin: 0 0 6px 0; font-size: 16px; font-weight: 700; color: var(--mob-text); }
  .sup-contact-card p { margin: 0; font-size: 13px; color: var(--mob-text-muted); font-weight: 500; line-height: 1.4; }

  .modal-overlay { position: fixed; inset: 0; background: rgba(5, 16, 36, 0.6); z-index: 300; display: none; opacity: 0; transition: opacity 0.3s; }
  .modal-sheet { position: fixed; bottom: 0; left: 0; right: 0; background: var(--mob-bg); border-radius: 24px 24px 0 0; z-index: 301; transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); padding: 24px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .modal-sheet.open { transform: translateY(0); }
  .modal-overlay.open { display: block; opacity: 1; }
  
  .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
  .modal-header h2 { margin: 0; font-size: 20px; font-weight: 800; color: var(--mob-text); }
  .modal-close-btn { background: var(--mob-surface); border: 1px solid var(--mob-border); width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; }

  .form-group { margin-bottom: 24px; }
  .form-group label { display: block; font-size: 14px; font-weight: 600; color: var(--mob-text); margin-bottom: 8px; }
  .form-control { width: 100%; box-sizing: border-box; background: var(--mob-surface); border: 1px solid var(--mob-border); padding: 14px 16px; border-radius: 12px; font-size: 16px; outline: none; transition: 0.2s; font-family: 'Inter', sans-serif; }
  .form-control:focus { border-color: var(--mob-primary); box-shadow: 0 0 0 3px var(--mob-primary-dim); }
  
  .btn-submit-freeze { background: #ef4444; color: white; border: none; padding: 16px 20px; border-radius: 12px; font-weight: 700; width: 100%; cursor: pointer; font-size: 15px; transition: transform 0.2s; }
  .btn-submit-freeze:active { transform: scale(0.96); }

  .toast-notif { position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-100px); background: var(--mob-primary); color: white; padding: 12px 24px; border-radius: 20px; font-size: 14px; font-weight: 600; box-shadow: var(--mob-shadow-md); z-index: 999; transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); text-align: center; width: auto; white-space: nowrap; }
  .toast-notif.show { transform: translateX(-50%) translateY(0); }
  
  .mob-nav-icon svg { width: 24px; height: 24px; stroke-width: 2px; margin-bottom: 2px; }
</style>

<div id="toast" class="toast-notif">Message</div>

<header class="sup-header">
  <div style="display: flex; align-items: center; gap: 12px;">
    <h1 style="margin: 0; font-size: 18px; font-weight: 800; color: var(--mob-text);">Support</h1>
  </div>
  
  <div style="display: flex; gap: 8px; align-items: center;">
    <button class="mob-avatar-mini" onclick="openProfileMenu()">
      {{ strtoupper(substr($user->name, 0, 1)) }}
    </button>
  </div>
</header>

<main class="mob-main-content" style="padding-top: 0; padding-bottom: 100px;">
  
  

  <div class="sup-hero-card">
    <h2>Welcome, {{ $user->name }}</h2>
    <p>How can we assist you with your account today?</p>
  </div>

  <div class="compact-security-card ">
    <div class="csc-left">
      <div class="csc-icon">
        <i data-lucide="shield-alert"></i>
      </div>
      <div class="csc-text">
        <h4>Account Security</h4>
        
          <p>If you suspect unauthorized activity, freeze your account immediately.</p>
        
      </div>
    </div>
    <div class="csc-right">
      
        <button class="btn-csc-freeze" onclick="openFreezeModal()">Freeze</button>
      
    </div>
  </div>

  <h3 class="sup-section-title">Contact Us</h3>
  <div class="sup-contact-grid">
    <button class="sup-contact-card" onclick="openTicketModal()">
      <div class="sup-contact-icon"><i data-lucide="message-square"></i></div>
      <div class="sup-contact-card-text">
        <h4>Live Chat</h4>
        <p>Connect securely with an agent in real-time. Best for urgent account inquiries.</p>
      </div>
    </button>
    
    <button class="sup-contact-card" onclick="openEmailModal()">
      <div class="sup-contact-icon"><i data-lucide="mail"></i></div>
      <div class="sup-contact-card-text">
        <h4>Email Support</h4>
        <p>Reach out to our dedicated teams for document submission or compliance matters.</p>
      </div>
    </button>
  </div>

  <h3 class="sup-section-title">My Tickets</h3>
  <div class="settings-card">
    @forelse ($tickets as $ticket)
      <div class="settings-row">
        <div class="settings-info">
          <div class="settings-label">{{ $ticket->subject }}</div>
          <div class="settings-value" style="font-size: 13px;">{{ $ticket->created_at->format('M d, Y') }} · {{ ucfirst($ticket->status) }}</div>
        </div>
        <div class="settings-icon"><i data-lucide="chevron-right"></i></div>
      </div>
    @empty
      <div class="settings-row">
        <div class="settings-info">
          <div class="settings-value" style="color: var(--mob-text-muted);">No tickets yet</div>
        </div>
      </div>
    @endforelse
  </div>

</main>

<div class="modal-overlay" id="ticketOverlay" onclick="closeTicketModal()"></div>
<div class="modal-sheet" id="ticketSheet">
  <div class="modal-header">
    <h2>Submit a Ticket</h2>
    <button class="modal-close-btn" onclick="closeTicketModal()"><i data-lucide="x" style="width: 16px; color: var(--mob-text);"></i></button>
  </div>

  <form method="POST" action="{{ route('support.store') }}">
    @csrf
    <div class="form-group">
      <label>Subject</label>
      <input type="text" name="subject" class="form-control" placeholder="Brief description of your issue" required>
    </div>
    <div class="form-group">
      <label>Priority</label>
      <select name="priority" class="form-control">
        <option value="low">Low</option>
        <option value="medium" selected>Medium</option>
        <option value="high">High</option>
        <option value="urgent">Urgent</option>
      </select>
    </div>
    <div class="form-group">
      <label>Message</label>
      <textarea name="message" class="form-control" rows="4" placeholder="Describe your issue in detail..." required></textarea>
    </div>
    <button type="submit" class="btn-submit-freeze">Submit Ticket</button>
  </form>
</div>

<div class="modal-overlay" id="emailOverlay" onclick="closeEmailModal()"></div>
<div class="modal-sheet" id="emailSheet">
  <div class="modal-header">
    <h2>Email Support</h2>
    <button class="modal-close-btn" onclick="closeEmailModal()"><i data-lucide="x" style="width: 16px; color: var(--mob-text);"></i></button>
  </div>

  <div class="settings-card" style="margin: 0;">
    <div class="settings-row">
      <div class="settings-info">
        <div class="settings-label">General Support</div>
        <div class="settings-value" style="font-family: monospace; font-size: 14px;">support@clearb.info</div>
      </div>
      <button class="acc-copy-btn" onclick="copyToClipboard('support@clearb.info')"><i data-lucide="copy" style="width: 16px;"></i></button>
    </div>
    <div class="settings-row">
      <div class="settings-info">
        <div class="settings-label">Security & Compliance</div>
        <div class="settings-value" style="font-family: monospace; font-size: 14px;">compliance@clearb.info</div>
      </div>
      <button class="acc-copy-btn" onclick="copyToClipboard('compliance@clearb.info')"><i data-lucide="copy" style="width: 16px;"></i></button>
    </div>
  </div>
</div>

<div class="modal-overlay" id="freezeOverlay" onclick="closeFreezeModal()"></div>
<div class="modal-sheet" id="freezeSheet">
  <div class="modal-header">
    <h2>Confirm Freeze</h2>
    <button class="modal-close-btn" onclick="closeFreezeModal()"><i data-lucide="x" style="width: 16px; color: var(--mob-text);"></i></button>
  </div>
  <p style="color: var(--mob-text-muted); margin-bottom: 24px; font-size: 14px; line-height: 1.5;">
    Freezing your account will immediately block all outgoing transfers and payments. To proceed, please verify your identity.
  </p>
  
  <form action="#" method="POST">
    <div class="form-group">
      <label>Account Password</label>
      <input type="password" name="password" class="form-control" placeholder="Enter your password" required>
    </div>
    <button type="submit" class="btn-submit-freeze">Confirm & Freeze Account</button>
  </form>
</div>

<nav class="mob-bottom-nav">
  <a href="{{ route('dashboard') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="home"></i></span>
    Home
  </a>
  <a href="{{ route('account') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="credit-card"></i></span>
    Accounts
  </a>
  <a href="{{ route('transfers') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="arrow-right-left"></i></span>
    Transactions
  </a>
  <a href="{{ route('support') }}" class="mob-nav-link active">
    <span class="mob-nav-icon"><i data-lucide="headphones"></i></span>
    Support
  </a>
</nav>

<script>
  lucide.createIcons();

  function showToast(msg) {
    const toast = document.getElementById('toast');
    toast.innerText = msg;
    toast.classList.add('show');
    setTimeout(() => toast.classList.remove('show'), 3000);
  }

  function openTicketModal() {
    document.getElementById('ticketOverlay').classList.add('open');
    setTimeout(() => document.getElementById('ticketSheet').classList.add('open'), 10);
  }

  function closeTicketModal() {
    document.getElementById('ticketSheet').classList.remove('open');
    setTimeout(() => document.getElementById('ticketOverlay').classList.remove('open'), 300);
  }

  function openEmailModal() {
    document.getElementById('emailOverlay').classList.add('open');
    setTimeout(() => document.getElementById('emailSheet').classList.add('open'), 10);
  }

  function closeEmailModal() {
    document.getElementById('emailSheet').classList.remove('open');
    setTimeout(() => document.getElementById('emailOverlay').classList.remove('open'), 300);
  }

  function openFreezeModal() {
    document.getElementById('freezeOverlay').classList.add('open');
    setTimeout(() => document.getElementById('freezeSheet').classList.add('open'), 10);
  }

  function closeFreezeModal() {
    document.getElementById('freezeSheet').classList.remove('open');
    setTimeout(() => document.getElementById('freezeOverlay').classList.remove('open'), 300);
  }

  function copyToClipboard(text) {
    navigator.clipboard.writeText(text).then(() => {
      showToast('Copied to clipboard');
    });
  }

  function openProfileMenu() { document.getElementById('profileMenu').classList.add('open'); }
  function closeProfileMenu() { document.getElementById('profileMenu').classList.remove('open'); }
</script>
@endsection
