@extends('layouts.app')
@section('title', isset($task) ? 'Edit Task' : 'Create Task')
@section('content')
<h4 class="mb-3">{{ isset($task) ? 'Edit' : 'Create' }} Task</h4>
<form method="POST" enctype="multipart/form-data" action="{{ isset($task) ? route('tasks.update',$task) : route('tasks.store') }}" class="card card-body">
@csrf @if(isset($task)) @method('PUT') @endif
<div class="row g-3">
<div class="col-md-6"><label class="form-label">Title</label><input class="form-control" name="title" value="{{ old('title',$task->title ?? '') }}" required></div>
<div class="col-md-3"><label class="form-label">Priority</label><select class="form-select" name="priority">@foreach(['low','medium','high','critical'] as $p)<option value="{{ $p }}" @selected(old('priority',$task->priority ?? 'medium')===$p)>{{ ucfirst($p) }}</option>@endforeach</select></div>
<div class="col-md-3"><label class="form-label">Progress %</label><input type="number" min="0" max="100" class="form-control" name="progress_percent" value="{{ old('progress_percent',$task->progress_percent ?? 0) }}"></div>
<div class="col-md-4"><label class="form-label">Project</label><select class="form-select" name="project_id" required>@foreach($projects as $project)<option value="{{ $project->id }}" @selected(old('project_id',$task->project_id ?? '')==$project->id)>{{ $project->name }}</option>@endforeach</select></div>
<div class="col-md-4"><label class="form-label">Module</label><select class="form-select" name="project_module_id"><option value="">Select module</option>@foreach($projects as $project) @foreach($project->modules as $module)<option value="{{ $module->id }}" @selected(old('project_module_id',$task->project_module_id ?? '')==$module->id)>{{ $project->name }} - {{ $module->name }}</option>@endforeach @endforeach</select></div>
<div class="col-md-4"><label class="form-label">Status</label><select class="form-select" name="task_status_id">@foreach($statuses as $status)<option value="{{ $status->id }}" @selected(old('task_status_id',$task->task_status_id ?? '')==$status->id)>{{ $status->name }}</option>@endforeach</select></div>
<div class="col-md-6"><label class="form-label">Deadline</label><input type="date" class="form-control" name="deadline" value="{{ old('deadline',isset($task->deadline)?$task->deadline->format('Y-m-d'):'') }}"></div>
<div class="col-md-6"><label class="form-label">Assign Employees</label><select class="form-select" multiple name="assignee_ids[]">@foreach($employees as $employee)<option value="{{ $employee->id }}" @selected(isset($task) && $task->assignees->contains('id',$employee->id))>{{ $employee->name }}</option>@endforeach</select></div>
<div class="col-md-12"><label class="form-label">Dependencies</label><select class="form-select" multiple name="dependency_ids[]">@foreach($tasks as $dependencyTask)<option value="{{ $dependencyTask->id }}" @selected(isset($task) && $task->dependencies->contains('id',$dependencyTask->id))>{{ $dependencyTask->title }}</option>@endforeach</select></div>
<div class="col-md-12"><label class="form-label">Description</label><textarea class="form-control" name="description">{{ old('description',$task->description ?? '') }}</textarea></div>
<div class="col-md-12"><label class="form-label">Files</label><input type="file" class="form-control" multiple name="files[]"></div>
</div>
<div class="mt-3"><button class="btn btn-success">Save Task</button></div>
</form>
@if(isset($task))
<div class="card mt-4"><div class="card-body">
<h5>Comments</h5>
<form method="POST" action="{{ route('tasks.comments.store',$task) }}" class="mb-3">@csrf<div class="input-group"><input name="comment" class="form-control" placeholder="Add comment" required><button class="btn btn-primary">Post</button></div></form>
@foreach($task->comments as $comment)<div class="border rounded p-2 mb-2"><strong>{{ $comment->user?->name }}</strong><div>{{ $comment->comment }}</div></div>@endforeach
<h5 class="mt-3">Files</h5>
@foreach($task->files as $file)<div class="d-flex justify-content-between border rounded p-2 mb-2"><a href="{{ asset('storage/'.$file->file_path) }}" target="_blank">{{ $file->original_name }}</a><form method="POST" action="{{ route('tasks.files.destroy',$file) }}">@csrf @method('DELETE')<button class="btn btn-sm btn-outline-danger">Remove</button></form></div>@endforeach
</div></div>
@endif
@endsection
