---
import { localizedPath } from '@/i18n/utils';
import CountryFormFields from '@/components/admin/CountryFormFields.astro';
import type { CountryFormValues } from '@/lib/countries/form';
import type { IsoCountryOption } from '@/lib/countries/iso';
import type { Locale } from '@/data/site';

interface Props {
  lang: Locale;
  form: CountryFormValues;
  error: string | null;
  countryOptions: IsoCountryOption[];
  excludeCodes: string[];
  isEdit?: boolean;
  isoCode?: string;
}

const { lang, form, error, countryOptions, excludeCodes, isEdit = false, isoCode = '' } = Astro.props;
---

<form method="POST" class="mx-auto max-w-4xl space-y-6">
  {error && <div class="alert alert-error text-sm">{error}</div>}

  <CountryFormFields
    locale={lang}
    form={form}
    isEdit={isEdit}
    isoCode={isoCode}
    countryOptions={countryOptions}
    excludeCodes={excludeCodes}
  />

  <div class="flex gap-3">
    <button type="submit" class="btn btn-primary">
      {lang === 'ar' ? 'حفظ' : 'Save'}
    </button>
    <a href={localizedPath(lang, 'admin/countries')} class="btn btn-ghost">
      {lang === 'ar' ? 'إلغاء' : 'Cancel'}
    </a>
  </div>
</form>
