---
import type { DateField } from '../../resource-types';

interface Props {
  field: DateField;
  value: unknown;
}

const { field, value } = Astro.props;

// Coerce ISO datetime → "YYYY-MM-DD" for the <input type="date"> control.
function toDateInputValue(v: unknown): string {
  if (v == null || v === '') return '';
  const s = String(v);
  const m = s.match(/^(\d{4}-\d{2}-\d{2})/);
  return m ? m[1] : '';
}
const v = toDateInputValue(value);
---

<input
  type="date"
  id={`f-${field.key}`}
  name={field.key}
  class="bs-input"
  value={v}
  required={field.required}
  readonly={field.readOnly}
/>
