@extends('layouts.app')

@section('content')
<div class="row mb-4">
    <div class="col-md-12">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-1">
                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}" class="text-decoration-none text-muted small">Dashboard</a></li>
                <li class="breadcrumb-item"><a href="{{ route('notices.index') }}" class="text-decoration-none text-muted small">Notices</a></li>
                <li class="breadcrumb-item active text-primary small fw-semibold" aria-current="page">Modify</li>
            </ol>
        </nav>
        <h2 class="fw-bold text-dark">Modify Notice</h2>
        <p class="text-secondary small">Update the content or replace attachments for this notice.</p>
    </div>
</div>

<div class="row">
    <div class="col-lg-7">
        <div class="card border-0 shadow-lg rounded-4 overflow-hidden">
            <div class="card-header bg-white border-0 py-3 px-4 mt-2">
                <h6 class="m-0 fw-bold text-dark"><i class="bi bi-pencil-fill me-2 text-primary"></i> Edit Notice Information</h6>
            </div>
            <div class="card-body p-4 pt-2">
                <form action="{{ route('notices.update', $notice) }}" method="POST" enctype="multipart/form-data">
                    @csrf
                    @method('PUT')
                    <div class="mb-4">
                        <label for="title" class="form-label fw-bold text-dark mb-2">Notice Title</label>
                        <div class="input-group">
                            <span class="input-group-text bg-light border-0"><i class="bi bi-type text-secondary"></i></span>
                            <input type="text" name="title" class="form-control bg-light border-0 @error('title') is-invalid @enderror" id="title" placeholder="Enter notice title" value="{{ old('title', $notice->title) }}" required style="padding: 0.75rem;">
                        </div>
                        @error('title')
                            <div class="invalid-feedback d-block mt-2">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="mb-4">
                        <label for="uploads" class="form-label fw-bold text-dark mb-2">Attachment Update</label>
                        
                        @if($notice->uploads)
                            <div class="mb-3 p-3 border rounded-4 d-flex align-items-center bg-light">
                                <div class="bg-white rounded-3 p-2 me-3 shadow-sm">
                                    <i class="bi bi-file-earmark-check-fill text-success fs-4"></i>
                                </div>
                                <div>
                                    <span class="d-block small text-secondary fw-bold text-uppercase" style="font-size: 10px;">Current File</span>
                                    <a href="{{ asset($notice->uploads) }}" target="_blank" class="text-decoration-none text-primary fw-bold small">
                                        View Attachment <i class="bi bi-box-arrow-up-right ms-1"></i>
                                    </a>
                                </div>
                                <div class="ms-auto">
                                    <span class="badge bg-success-subtle text-success rounded-pill px-3">Secure</span>
                                </div>
                            </div>
                        @endif

                        <div class="upload-container bg-light rounded-4 p-4 text-center border-2 border-dashed border-secondary-subtle">
                            <i class="bi bi-upload text-primary fs-1 mb-3 d-block"></i>
                            <p class="text-dark fw-semibold mb-1">Upload New File to Replace</p>
                            <p class="text-secondary small mb-0">Leave empty to keep existing file</p>
                            <input type="file" name="uploads" class="form-control @error('uploads') is-invalid @enderror" id="uploads">
                        </div>
                        @error('uploads')
                            <div class="invalid-feedback d-block mt-2">{{ $message }}</div>
                        @enderror
                    </div>

                    <hr class="my-4 opacity-50">

                    <div class="d-flex align-items-center justify-content-between">
                        <a href="{{ route('notices.index') }}" class="btn btn-link text-decoration-none text-secondary fw-semibold">
                            <i class="bi bi-x-circle me-1"></i> Discard Changes
                        </a>
                        <button type="submit" class="btn btn-primary rounded-3 px-5 fw-bold shadow-sm py-2">
                            <i class="bi bi-check-lg me-2"></i> Save Changes
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <!-- Sidebar Meta info -->
    <div class="col-lg-5">
        <div class="card border-0 shadow-sm rounded-4 bg-white mb-4">
            <div class="card-body p-4">
                <h6 class="fw-bold text-dark mb-3"><i class="bi bi-info-circle me-2 text-primary"></i> Meta Information</h6>
                <div class="mb-3 pb-3 border-bottom d-flex justify-content-between align-items-center">
                    <span class="text-secondary small">Created At</span>
                    <span class="text-dark fw-medium small">{{ $notice->created_at->format('M d, Y H:i') }}</span>
                </div>
                <div class="mb-3 pb-3 border-bottom d-flex justify-content-between align-items-center">
                    <span class="text-secondary small">Last Updated</span>
                    <span class="text-dark fw-medium small">{{ $notice->updated_at->diffForHumans() }}</span>
                </div>
                <div class="d-flex justify-content-between align-items-center">
                    <span class="text-secondary small">Record ID</span>
                    <span class="badge bg-light text-dark border fw-bold">#{{ $notice->id }}</span>
                </div>
            </div>
        </div>
        
        <div class="alert bg-primary-subtle text-primary border-0 rounded-4 p-4 shadow-sm">
            <div class="d-flex">
                <i class="bi bi-lightbulb-fill fs-4 me-3"></i>
                <div>
                    <h6 class="fw-bold mb-1">Quick Note</h6>
                    <p class="small mb-0 opacity-75">Updating a notice will notify all active subscribers instantly via their dashboard. Ensure all links and titles are accurate.</p>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('styles')
<style>
    .upload-container {
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
    }
    .upload-container:hover {
        background-color: #f1f5f9 !important;
        border-color: #3b82f6 !important;
    }
    .upload-container input[type="file"] {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        opacity: 0;
        cursor: pointer;
    }
    .bg-primary-subtle { background-color: #eff6ff !important; }
    .bg-success-subtle { background-color: #ecfdf5 !important; }
    .text-success { color: #10b981 !important; }
    .border-dashed { border-style: dashed !important; }
    .input-group-text { border: none !important; }
</style>
@endsection
