<x-layouts.app :title="__('competitors.title')"><x-customer-shell><header class="tp-page-header"><div><p>{{__('customer.reports')}}</p><h1>{{__('competitors.title')}}</h1><span>{{__('competitors.description')}}</span></div></header>
@if($projects->isEmpty())<section class="tp-panel">{{__('competitors.empty_projects')}}</section>@else<section class="tp-panel mb-3"><form method="get" class="d-flex gap-2"><select name="project" class="form-select">@foreach($projects as $p)<option value="{{$p->ulid}}" @selected($project?->is($p))>{{$p->name}}</option>@endforeach</select><button class="btn btn-primary">{{__('losers.filter')}}</button></form></section>
<section class="tp-panel mb-3"><h2 class="h5">{{__('competitors.add')}}</h2><form method="post" action="{{route('competitors.store',$project)}}" class="tp-competitor-form">@csrf<input class="form-control" name="name" placeholder="{{__('competitors.name')}}"><input class="form-control" name="domain" required placeholder="{{__('competitors.domain')}}"><button class="btn btn-primary">{{__('competitors.add')}}</button></form>@error('domain')<p class="text-danger">{{$message}}</p>@enderror<table class="table mt-3"><tbody>@forelse($project->competitors as $c)<tr><td>{{$c->name}}</td><td>{{$c->normalized_domain}}</td><td>{{__('competitors.'.$c->status)}}</td><td><a href="{{route('competitors.show',[$project,$c])}}">{{__('competitors.view')}}</a></td></tr>@empty<tr><td>{{__('competitors.empty_competitors')}}</td></tr>@endforelse</tbody></table></section>
@if($data&&$competitors->isNotEmpty())@php($strong=$competitors->sortByDesc(fn($c)=>$data['scores'][$c->normalized_domain]??0)->first())<div class="tp-metric-grid mb-3"><x-metric-card :label="__('competitors.your_visibility')" :value="number_format($data['scores'][$project->domain]??0,2).'%'"/><x-metric-card :label="__('competitors.strongest')" :value="$strong?->name"/><x-metric-card :label="__('competitors.lead')" :value="$data['lead']"/><x-metric-card :label="__('competitors.trail')" :value="$data['trail']"/><x-metric-card :label="__('competitors.shared')" :value="$data['shared']"/><x-metric-card :label="__('competitors.unranked')" :value="$data['unranked']"/></div><section class="tp-panel"><div class="table-responsive"><table class="table"><thead><tr><th>{{__('competitors.keyword')}}</th><th>{{__('competitors.your_rank')}}</th><th>{{__('competitors.competitor_rank')}}</th><th>{{__('competitors.gap')}}</th><th>{{__('competitors.leader')}}</th></tr></thead><tbody>@forelse($data['rows'] as $row)<tr><td>{{$row['keyword']->phrase}}</td><td>{{$row['own']??'—'}}</td><td>{{$row['rival']??'—'}}</td><td>{{$row['gap']??'—'}}</td><td>{{__('competitors.'.($row['leader']==='you'?'you_lead':($row['leader']==='competitor'?'competitor_leads':($row['leader']==='tied'?'tied':'no_measurement'))))}}</td></tr>@empty<tr><td colspan="5">{{__('competitors.empty_data')}}</td></tr>@endforelse</tbody></table></div></section>@endif @endif</x-customer-shell></x-layouts.app>
