json($context->current($r->user())); } public function focus(Request $r, InvestorContext $context) { return response()->json($context->focus($r->user(), $r->all())); } public function show(Request $r, string $id, InvestorContext $context) { return response()->json($context->view($r->user(), $id)); } public function options(Request $r, InvestorContext $context) { $d = $r->validate(['q' => 'nullable|string|max:120']); return response()->json($context->options($d['q'] ?? '')); } public function edit(Request $r, string $id, InvestorContext $context) { $data = $context->view($r->user(), $id); abort_unless($data['can_write'], 403); return Inertia::render('investor-path/context', ['initial' => $data, 'options' => $context->options(), 'source' => $r->query('source') ? $context->reference($r->validate(['source' => 'required|string|max:100'])['source']) : null, 'territorySelection' => isset($data['context']['selection']['territory']) ? app(InvestmentGeography::class)->path($data['context']['selection']['territory']['id']) : []]); } public function preview(Request $r, string $id, InvestorContext $context) { return response()->json($context->preview($r->user(), $id, $r->all())); } public function commit(Request $r, string $id, InvestorContext $context) { return response()->json($context->commit($r->user(), $id, $r->all())); } public function start(Request $r, InvestorPath $path, InvestorContext $context) { $d = $r->validate(['source' => 'nullable|string|max:100', 'step' => ['nullable', 'regex:/^S(0[1-9]|1[0-9])$/']]); $ref = isset($d['source']) ? $context->reference($d['source']) : null; return Inertia::render('investor-path/context-start', ['contexts' => $path->contexts($r->user()), 'source' => $ref, 'step' => $d['step'] ?? null]); } public function installation(Request $r, InvestorContextInstallation $install) { $plan = $install->preview($r->user()); return $r->expectsJson() ? response()->json($plan) : Inertia::render('investor-path/context-installation', ['plan' => $plan]); } public function install(Request $r, InvestorContextInstallation $install) { return response()->json($install->apply($r->user(),$r->all())); } }