@extends('admin.masterAdmin')

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

                <div class="mb-3">
                    <label>Category</label>
                    <select name="category_id" class="form-control" required>
                        <option value="">Select Category</option>
                        @foreach ($categories as $category)
                            <option value="{{ $category->id }}"
                                {{ old('category_id', $career->category_id ?? '') == $category->id ? 'selected' : '' }}>
                                {{ $category->name }}
                            </option>
                        @endforeach
                    </select>
                </div>

                <div class="mb-3">
                    <label>Title</label>
                    <input type="text" name="title" class="form-control"
                        value="{{ old('title', $career->title ?? '') }}" required>
                </div>

                <div class="mb-3">
                    <label>Work Area</label>
                    <input type="text" name="work_area" class="form-control"
                        value="{{ old('work_area', $career->work_area ?? '') }}" required>
                </div>

                <div class="mb-3">
                    <label>Job Type</label>
                    <input type="text" name="job_type" class="form-control"
                        value="{{ old('job_type', $career->job_type ?? '') }}" required>
                </div>

                <div class="mb-3">
                    <label>Description</label>
                    <textarea name="description" class="form-control" rows="4">{{ old('description', $career->description ?? '') }}</textarea>
                </div>
                <div class="mb-3">
                    <label for="candidate_requirement">Candidate Requirement</label>
                    <textarea name="candidate_requirement" class="form-control" rows="4">{{ old('candidate_requirement', isset($career) ? str_replace(', ', "\n", $career->candidate_requirement) : '') }}</textarea>
                    <small class="form-text text-muted">Enter one requirement per line.</small>
                </div>



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