@extends('layouts.app') @section('title', $cropPlan->name) @section('content') {{-- Header --}}

{{ $cropPlan->name }}

{{ $cropPlan->crop }} · {{ $cropPlan->location }} · {{ date('F', mktime(0,0,0,$cropPlan->planting_month,1)) }}

@csrf
What-If Edit
@csrf @method('PATCH')
@csrf @method('DELETE')
@if(!$latestResult)

No analysis yet for this plan.

@csrf
@else @php $label = $latestResult->feasibility_label; $isNotSuitable = $label === 'not_suitable'; $marketDegraded = !$latestResult->market_price_per_quintal; $confidence = round($latestResult->feasibility_confidence * 100); $stampClass = match($label) { 'suitable' => 'verdict-suitable', 'risky' => 'verdict-risky', 'not_suitable' => 'verdict-not-suitable', default => 'verdict-risky' }; $stampIcon = match($label) { 'suitable' => 'bi-check-circle', 'risky' => 'bi-exclamation-triangle', 'not_suitable' => 'bi-x-circle', default => 'bi-question-circle' }; $stampText = match($label) { 'suitable' => 'Suitable', 'risky' => 'Risky', 'not_suitable' => 'Not Suitable', default => 'Unknown' }; @endphp {{-- Verdict stamp --}}
{{ $stampText }}
{{ $confidence }}% confidence

{{ $latestResult->crop }} — {{ $latestResult->location }}

Planting window: {{ date('F', mktime(0,0,0,$latestResult->month,1)) }} · Analyzed {{ $latestResult->created_at->diffForHumans() }}

{{-- Key factors — hide temperature if not available --}} @if($latestResult->top_factors) @php $factors = collect($latestResult->top_factors) ->filter(fn($f) => !str_contains($f, 'temp') || $latestResult->forecast_temp_c !== null) ->values(); @endphp @if($factors->count())
Key factors: @foreach($factors as $factor) {{ str_replace('_', ' ', $factor) }} @endforeach
@endif @endif {{-- Conflicts --}} @if($latestResult->conflicts && count($latestResult->conflicts) > 0)
Worth knowing before you decide:
    @foreach($latestResult->conflicts as $conflict)
  • {{ $conflict }}
  • @endforeach
@endif
{{-- Main data grid --}}
{{-- Climate --}}

Climate Assessment @if($latestResult->climate_anomaly_label === 'unknown') Limited data @endif

Forecast rainfall {{ $latestResult->forecast_rainfall_mm ? $latestResult->forecast_rainfall_mm . ' mm' : '—' }}
Temperature {{ $latestResult->forecast_temp_c ? $latestResult->forecast_temp_c . ' °C' : '—' }}
Anomaly level {{ $latestResult->climate_anomaly_label ?? '—' }} @if($latestResult->climate_anomaly_score && $latestResult->climate_anomaly_label !== 'unknown') ({{ $latestResult->climate_anomaly_score }}) @endif
{{-- Yield — only show when suitable or risky --}} {{--

Yield Forecast

@if($isNotSuitable)
Yield estimate is not shown for crops rated not suitable. See alternative crops below for viable options.
@else
Expected yield {{ $latestResult->expected_yield_ton_ha }} t/ha
Uncertainty ± {{ $latestResult->yield_uncertainty }} t/ha
Range {{ round($latestResult->expected_yield_ton_ha - $latestResult->yield_uncertainty, 2) }} – {{ round($latestResult->expected_yield_ton_ha + $latestResult->yield_uncertainty, 2) }} t/ha
@endif
--}} {{-- Trend --}}

Multi-Year Trend

@php $trendIcon = match($latestResult->trend) { 'upward' => 'bi-graph-up-arrow', 'downward' => 'bi-graph-down-arrow', 'stable' => 'bi-dash-lg', 'volatile' => 'bi-shuffle', default => 'bi-question-circle' }; @endphp
Direction {{ $latestResult->trend ?? '—' }}
Confidence {{ round($latestResult->trend_confidence * 100) }}%
{{-- Market --}}

Market Intelligence @if($marketDegraded) Limited data @endif

@if($marketDegraded)
Market forecast unavailable — insufficient recent price history for this crop. Consult your local mandi or Agmarknet for current prices.
@else
Price per kg ₹{{ $latestResult->price_per_kg ?? '—' }}
Price range per kg ₹{{ $latestResult->min_price_per_kg ?? '—' }} – ₹{{ $latestResult->max_price_per_kg ?? '—' }}
Price per quintal ₹{{ $latestResult->market_price_per_quintal ?? '—' }}
Demand level {{ $latestResult->demand_level ?? '—' }}
@if($latestResult->market_data_date)
Data as of {{ $latestResult->market_data_date }}
@endif @endif
{{-- Profit / Loss — only show when not not_suitable AND market not degraded --}} {{-- @if(!$isNotSuitable && !$marketDegraded) --}} {{--

Profit & Loss Estimate (per hectare)

Estimated profit ₹{{ number_format($latestResult->estimated_profit_per_ha) }}
Loss risk (worst case) ₹{{ number_format($latestResult->estimated_loss_risk_per_ha) }}
Price used Market model

Profit = (expected yield × price per tonne) − input costs. Loss risk uses the lower end of the yield uncertainty range. These are estimates — actual results depend on local conditions.

@elseif(!$isNotSuitable && $marketDegraded)

Profit & Loss Estimate

Profit estimate cannot be calculated — market price data is unavailable for this crop. Once price history is available, this section will show a full profit/loss breakdown.
@endif --}} {{-- Alternatives --}} @if($latestResult->alternatives && count($latestResult->alternatives) > 0)

Alternative Crops Worth Considering @if($latestResult->recommendation_degraded ?? false) Indicative only @endif

@if($latestResult->recommendation_degraded ?? false)

Rankings are based on climate and agronomic fit only. Market demand data is unavailable so scores may not reflect economic conditions.

@endif
@foreach($latestResult->alternatives as $alt) @php $score = $alt['score'] ?? 0; $scorePct = round(min(max($score, 0), 1) * 100); @endphp @endforeach
Crop Suitability Score Score Bar
{{ $alt['crop'] ?? '' }} {{ $scorePct }}%
@endif {{-- Explanation --}}

In Plain Terms

{{ $latestResult->explanation }}
{{-- Models used --}}

Models Used in This Analysis

@php $models = json_decode($latestResult->models_used, true) ?? []; @endphp
@foreach($models as $name => $desc) @endforeach
Model Description
{{ $name }} {{ $desc }}
{{-- Training data sources --}}

Training Data Sources

@php $sources = json_decode($latestResult->training_data_sources, true) ?? []; @endphp
@foreach($sources as $source => $detail) @endforeach
Source Details
{{ $source }} {{ $detail }}
{{-- Meta --}}
Model version: {{ $latestResult->model_version }} · Processed in {{ $latestResult->processing_ms }}ms · {{ $latestResult->degraded ? 'Some models returned degraded results — see badges above' : 'All models ran successfully' }}
@endif @endsection