@extends('backend.master')
@section('title','Edit Upload #'.$uploadApp->id)

@section('content')

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

<style>
    :root{
        --primary:#2FAAA6;
        --primary-dark:#1f8f8b;
        --bg:#f5f5f5;
        --ink:#111827;
        --muted:#6b7280;
    }
    body{background:var(--bg);}
    .page-wrap{max-width:700px;margin:20px auto 60px;padding:0 12px;}
    .card-main{
        background:#fff;border-radius:18px;padding:18px 16px 20px;
        box-shadow:0 12px 32px rgba(15,23,42,.10);border:1px solid #e5e7eb;
    }
    .title{font-size:18px;font-weight:700;color:var(--ink);}
    .subtitle{font-size:13px;color:var(--muted);}
    .btn-back{
        font-size:12px;text-decoration:none;display:inline-flex;align-items:center;gap:6px;
        color:#4b5563;
    }
    .btn-back i{font-size:11px;}

    .current-box{
        border-radius:14px;border:1px solid #e5e7eb;background:#f9fafb;
        padding:10px 12px;font-size:12px;color:#4b5563;margin-bottom:10px;
    }
    .current-box a{
        font-weight:600;color:var(--primary-dark);text-decoration:none;word-break:break-all;
    }
    .current-box a:hover{text-decoration:underline;}

    .btn-submit{
        border:none;border-radius:999px;padding:10px 18px;font-size:14px;font-weight:600;
        background:linear-gradient(135deg,var(--primary),var(--primary-dark));
        color:#fff;box-shadow:0 16px 34px rgba(31,143,139,.45);width:100%;
        display:inline-flex;align-items:center;justify-content:center;gap:6px;
    }
    .btn-submit i{font-size:14px;}
</style>

<div class="page-wrap">

    <div class="mb-2">
        <a href="{{ route('upload-apps.index') }}" class="btn-back">
            <i class="fa-solid fa-arrow-left"></i> Back to uploads
        </a>
    </div>

    @if($errors->any())
        <div class="alert alert-danger py-2 px-3 mb-3" style="font-size:13px;">
            <i class="fa-solid fa-triangle-exclamation"></i>
            {{ implode(' ', $errors->all()) }}
        </div>
    @endif

    <div class="card-main">
        <div class="mb-3">
            <div class="title">
                <i class="fa-solid fa-pen-to-square"></i>
                Edit App Upload #{{ $uploadApp->id }}
            </div>
            <div class="subtitle">
                Replace the uploaded file if needed. Leave blank to keep current file.
            </div>
        </div>

        {{-- Current file info --}}
        <div class="current-box">
            <div style="font-weight:600;margin-bottom:3px;color:#374151;">Current File</div>
            @if($uploadApp->upload_apk)
                <a href="{{ asset('storage/'.$uploadApp->upload_apk) }}" target="_blank">
                    {{ basename($uploadApp->upload_apk) }}
                </a>
            @else
                <span style="color:#9ca3af;">No file uploaded yet.</span>
            @endif
        </div>

        <form method="POST"
              action="{{ route('upload-apps.update',$uploadApp) }}"
              enctype="multipart/form-data">
            @csrf
            @method('PUT')

            <div class="mb-3">
                <label class="form-label" style="font-weight:600;font-size:14px;">
                    Replace File (optional)
                </label>
                <input type="file"
                       name="upload_apk"
                       class="form-control @error('upload_apk') is-invalid @enderror">
                @error('upload_apk')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
                <div class="form-text" style="font-size:12px;color:#6b7280;">
                    Keep empty to use the existing file. Max 50MB.
                </div>
            </div>

            <button type="submit" class="btn-submit">
                <i class="fa-solid fa-floppy-disk"></i>
                <span>Save changes</span>
            </button>
        </form>
    </div>
</div>
@endsection
