'use client';

import { AlertTriangle, CalendarDays } from 'lucide-react';
import type { FlightError } from '@/services/flights/errors';
import './flight-results-notice.css';

/**
 * A line above the results explaining why they are not what was just asked for.
 *
 * Both cases it covers share one shape: the traveller changed something, the
 * results on screen did not change with it, and without a word here that reads
 * as the page being broken. Neither replaces the list — the previous results
 * are still the best answer available, and taking them away to show a message
 * would lose information the traveller is mid-way through using.
 */

/**
 * Round trip is selected but has no return date, so there is nothing to search.
 *
 * Announced politely rather than assertively: it is the expected consequence of
 * the traveller's own action, with the date picker already open beside it, not
 * an interruption.
 */
export function AwaitingReturnDateNotice() {
  return (
    <div
      className="alert d-flex align-items-start gap-2 mb-3 py-2 px-3 flight-results-notice flight-results-notice--info"
      role="status"
    >
      <CalendarDays size={16} aria-hidden="true" className="flex-shrink-0 mt-1" />
      <span className="text-sm mb-0">
        Select a return date to see round-trip prices. Showing your previous results until then.
      </span>
    </div>
  );
}

/**
 * The search failed but earlier results are still on screen.
 *
 * The retry is the point. An error with no way forward leaves the traveller
 * reloading the page to find out whether it was temporary.
 */
export function SearchFailedNotice({
  error,
  onRetry,
  isRetrying,
}: {
  error: FlightError;
  onRetry: () => void;
  isRetrying: boolean;
}) {
  return (
    <div
      className="alert d-flex flex-wrap align-items-center gap-2 mb-3 py-2 px-3 flight-results-notice flight-results-notice--warning"
      // Assertive, unlike the notice above: nothing the traveller did caused
      // this, and it changes what the results on screen can be trusted to mean.
      role="alert"
    >
      <AlertTriangle size={16} aria-hidden="true" className="flex-shrink-0" />
      <span className="text-sm mb-0 flex-grow-1">
        {error.message} Showing your previous results.
      </span>
      <button
        type="button"
        className="btn btn-sm flight-results-notice__retry"
        onClick={onRetry}
        disabled={isRetrying}
      >
        {isRetrying ? 'Retrying…' : 'Retry'}
      </button>
    </div>
  );
}
