@extends('layouts.app')

@section('title', $companyPolicy->name)
@section('heading', $companyPolicy->name)

@section('content')
    <x-card>
        <div class="mb-4 flex flex-wrap items-center justify-between gap-3">
            <a href="{{ route('company-policies.portal') }}" class="text-sm text-primary hover:underline">&larr; All policies</a>
            @if(auth()->user()?->hasPermission('hr_operations_view'))
                <a href="{{ route('company-policies.acknowledgments', $companyPolicy) }}" class="text-sm text-slate-600 hover:underline">View acknowledgments</a>
            @endif
        </div>
        @if(session('success'))
            <div class="mb-4 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-800">{{ session('success') }}</div>
        @endif
        @if($companyPolicy->description)
            <p class="mb-4 text-sm text-slate-600">{{ $companyPolicy->description }}</p>
        @endif
        <div class="prose prose-slate max-w-none text-sm">
            {!! nl2br(e($companyPolicy->content ?? 'No content available.')) !!}
        </div>

        @if($acknowledged)
            <p class="mt-6 text-sm font-medium text-emerald-700">You have acknowledged this policy.</p>
        @else
            <form action="{{ route('company-policies.acknowledge', $companyPolicy) }}" method="post" class="mt-6">
                @csrf
                <button type="submit" class="rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-white">I have read and acknowledge this policy</button>
            </form>
        @endif
    </x-card>
@endsection
