@extends('admin.masterAdmin')

@section('content')
<div class="card">
    <div class="card-header">
        <h5>{{ isset($certificate) ? 'Edit Certificate' : 'Add Certificate' }}</h5>
    </div>
    <div class="card-body">
        <form
            action="{{ isset($certificate) ? route('certificate.update', $certificate->id) : route('certificate.store') }}"
            method="POST" enctype="multipart/form-data">
            @csrf
            @if (isset($certificate))
            @method('PUT')
            @endif

            <div class="mb-3">
                <label>Name <span style="color: red;">*</span></label>
                <input type="text" name="name" class="form-control" value="{{ old('name', $certificate->name ?? '') }}"
                    required>
            </div>

            <div class="mb-3">
                <label>Type <span style="color: red;">*</span></label>
                <input type="text" name="type" class="form-control" value="{{ old('type', $certificate->type ?? '') }}"
                    placeholder="Certificate, Accreditations, etc" required>
            </div>

            <div class="mb-3">
                <label>Link </label>
                <input type="url" name="link" class="form-control" placeholder="https://iso.com"
                    value="{{ old('link', $certificate->link ?? '') }}">
            </div>

            <div class="mb-3">
                <label>Date <span style="color: red;">*</span></label>
                <input type="date" name="date" class="form-control"
                    value="{{ old('date', isset($certificate->date) ? date('Y-m-d', strtotime($certificate->date)) : '') }}">
            </div>

            <div class="mb-3">
                <label>Renew (Years)</label>
                <input type="number" name="renew" placeholder="IF Renew this year" class="form-control"
                    value="{{ old('renew', $certificate->renew ?? '') }}">
            </div>

            <div class="mb-3">
                <label>Description</label>
                <textarea name="description" class="form-control"
                    rows="4">{{ old('description', $certificate->description ?? '') }}</textarea>
            </div>

            <div class="mb-3">
                <label>Image <span style="color: red;">*</span></label>
                <input type="file" name="image" accept="image/*" class="form-control">
                @if (isset($certificate) && $certificate->image)
                <div class="mt-2">
                    <img src="{{ asset( $certificate->image) }}" alt="Certificate Image" width="120">
                </div>
                @endif
            </div>

            <button class="btn btn-success mt-3">{{ isset($certificate) ? 'Update' : 'Save' }}</button>
            <a href="{{ route('certificate.index') }}" class="btn btn-secondary mt-3">Cancel</a>
        </form>
    </div>
</div>
@endsection