@extends('layout.user')

@section('content')
@php
  $gs = \App\Models\GeneralSetting::first();
  $telegramLink = $telegramLink ?? ($gs->telegram_link ?? '#');
  $tutorialLink = trim((string) ($currentProjectTutorialLink ?? ''));
  $tutorialType = trim((string) ($currentProjectTutorialPlayerType ?? ''));
  $tutorialSrc = trim((string) ($currentProjectTutorialPlayerSrc ?? ''));
  $tutorialTitle = trim((string) ($currentProjectTutorialTitle ?? '')) ?: 'ফেসবুক প্রজেক্ট ভিডিও';
  $hasTutorialLink = $tutorialLink !== '' && $tutorialLink !== '#' && $tutorialType !== '' && $tutorialSrc !== '';
@endphp

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css"/>

<style>
  :root{
    --bg:#f5f7fb;
    --ink:#0f172a;
    --muted:#6b7280;
    --card:#ffffff;
    --line:#e5e7eb;

    --pri:#2563eb;
    --pri-deep:#1d4ed8;
    --ok:#059669;
    --bad:#dc2626;
  }

  html,body{
    background:var(--bg);
    color:var(--ink);
    font-family:system-ui,-apple-system,"Noto Sans Bengali",Segoe UI,Roboto,Arial,sans-serif;
  }

  .max-w-md{max-width:28rem}
  .mx-auto{margin-left:auto;margin-right:auto}
  .px-3{padding-left:.75rem;padding-right:.75rem}
  .py-4{padding-top:1rem;padding-bottom:1rem}
  .mb-4{margin-bottom:1rem}
  .text-center{text-align:center}
  .text-xs{font-size:.75rem}
  .text-sm{font-size:.875rem}
  .text-lg{font-size:1.125rem}
  .font-extrabold{font-weight:800}
  .font-bold{font-weight:700}
  .space-y-4>*+*{margin-top:1rem}
  .grid{display:grid}
  .grid-cols-2{grid-template-columns:1fr 1fr}
  .gap-3{gap:.75rem}

  .blue-ring{
    border:2px solid rgba(37,99,235,.55) !important;
    box-shadow:0 0 0 3px rgba(37,99,235,.10);
  }

  .bd-card{
    background:var(--card);
    border-radius:16px;
    box-shadow:0 10px 24px rgba(2,6,23,.06);
  }

  .bd-solid{
    background:linear-gradient(90deg,var(--pri),var(--pri-deep));
    color:#fff;
  }

  .bd-btn{
    background:var(--pri);
    color:#fff;
    font-weight:800;
    border:none;
    border-radius:12px;
    transition:.2s;
  }
  .bd-btn:hover{background:var(--pri-deep)}

  .bd-badge{
    display:inline-flex;align-items:center;justify-content:center;
    width:40px;height:40px;border-radius:12px;background:var(--pri);color:#fff
  }

  .bd-copy{
    position:absolute;top:.45rem;right:.45rem;width:30px;height:30px;border-radius:999px;
    display:flex;align-items:center;justify-content:center;background:#ffffff25;color:#fff;
    border:1px solid #ffffff40;
  }

  .bd-btn-frame{
    background:#fff;
    border:1px solid #dfe3eb;
    border-radius:12px;
    padding:4px;
    box-shadow:0 2px 8px rgba(2,6,23,.04);
  }

  .bd-link-btn{
    display:block;
    width:100%;
    text-align:center;
    padding:.65rem 1rem;
    border-radius:12px;
    font-weight:800;
    background:var(--pri);
    color:#fff !important;
    box-shadow:0 6px 14px rgba(2,6,23,.06);
    transition:transform .12s ease, background .12s ease;
    -webkit-tap-highlight-color:transparent;
  }
  .bd-link-btn:hover{background:var(--pri-deep)}
  .bd-link-btn:link,.bd-link-btn:visited,.bd-link-btn:focus{color:#fff !important;text-decoration:none}
  .bd-link-btn:active{transform:translateY(1px)}

  .inp{
    width:100%;
    border:2px solid rgba(37,99,235,.55);
    border-radius:12px;
    padding:.65rem .85rem;
    font-size:.95rem;
    transition:.15s;
    background:#fff;
    color:var(--ink);
    box-shadow:0 0 0 3px rgba(37,99,235,.10);
  }
  .inp:focus{ outline:none; border-color:rgba(37,99,235,.75); box-shadow:0 0 0 4px rgba(37,99,235,.18); }

  .top-actions{
    display:grid;
    gap:.75rem;
    margin-bottom:1rem;
  }
  .top-actions.has-video{grid-template-columns:1fr 1fr;}
  .top-actions.no-video{grid-template-columns:1fr;}

  @media (max-width:420px){
    .top-actions{grid-template-columns:1fr;}
  }
</style>

<div class="max-w-md mx-auto px-3 py-4">

  @include('partials.mobile_action_cards', [
    'primaryVisible' => true,
    'primaryHref' => '/fb/marketing/history',
    'primaryLabel' => 'হিস্ট্রি',
    'primarySubtitle' => 'পূর্বের সব সাবমিশন দেখুন',
    'videoLink' => $tutorialLink,
    'videoType' => $tutorialType,
    'videoSrc' => $tutorialSrc,
    'videoTitle' => $tutorialTitle,
    'videoLabel' => 'ভিডিও',
    'videoSubtitle' => 'এই প্রজেক্টের ভিডিও দেখতে এখানে ক্লিক করুন',
  ])

  @if(session('success'))
    <div class="bd-card blue-ring" style="padding:10px 12px;margin-bottom:12px;background:#ecfdf5;color:#065f46;">
      <i class="fas fa-check-circle me-1"></i> {{ session('success') }}
    </div>
  @endif

  @if(session('error'))
    <div class="bd-card blue-ring" style="padding:10px 12px;margin-bottom:12px;background:#fef2f2;color:#991b1b;">
      <i class="fas fa-times-circle me-1"></i> {{ session('error') }}
    </div>
  @endif

  @if($errors->any())
    <div class="bd-card blue-ring" style="padding:10px 12px;margin-bottom:12px;background:#fef2f2;color:#991b1b;">
      সাবমিশনে সমস্যা হয়েছে। নিচের ঘরগুলো ঠিক করুন।
    </div>
  @endif

  @if(isset($setting) && $setting->is_active)

  <div class="bd-card blue-ring" style="padding:16px;margin-bottom:16px;">
    <h1 class="text-lg font-extrabold text-center" style="font-size:22px;color:var(--pri)">ফেসবুক মার্কেটিং</h1>
    <p class="text-[13px] text-center" style="color:var(--muted);margin-top:6px;">
      সঠিক নিয়মে কাজ করুন। ফেসবুক আইডিতে কমপক্ষে ৩০ জন ফ্রেন্ড থাকতে হবে, না হলে পেমেন্ট হবে না। ভুল UID, ইমেইল বা 2FA দিলে অ্যাকাউন্ট স্থগিত হতে পারে।
    </p>
    <p class="text-xs text-center font-extrabold" style="color:var(--bad);margin-top:6px;">
      রিপোর্ট টাইম: ৩–৪ দিন
    </p>

    <div class="grid grid-cols-2 gap-3" style="margin-top:12px;">
      <div class="blue-ring" style="background:#f8fafc;border-radius:12px;padding:12px;text-align:center;">
        <div class="text-xs" style="color:var(--muted)">লিমিট</div>
        <div class="font-extrabold text-lg" style="color:var(--ink)">{{ $setting->limit_per_user }}</div>
      </div>
      <div class="blue-ring" style="background:#f8fafc;border-radius:12px;padding:12px;text-align:center;">
        <div class="text-xs" style="color:var(--muted)">এমাউন্ট</div>
        <div class="font-extrabold text-lg" style="color:var(--pri)">৳ {{ number_format($setting->amount_per_id, 2) }}</div>
      </div>
    </div>

    <div class="bd-solid blue-ring" style="border-radius:14px;padding:12px;margin-top:12px;">
      <div class="text-center text-lg font-extrabold">আজকের পাসওয়ার্ড</div>

      <div class="blue-ring" style="margin-top:10px;background:#ffffff14;border-radius:12px;padding:12px;position:relative;">
        <div class="text-xs" style="opacity:.9;">Password</div>
        <div id="todayPassword" class="font-bold" style="word-break:break-word;">{{ $setting->password }}</div>
        <button type="button" onclick="copyText('todayPassword')" class="bd-copy" title="কপি করুন">
          <i class="fas fa-copy"></i>
        </button>
      </div>
    </div>
  </div>

  <div class="bd-card blue-ring" style="padding:16px;">
    <h2 class="text-lg font-extrabold text-center" style="color:var(--pri)">ফেসবুক UID সাবমিশন ফর্ম</h2>
    <p class="text-xs text-center" style="color:var(--muted);margin-top:6px;">নিচের ফর্মটি পূরণ করুন</p>

    <form method="POST" action="/fb/marketing" class="space-y-3" style="margin-top:12px;">
      @csrf

      <div style="margin-bottom:12px;">
        <label class="block text-sm mb-1 font-bold" style="color:var(--ink)">
          <i class="fas fa-id-card me-1" style="color:var(--muted)"></i>
          Facebook ID Link দিন
        </label>

        <input type="url"
               name="fb_uid"
               required
               value="{{ old('fb_uid') }}"
               class="inp"
               placeholder="ফেসবুক আইডির লিংক দিন">

        @error('fb_uid')
          <p class="text-xs mt-1" style="color:var(--bad)">{{ $message }}</p>
        @enderror
      </div>

      <div style="margin-bottom:12px;">
        <label class="block text-sm mb-1 font-bold" style="color:var(--ink)"><i class="fas fa-envelope me-1" style="color:var(--muted)"></i> Hotmail / Login ( লাইন পুরোটি) লিখুন</label>
        <input type="text" name="fb_email" autocomplete="email" required
               value="{{ old('fb_email') }}"
               class="inp" placeholder="যে হটমেইল আইডিতে যুক্ত করেছেন">
        @error('fb_email') <p class="text-xs mt-1" style="color:var(--bad)">{{ $message }}</p> @enderror
      </div>

      <div style="margin-bottom:12px;">
        <label class="block text-sm mb-1 font-bold" style="color:var(--ink)"><i class="fas fa-lock me-1" style="color:var(--muted)"></i> পাসওয়ার্ড লিখুন</label>
        <input type="text" name="fb_password" autocomplete="off" required
               value="{{ old('fb_password') }}"
               class="inp" placeholder="আইডির পাসওয়ার্ড (আজকের পাসওয়ার্ড)">
        @error('fb_password') <p class="text-xs mt-1" style="color:var(--bad)">{{ $message }}</p> @enderror
      </div>

      <div style="margin-bottom:12px;">
        <label class="block text-sm mb-1 font-bold" style="color:var(--ink)"><i class="fas fa-shield-alt me-1" style="color:var(--muted)"></i> 2FA Key লিখুন</label>
        <input type="text" name="fb_2fa" minlength="16" autocomplete="off" required
               value="{{ old('fb_2fa') }}"
               class="inp" placeholder="2FA কী লিখুন">
        @error('fb_2fa') <p class="text-xs mt-1" style="color:var(--bad)">{{ $message }}</p> @enderror
      </div>

      @if($cookieLinkEnabled ?? true)
      <div style="margin-bottom:12px;">
        <label class="block text-sm mb-1 font-bold" style="color:var(--ink)">
          <i class="fas fa-link me-1" style="color:var(--muted)"></i> সম্পুর্ন কুকিজ লিঙ্ক দিন_
        </label>
        <input type="text" name="fb_cookie_link" autocomplete="off" required
               value="{{ old('fb_cookie_link') }}"
               class="inp" placeholder="কুকিজ লিংক বা টেক্সট দিন">
        @error('fb_cookie_link') <p class="text-xs mt-1" style="color:var(--bad)">{{ $message }}</p> @enderror
      </div>
      @endif

      <button id="submitBtn" type="submit" class="w-full bd-btn py-3 font-extrabold blue-ring">
        <i class="fas fa-paper-plane mr-1"></i> সাবমিট করুন
      </button>

      <div class="bd-btn-frame blue-ring" style="margin-top:12px;">
        <a href="{{ $telegramLink }}" target="_blank" rel="noopener" class="bd-link-btn blue-ring">
          <i class="fa-brands fa-telegram mr-1"></i>
          টেলিগ্রামে আপডেট পান
        </a>
      </div>

    </form>
  </div>

  @endif

</div>

<script>
function copyText(id){
  const text=(document.getElementById(id)?.innerText||'').trim();
  if(!text) return;
  navigator.clipboard.writeText(text).then(()=>alert('কপি হয়েছে!'));
}
document.addEventListener('DOMContentLoaded', function(){
  const form=document.querySelector('form[action="/fb/marketing"]');
  const btn=document.getElementById('submitBtn');
  if(form && btn){
    form.addEventListener('submit', function(){
      btn.disabled=true;
      btn.style.opacity=.7;
      btn.style.cursor='not-allowed';
    });
  }
});
</script>

@endsection
