"use client";

import { useActionState } from "react";
import { createBundleAction } from "@/lib/actions/bundles";

export function NewBundleForm() {
  const [state, formAction, pending] = useActionState(createBundleAction, {});

  return (
    <form action={formAction} className="bg-[var(--rk-surface)] border border-white/10 rounded-2xl p-5 flex flex-col gap-3 mb-8">
      <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
        <input
          name="title"
          placeholder="Titel, z. B. Jahres-Paket (3 Shootings)"
          required
          className="bg-transparent border border-white/15 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-white/50"
        />
        <input
          name="titleEn"
          placeholder="Titel (Englisch, optional)"
          className="bg-transparent border border-white/15 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-white/50"
        />
      </div>
      <textarea
        name="description"
        placeholder="Was ist enthalten? (Deutsch)"
        rows={3}
        className="bg-transparent border border-white/15 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:border-white/50 resize-y"
      />
      <textarea
        name="descriptionEn"
        placeholder="Was ist enthalten? (Englisch, optional)"
        rows={3}
        className="bg-transparent border border-white/15 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:border-white/50 resize-y"
      />
      <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
        <input
          name="price"
          type="number"
          min="0"
          step="0.01"
          placeholder="Paketpreis in €"
          required
          className="bg-transparent border border-white/15 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-white/50"
        />
        <input
          name="compareAtPrice"
          type="number"
          min="0"
          step="0.01"
          placeholder="Regulärer Preis (optional, für Du-sparst-Anzeige)"
          className="bg-transparent border border-white/15 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-white/50"
        />
      </div>
      <label className="flex items-center gap-2 text-sm">
        <input type="checkbox" name="active" defaultChecked className="h-3.5 w-3.5" />
        Sofort sichtbar auf der Angebote-Seite
      </label>
      <button
        type="submit"
        disabled={pending}
        className="self-start border border-white/30 rounded-lg px-4 py-2 text-xs uppercase tracking-[0.15em] hover:border-white disabled:opacity-50"
      >
        Paket anlegen
      </button>
      {state.error && <p className="text-sm text-red-400">{state.error}</p>}
    </form>
  );
}
