@extends('admin.layouts.app')
@section('title', isset($caseStudy) ? 'Edit Case Study' : 'Add Case Study')
@section('page-title', isset($caseStudy) ? 'Edit Case Study' : 'Add Case Study')
@section('content')
<div class="mb-3"><a href="{{ route('admin.case-studies.index') }}" class="btn btn-sm" style="border:1px solid #e2e8f0;color:#374151"><i class="bi bi-arrow-left me-1"></i>Back</a></div>

<form method="POST" action="{{ isset($caseStudy) ? route('admin.case-studies.update', $caseStudy->id) : route('admin.case-studies.store') }}" enctype="multipart/form-data">
    @csrf @if(isset($caseStudy)) @method('PUT') @endif
    <div class="row g-3">
        <div class="col-lg-8">
            <div class="card-admin p-4 mb-3">
                <div class="fw-700 mb-3" style="font-size:.88rem">Case Study Details</div>
                <div class="row g-3 mb-3">
                    <div class="col-md-8">
                        <label class="form-label">Title *</label>
                        <input type="text" name="title" class="form-control" value="{{ old('title', $caseStudy->title ?? '') }}" required>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Tab Label</label>
                        <input type="text" name="tab_label" class="form-control" value="{{ old('tab_label', $caseStudy->tab_label ?? '') }}" placeholder="e.g. EN14387 Case">
                    </div>
                </div>
                <div class="row g-3 mb-3">
                    <div class="col-md-6">
                        <label class="form-label">Category</label>
                        <input type="text" name="category" class="form-control" value="{{ old('category', $caseStudy->category ?? '') }}" placeholder="e.g. Products, Engineering">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Sort Order</label>
                        <input type="number" name="sort_order" class="form-control" value="{{ old('sort_order', $caseStudy->sort_order ?? 0) }}">
                    </div>
                </div>
                <div class="mb-3">
                    <label class="form-label">Summary (shown on listing page)</label>
                    <textarea name="summary" class="form-control" rows="3">{{ old('summary', $caseStudy->summary ?? '') }}</textarea>
                </div>
                <div class="mb-0">
                    <label class="form-label">Full Content (HTML allowed)</label>
                    <textarea name="full_content" class="form-control" rows="12">{{ old('full_content', $caseStudy->full_content ?? '') }}</textarea>
                </div>
            </div>
            <div class="card-admin p-4">
                <div class="fw-700 mb-3" style="font-size:.88rem">SEO</div>
                <div class="mb-3"><label class="form-label">Meta Title</label><input type="text" name="meta_title" class="form-control" value="{{ old('meta_title', $caseStudy->meta_title ?? '') }}"></div>
                <div><label class="form-label">Meta Description</label><textarea name="meta_description" class="form-control" rows="2">{{ old('meta_description', $caseStudy->meta_description ?? '') }}</textarea></div>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="card-admin p-4 mb-3">
                <div class="fw-700 mb-3" style="font-size:.88rem">Publish</div>
                <div class="mb-3">
                    <label class="form-label">Status</label>
                    <select name="is_active" class="form-select">
                        <option value="1" {{ old('is_active', $caseStudy->is_active ?? 1) == 1 ? 'selected' : '' }}>Active</option>
                        <option value="0" {{ old('is_active', $caseStudy->is_active ?? 1) == 0 ? 'selected' : '' }}>Inactive</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-admin w-100">{{ isset($caseStudy) ? 'Update Case Study' : 'Save Case Study' }}</button>
            </div>
            <div class="card-admin p-4">
                <div class="fw-700 mb-3" style="font-size:.88rem">Hero Image</div>
                @if(isset($caseStudy) && $caseStudy->hero_image)
                <img src="{{ asset('uploads/images/'.$caseStudy->hero_image) }}" alt="" style="max-height:100px;max-width:100%;margin-bottom:.5rem;border-radius:6px">
                @endif
                <input type="file" name="hero_image" class="form-control form-control-sm" accept="image/*">
            </div>
        </div>
    </div>
</form>
@endsection
