import { Button } from '@ump/shared';
import { Input } from '@ump/shared';
import { Label } from '@ump/shared';

export interface AuditFilterFormState {
  fromLocal: string;
  toLocal: string;
  actorEmail: string;
  actorUserId: string;
  entityType: string;
  entityId: string;
  action: string;
}

interface AuditLogFiltersProps {
  value: AuditFilterFormState;
  onChange: (patch: Partial<AuditFilterFormState>) => void;
  onApply: () => void;
  onPreset24h: () => void;
  onPreset7d: () => void;
  onPreset30d: () => void;
}

export function AuditLogFilters({
  value,
  onChange,
  onApply,
  onPreset24h,
  onPreset7d,
  onPreset30d,
}: AuditLogFiltersProps) {
  return (
    <div className="space-y-4 rounded-lg border border-border bg-card p-4">
      <div className="flex flex-wrap gap-2">
        <span className="text-sm text-muted-foreground mr-2 self-center">Khoảng thời gian:</span>
        <Button type="button" variant="outline" size="sm" onClick={onPreset24h}>
          24 giờ
        </Button>
        <Button type="button" variant="outline" size="sm" onClick={onPreset7d}>
          7 ngày
        </Button>
        <Button type="button" variant="outline" size="sm" onClick={onPreset30d}>
          30 ngày
        </Button>
      </div>

      <div className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
        <div className="space-y-1.5">
          <Label htmlFor="audit-from">Từ (local)</Label>
          <Input
            id="audit-from"
            type="datetime-local"
            value={value.fromLocal}
            onChange={(e) => onChange({ fromLocal: e.target.value })}
          />
        </div>
        <div className="space-y-1.5">
          <Label htmlFor="audit-to">Đến (local)</Label>
          <Input
            id="audit-to"
            type="datetime-local"
            value={value.toLocal}
            onChange={(e) => onChange({ toLocal: e.target.value })}
          />
        </div>
        <div className="space-y-1.5">
          <Label htmlFor="audit-email">Actor email</Label>
          <Input
            id="audit-email"
            placeholder="name@ump.edu.vn"
            autoComplete="off"
            value={value.actorEmail}
            onChange={(e) => onChange({ actorEmail: e.target.value })}
          />
        </div>
        <div className="space-y-1.5">
          <Label htmlFor="audit-user-id">Actor user UUID</Label>
          <Input
            id="audit-user-id"
            placeholder="optional"
            autoComplete="off"
            value={value.actorUserId}
            onChange={(e) => onChange({ actorUserId: e.target.value })}
          />
        </div>
        <div className="space-y-1.5">
          <Label htmlFor="audit-etype">Loại entity</Label>
          <Input
            id="audit-etype"
            placeholder="application_evidence …"
            value={value.entityType}
            onChange={(e) => onChange({ entityType: e.target.value })}
          />
        </div>
        <div className="space-y-1.5">
          <Label htmlFor="audit-eid">ID entity</Label>
          <Input
            id="audit-eid"
            placeholder="case-id:role hoặc user id …"
            value={value.entityId}
            onChange={(e) => onChange({ entityId: e.target.value })}
          />
        </div>
        <div className="space-y-1.5 md:col-span-2">
          <Label htmlFor="audit-action">Hành động (CSV)</Label>
          <Input
            id="audit-action"
            placeholder="create,update,login,…"
            value={value.action}
            onChange={(e) => onChange({ action: e.target.value })}
          />
        </div>
      </div>

      <Button type="button" onClick={onApply}>
        Áp dụng bộ lọc
      </Button>
    </div>
  );
}
