Files
petriandClaude Sonnet 5.5 87e38260dc Show a task card's actions above tabs for notes, images and materials
The opened task card keeps its details and description at the top, then
the status, book hours, edit and remove actions, and below them tabs:
checklist and comments, images, and materials and machines. The tabs are
a project component (x-tabs) after the WAI-ARIA pattern, because
TallStackUI's tab ties its panels to missing ids and has no arrow keys.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-29 09:58:04 +02:00

648 lines
33 KiB
PHP

<?php
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Customers\Application\Contracts\CustomerQueries;
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
use App\Modules\Jobs\Application\Contracts\TaskQueries;
use App\Modules\Jobs\Application\DTOs\JobChangeEntry;
use App\Modules\Jobs\Application\DTOs\TaskSummary;
use App\Modules\Jobs\Application\UseCases\ChangeTaskStatus;
use App\Modules\Jobs\Application\UseCases\RemoveTask;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Exceptions\TaskHasTimeEntries;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Users\Application\Contracts\UserAccountQueries;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Gate;
use App\Modules\Shared\Domain\ValueObjects\Money;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Attributes\On;
use Livewire\Component;
/**
* A customer job's page: details, members, links, instructions and history.
*/
new class extends Component
{
#[Locked]
public int $jobId;
/**
* The task the remove dialog asks about.
*/
#[Locked]
public ?int $removalTaskId = null;
#[Locked]
public string $removalTaskTitle = '';
public string $taskStatusMessage = '';
public function mount(CustomerJobQueries $jobQueries, int $job): void
{
$this->authorize('jobs.view');
abort_if($jobQueries->findDetails($job) === null, 404);
$this->authorize('jobs.view-job', $job);
$this->jobId = $job;
}
#[Computed]
public function job(): CustomerJobDetails
{
return app(CustomerJobQueries::class)->findDetails($this->jobId) ?? abort(404);
}
/**
* @return list<JobChangeEntry>
*/
#[Computed]
public function changes(): array
{
$changes = app(CustomerJobQueries::class)->changes($this->jobId);
// Changes of the quoted amount are shown only to those who may see quotes (spec 5.7).
return Gate::allows('money.quotes')
? $changes
: array_values(array_filter($changes, fn (JobChangeEntry $change): bool => ! in_array($change->field, ['quoted_amount', 'monthly_fee'], true)));
}
/**
* @return list<TaskSummary>
*/
#[Computed]
public function tasks(): array
{
return app(TaskQueries::class)->tasksOf($this->jobId);
}
/**
* A task's comments or images changed: the task cards show their number.
*/
#[On('task-comments-changed')]
#[On('task-images-changed')]
public function refreshTasks(): void
{
unset($this->tasks);
}
public function changeTaskStatus(int $taskId, string $status, ChangeTaskStatus $changeStatus): void
{
$this->authorize('jobs.update-task-status', $this->jobId);
$newStatus = TaskStatus::tryFrom($status);
$task = app(TaskQueries::class)->findTask($this->jobId, $taskId);
if ($newStatus === null || $task === null) {
$this->taskStatusMessage = __('jobs.tasks.not_found');
return;
}
try {
$changeStatus->execute($this->jobId, $taskId, $newStatus);
} catch (TaskNotFound) {
$this->taskStatusMessage = __('jobs.tasks.not_found');
return;
}
unset($this->tasks);
$this->taskStatusMessage = __('jobs.tasks.status_changed', ['title' => $task->title, 'status' => __('jobs.tasks.statuses.'.$newStatus->value)]);
// The list is re-ordered (done tasks last): keep focus on the same select.
$this->js("document.getElementById('task-status-{$taskId}')?.focus()");
}
public function confirmTaskRemoval(int $taskId): void
{
$this->authorize('jobs.manage-tasks', $this->jobId);
$task = app(TaskQueries::class)->findTask($this->jobId, $taskId);
if ($task === null) {
$this->taskStatusMessage = __('jobs.tasks.not_found');
return;
}
$this->removalTaskId = $task->id;
$this->removalTaskTitle = $task->title;
$this->js("document.getElementById('remove-task-dialog').showModal()");
}
public function removeTask(RemoveTask $removeTask): void
{
$this->authorize('jobs.manage-tasks', $this->jobId);
if ($this->removalTaskId === null) {
return;
}
try {
$removeTask->execute($this->jobId, $this->removalTaskId);
$this->taskStatusMessage = __('jobs.tasks.removed', ['title' => $this->removalTaskTitle]);
} catch (TaskNotFound) {
$this->taskStatusMessage = __('jobs.tasks.not_found');
} catch (TaskHasTimeEntries) {
$this->taskStatusMessage = __('jobs.tasks.has_time_entries', ['title' => $this->removalTaskTitle]);
}
unset($this->tasks);
$this->reset('removalTaskId', 'removalTaskTitle');
$this->js("document.getElementById('remove-task-dialog').close(); document.getElementById('tasks-heading').focus()");
}
public function formatDate(?string $date): string
{
return $date === null ? __('jobs.not_set') : CarbonImmutable::parse($date)->format('j.n.Y');
}
/**
* A history value as text: names for ids, labels for enum keys,
* Finnish dates.
*/
public function historyValue(string $field, ?string $value): string
{
if ($value === null || $value === '') {
return __('jobs.not_set');
}
$ids = array_map('intval', explode(',', $value));
$named = fn (array $names): string => implode(', ', array_map(
fn (int $id): string => $names[$id] ?? __('jobs.history.unknown', ['id' => $id]),
$ids,
));
return match ($field) {
'starts_on', 'due_on', 'planned_from', 'planned_to' => $this->formatDate($value),
'quoted_amount', 'monthly_fee' => Money::fromCents((int) $value)->format(),
'kind' => __('jobs.kinds.'.$value),
'status' => __('jobs.statuses.'.$value),
'priority' => __('jobs.priorities.'.$value),
'payment_basis' => __('jobs.payment_bases.'.$value),
'customer' => $named(app(CustomerQueries::class)->namesByIds($ids)),
'service_units' => $named(app(CatalogQueries::class)->serviceUnitNames($ids)),
'responsible_user', 'contact_user', 'biller_user', 'members' => $named(app(UserAccountQueries::class)->namesByIds($ids)),
'customer_contact' => app(CustomerQueries::class)->findContact($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]),
'billing_unit' => app(CustomerQueries::class)->findBillingUnit($this->job->customer->id, $ids[0])->name ?? __('jobs.history.unknown', ['id' => $ids[0]]),
default => $value,
};
}
public function render(): mixed
{
return $this->view()->title($this->job->number.' '.$this->job->name);
}
};
?>
@php($job = $this->job)
<div class="mx-auto max-w-5xl space-y-8 p-4 sm:p-6">
<div class="space-y-4">
<div class="flex flex-wrap items-start justify-between gap-4">
<h1 class="text-2xl font-semibold break-words">
<span class="whitespace-nowrap">{{ $job->number }}</span> {{ $job->name }}
</h1>
@can('jobs.manage')
<x-button :href="route('jobs.edit', $job->id)" wire:navigate subtle color="black" icon="pencil" :text="__('jobs.edit')" />
@endcan
</div>
@if (session('status'))
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
@endif
<dl class="flex flex-wrap gap-x-8 gap-y-2 text-sm">
<div class="flex gap-2"><dt class="font-medium">{{ __('jobs.fields.status') }}:</dt><dd>{{ __('jobs.statuses.'.$job->status->value) }}</dd></div>
<div class="flex gap-2"><dt class="font-medium">{{ __('jobs.fields.priority') }}:</dt><dd><x-jobs.priority :priority="$job->priority" /></dd></div>
<div class="flex gap-2"><dt class="font-medium">{{ __('jobs.fields.due_on') }}:</dt><dd><x-jobs.due-date :date="$job->dueOn" :status="$job->status" /></dd></div>
</dl>
</div>
<section aria-labelledby="basics-heading" class="space-y-3">
<h2 id="basics-heading" class="text-xl font-semibold">{{ __('jobs.sections.basics') }}</h2>
<dl class="grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('jobs.fields.customer') }}</dt>
<dd>
@can('customers.use')
<x-link :href="route('customers.show', $job->customer->id)" navigate>{{ $job->customer->name }}</x-link>
@else
{{ $job->customer->name }}
@endcan
</dd>
<dt class="font-medium">{{ __('jobs.fields.service_units') }}</dt>
<dd>{{ collect($job->serviceUnits)->pluck('name')->join(', ') }}</dd>
<dt class="font-medium">{{ __('jobs.fields.kind') }}</dt>
<dd>{{ __('jobs.kinds.'.$job->kind->value) }}</dd>
<dt class="font-medium">{{ __('jobs.fields.payment_basis') }}</dt>
<dd>
{{ $job->paymentBasis === null ? __('jobs.not_set') : __('jobs.payment_bases.'.$job->paymentBasis->value) }}
@if ($job->paymentBasis?->value === 'monthly_fee')
@can('billing.manage')
<x-link :href="route('billing.job-months', $job->id)" navigate class="ml-2">{{ __('jobs.monthly_billing_link') }}</x-link>
@endcan
@endif
</dd>
<dt class="font-medium">{{ __('jobs.fields.estimated_hours') }}</dt>
<dd>{{ $job->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $job->estimatedHours).' h' }}</dd>
@can('money.quotes')
<dt class="font-medium">{{ __('jobs.fields.quoted_amount') }}</dt>
<dd>{{ $job->quotedAmountCents === null ? __('jobs.not_set') : Money::fromCents($job->quotedAmountCents)->format().' '.__('jobs.vat_excluded') }}</dd>
@if ($job->paymentBasis?->value === 'monthly_fee' || $job->monthlyFeeCents !== null)
<dt class="font-medium">{{ __('jobs.fields.monthly_fee') }}</dt>
<dd>{{ $job->monthlyFeeCents === null ? __('jobs.not_set') : Money::fromCents($job->monthlyFeeCents)->format().' '.__('jobs.vat_excluded') }}</dd>
@endif
@endcan
<dt class="font-medium">{{ __('jobs.fields.customer_reference') }}</dt>
<dd class="break-words">{{ $job->customerReference ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.fields.tags') }}</dt>
<dd>{{ $job->tags === [] ? __('jobs.tags.none') : implode(', ', $job->tags) }}</dd>
@if ($job->completedAt !== null)
<dt class="font-medium">{{ __('jobs.fields.completed_at') }}</dt>
<dd>{{ CarbonImmutable::parse($job->completedAt)->format('j.n.Y H.i') }}</dd>
@endif
<dt class="font-medium">{{ __('jobs.fields.created_at') }}</dt>
<dd>{{ CarbonImmutable::parse($job->createdAt)->format('j.n.Y H.i') }}, {{ $job->createdByName }}</dd>
</dl>
@if ($job->description !== null)
<h3 class="text-base font-semibold">{{ __('jobs.fields.description') }}</h3>
<p class="whitespace-pre-line text-sm">{{ $job->description }}</p>
@endif
</section>
<section aria-labelledby="schedule-heading" class="space-y-3">
<h2 id="schedule-heading" class="text-xl font-semibold">{{ __('jobs.sections.schedule') }}</h2>
<dl class="grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('jobs.fields.starts_on') }}</dt>
<dd>{{ $this->formatDate($job->startsOn) }}</dd>
<dt class="font-medium">{{ __('jobs.fields.due_on') }}</dt>
<dd><x-jobs.due-date :date="$job->dueOn" :status="$job->status" /></dd>
<dt class="font-medium">{{ __('jobs.fields.planned_from') }}</dt>
<dd>{{ $this->formatDate($job->plannedFrom) }}</dd>
<dt class="font-medium">{{ __('jobs.fields.planned_to') }}</dt>
<dd>{{ $this->formatDate($job->plannedTo) }}</dd>
</dl>
</section>
<section aria-labelledby="members-heading" class="space-y-3">
<h2 id="members-heading" class="text-xl font-semibold">{{ __('jobs.sections.members') }}</h2>
<dl class="grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('jobs.fields.responsible_user') }}</dt>
<dd>{{ $job->responsible->name }}</dd>
<dt class="font-medium">{{ __('jobs.fields.contact_user') }}</dt>
<dd>{{ $job->contactUser->name ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.fields.customer_contact') }}</dt>
<dd>{{ $job->customerContact->name ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.fields.biller_user') }}</dt>
<dd>{{ $job->biller->name ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.fields.billing_unit') }}</dt>
<dd>{{ $job->billingUnit->name ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.fields.members') }}</dt>
<dd>{{ $job->members === [] ? __('jobs.not_set') : collect($job->members)->pluck('name')->join(', ') }}</dd>
</dl>
</section>
<section id="tasks" aria-labelledby="tasks-heading" class="space-y-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<h2 id="tasks-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">{{ __('jobs.tasks.title') }}</h2>
@can('jobs.manage-tasks', $job->id)
@if ($job->status->allowsTasks())
<div class="flex flex-wrap gap-2">
<x-button :href="route('jobs.tasks.create', $job->id)" wire:navigate icon="plus" :text="__('jobs.tasks.new')" />
<x-button :href="route('jobs.tasks.from-template', $job->id)" wire:navigate subtle color="black" icon="queue-list" :text="__('jobs.tasks.from_template.title')" />
</div>
@endif
@endcan
</div>
@can('jobs.manage-tasks', $job->id)
@unless ($job->status->allowsTasks())
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.not_allowed_yet') }}</p>
@endunless
@endcan
<p role="status" aria-live="polite" class="text-sm">{{ $taskStatusMessage }}</p>
@if ($this->tasks === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.empty') }}</p>
@else
@php($canChangeStatus = Gate::allows('jobs.update-task-status', $job->id))
@php($canManageTasks = Gate::allows('jobs.manage-tasks', $job->id))
{{--
Task cards are disclosures: collapsed by default, each opened on its own, so several can be open at once.
"Expand all" and "Collapse all" send a tasks-expand window event that every card follows. A card also opens
when focus moves into it (e.g. the status select keeps focus after a re-render).
--}}
<div
class="flex flex-wrap items-center gap-2"
x-data="{ message: '', expandedText: @js(__('jobs.tasks.all_expanded')), collapsedText: @js(__('jobs.tasks.all_collapsed')) }"
>
<x-button
x-on:click="$dispatch('tasks-expand', true); message = expandedText"
subtle
color="black"
sm
icon="chevron-double-down"
:text="__('jobs.tasks.expand_all')"
data-tasks-expand-all
/>
<x-button
x-on:click="$dispatch('tasks-expand', false); message = collapsedText"
subtle
color="black"
sm
icon="chevron-double-up"
:text="__('jobs.tasks.collapse_all')"
data-tasks-collapse-all
/>
<p role="status" aria-live="polite" class="text-sm" x-text="message"></p>
</div>
<ul class="space-y-3">
@foreach ($this->tasks as $task)
{{-- A notification links to #task-<id>: that card opens and comes into view. --}}
<li
id="task-{{ $task->id }}"
class="scroll-mt-24"
wire:key="task-{{ $task->id }}"
x-data="{ open: location.hash === '#task-{{ $task->id }}' }"
x-init="if (open) $nextTick(() => $el.scrollIntoView({ block: 'start' }))"
x-on:tasks-expand.window="open = $event.detail"
x-on:focusin="if ($event.target.closest('[data-task-details]')) open = true"
>
<article aria-labelledby="task-{{ $task->id }}-title" class="rounded-lg border border-zinc-200 bg-white text-sm dark:border-zinc-700 dark:bg-zinc-900">
<div class="flex flex-col gap-2 p-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-6">
<h3 id="task-{{ $task->id }}-title" class="min-w-0 text-base font-medium sm:flex-1">
<button
type="button"
id="task-toggle-{{ $task->id }}"
x-on:click="open = ! open"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="task-{{ $task->id }}-details"
class="flex min-h-6 w-full items-start gap-2 rounded-md text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400"
>
<x-icon name="chevron-right" class="mt-0.5 size-5 shrink-0 transition-transform" x-bind:class="{ 'rotate-90': open }" aria-hidden="true" />
<span class="min-w-0 break-words">{{ $task->title }}</span>
</button>
</h3>
<dl class="flex flex-col gap-1 ps-7 sm:flex-row sm:flex-wrap sm:gap-x-6 sm:ps-0">
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.fields.assignee') }}:</dt>
<dd>{{ $task->assignee?->name ?? __('jobs.calendar.no_assignee') }}</dd>
</div>
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.fields.due_on') }}:</dt>
<dd><x-jobs.due-date :date="$task->dueOn" :status="$task->status" /></dd>
</div>
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.fields.status') }}:</dt>
<dd>{{ __('jobs.tasks.statuses.'.$task->status->value) }}</dd>
</div>
@if ($task->commentCount > 0)
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.comments.title') }}:</dt>
<dd>{{ $task->commentCount }}</dd>
</div>
@endif
@if ($task->imageCount > 0)
<div class="flex flex-wrap gap-x-1">
<dt class="font-medium">{{ __('jobs.tasks.images.title') }}:</dt>
<dd>{{ $task->imageCount }}</dd>
</div>
@endif
</dl>
</div>
<div
id="task-{{ $task->id }}-details"
data-task-details
x-show="open"
x-cloak
class="space-y-3 border-t border-zinc-200 p-4 dark:border-zinc-700"
>
<dl class="grid gap-x-6 gap-y-1 sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('jobs.tasks.fields.work_type') }}</dt>
<dd>{{ $task->workType->name }}</dd>
@if ($task->members !== [])
<dt class="font-medium">{{ __('jobs.tasks.fields.members') }}</dt>
<dd>{{ collect($task->members)->pluck('name')->join(', ') }}</dd>
@endif
<dt class="font-medium">{{ __('jobs.tasks.schedule') }}</dt>
<dd>
@if ($task->plannedFrom === null)
{{ __('jobs.not_set') }}
@else
{{ __('jobs.tasks.schedule_range', ['from' => $this->formatDate($task->plannedFrom), 'to' => $this->formatDate($task->plannedTo)]) }}
@endif
</dd>
<dt class="font-medium">{{ __('jobs.tasks.fields.estimated_hours') }}</dt>
<dd>{{ $task->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $task->estimatedHours).' h' }}</dd>
</dl>
@if ($task->description !== null)
<p class="whitespace-pre-line">{{ $task->description }}</p>
@endif
<div class="flex flex-wrap items-end gap-3">
@if ($canChangeStatus)
<div class="w-full sm:w-56">
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
<x-select.native
id="task-status-{{ $task->id }}"
wire:change="changeTaskStatus({{ $task->id }}, $event.target.value)"
:label="__('jobs.tasks.fields.status')"
:aria-label="__('jobs.tasks.status_of', ['title' => $task->title])"
>
@foreach (TaskStatus::cases() as $status)
<option value="{{ $status->value }}" @selected($status === $task->status)>{{ __('jobs.tasks.statuses.'.$status->value) }}</option>
@endforeach
</x-select.native>
</div>
@endif
@if (! $job->status->locksTime() && Gate::allows('time.book', $job->id))
<x-button
:href="route('time.task', $task->id)"
wire:navigate
subtle
color="black"
sm
icon="clock"
:text="__('jobs.tasks.book_time')"
:aria-label="__('jobs.tasks.book_time_named', ['title' => $task->title])"
/>
@endif
@if ($canManageTasks)
<x-button
:href="route('jobs.tasks.edit', [$job->id, $task->id])"
wire:navigate
subtle
color="black"
sm
icon="pencil"
:text="__('jobs.edit')"
:aria-label="__('jobs.tasks.edit_named', ['title' => $task->title])"
/>
<x-button
wire:click="confirmTaskRemoval({{ $task->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('customers.remove')"
:aria-label="__('jobs.tasks.remove_named', ['title' => $task->title])"
/>
@endif
</div>
<x-tabs
id="task-{{ $task->id }}-tabs"
:label="__('jobs.tasks.tabs.label', ['title' => $task->title])"
:tabs="[
'notes' => __('jobs.tasks.tabs.notes'),
'images' => __('jobs.tasks.tabs.images'),
'materials' => __('jobs.tasks.tabs.materials'),
]"
class="pt-2"
>
<x-tabs.panel tabs-id="task-{{ $task->id }}-tabs" name="notes" class="space-y-3">
<livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'checklist-'.$task->id" />
<livewire:jobs::task-comments :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'comments-'.$task->id" />
</x-tabs.panel>
<x-tabs.panel tabs-id="task-{{ $task->id }}-tabs" name="images">
<livewire:jobs::task-images :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'images-'.$task->id" />
</x-tabs.panel>
{{-- The sections mark themselves data-task-section when they have something to show. --}}
<x-tabs.panel tabs-id="task-{{ $task->id }}-tabs" name="materials" class="group space-y-3">
<livewire:inventory::task-materials :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'materials-'.$task->id" />
<livewire:machines::task-machine :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'machine-'.$task->id" />
<p class="group-has-[[data-task-section]]:hidden">{{ __('jobs.tasks.tabs.no_materials') }}</p>
</x-tabs.panel>
</x-tabs>
</div>
</article>
</li>
@endforeach
</ul>
@endif
<x-confirm-dialog id="remove-task-dialog" :title="__('customers.removal.title')">
<p>
@if ($removalTaskId !== null)
{{ __('jobs.tasks.remove_question', ['title' => $removalTaskTitle]) }}
@endif
</p>
<x-slot:actions>
<x-button wire:click="removeTask" color="red" icon="trash" :text="__('customers.remove')" />
</x-slot:actions>
</x-confirm-dialog>
</section>
@can('expenses.record')
<section aria-labelledby="expenses-heading" class="space-y-3">
<h2 id="expenses-heading" class="text-xl font-semibold">{{ __('jobs.sections.expenses') }}</h2>
<x-link :href="route('expenses.job', $job->id)" navigate>{{ __('expenses.job_page.link') }}</x-link>
</section>
@endcan
<section aria-labelledby="links-heading" class="space-y-3">
<h2 id="links-heading" class="text-xl font-semibold">{{ __('jobs.sections.links') }}</h2>
@if ($job->links === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.links.none') }}</p>
@else
<ul class="list-disc space-y-1 pl-5 text-sm">
@foreach ($job->links as $link)
<li class="break-all">
<x-link :href="$link['url']" target="_blank" rel="noopener noreferrer">
{{ $link['title'] }}<span class="sr-only"> ({{ __('jobs.opens_in_new_tab') }})</span>
</x-link>
</li>
@endforeach
</ul>
@endif
</section>
<section aria-labelledby="instructions-heading" class="space-y-3">
<h2 id="instructions-heading" class="text-xl font-semibold">{{ __('jobs.sections.instructions') }}</h2>
<p class="whitespace-pre-line text-sm">{{ $job->instructions ?? __('jobs.not_set') }}</p>
</section>
<section aria-labelledby="history-heading" class="space-y-3" x-data="{ open: false }">
<h2 id="history-heading" class="text-xl font-semibold">
<button
type="button"
id="history-toggle"
x-on:click="open = ! open"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="history-panel"
class="flex min-h-6 items-center gap-2 rounded-md text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-400"
>
<x-icon name="chevron-right" class="size-5 shrink-0 transition-transform" x-bind:class="{ 'rotate-90': open }" aria-hidden="true" />
{{ __('jobs.sections.history') }}
<span class="text-base font-normal">{{ trans_choice('jobs.history.count', count($this->changes), ['count' => count($this->changes)]) }}</span>
</button>
</h2>
<div id="history-panel" x-show="open" x-cloak>
@if ($this->changes === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.history.empty') }}</p>
@else
<ol class="space-y-2 text-sm">
@foreach ($this->changes as $change)
<li class="border-b border-zinc-200 pb-2 dark:border-zinc-700">
@if ($change->field === 'created')
{{ __('jobs.history.created', ['user' => $change->userName, 'number' => $change->newValue]) }}
@else
<span class="break-words">{{ __('jobs.history.changed', [
'field' => __('jobs.fields.'.$change->field),
'old' => $this->historyValue($change->field, $change->oldValue),
'new' => $this->historyValue($change->field, $change->newValue),
]) }}</span>
@if ($change->field === 'status' && \App\Modules\Jobs\Domain\Enums\JobStatus::tryFrom((string) $change->oldValue)?->unlocksTo(\App\Modules\Jobs\Domain\Enums\JobStatus::from((string) $change->newValue)))
<span class="font-medium">{{ __('jobs.history.unlocked') }}</span>
@endif
@endif
<span class="block text-zinc-600 dark:text-zinc-300">
{{ __('jobs.history.by', ['user' => $change->userName, 'time' => CarbonImmutable::parse($change->changedAt)->format('j.n.Y H.i')]) }}
</span>
</li>
@endforeach
</ol>
@endif
</div>
</section>
</div>