%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/views/
Upload File :
Create Path :
Current File : //home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/views/PaketFormView.tsx

import React, { useState } from 'react';
import {
  Store, Calendar, Layers, Users, Globe, UserCheck, Package,
  DollarSign, Tag, Code, Shield, Search, Lightbulb, Check, ChevronDown,
  Crown, Star, Zap, Sprout, CalendarDays, ArrowLeft
} from 'lucide-react';

interface PaketFormViewProps {
  initialData?: any; // If editing
  onBack: () => void;
  triggerToast: (msg: string) => void;
}

interface FeatureItem {
  id: string;
  title: string;
  description: string;
  icon: React.ElementType;
  iconBg: string;
  iconColor: string;
  checked: boolean;
}

export const PaketFormView: React.FC<PaketFormViewProps> = ({ initialData, onBack, triggerToast }) => {
  const isEdit = !!initialData;

  // Form State
  const [packageName, setPackageName] = useState(initialData?.name || '');
  const [packageType, setPackageType] = useState(initialData?.type || '');
  const [packageDescription, setPackageDescription] = useState(initialData?.description || initialData?.detailDescription || '');
  const [colorHex, setColorHex] = useState('#EC167F');
  const [selectedIcon, setSelectedIcon] = useState('Crown');
  const [badgeText, setBadgeText] = useState(initialData?.badge || '');

  const [price, setPrice] = useState(initialData?.price ? initialData.price.replace(/[^\d]/g, '') : '0');
  const [minTenant, setMinTenant] = useState(initialData?.minTenant === '-' ? '' : initialData?.minTenant || '');
  const [maxTenant, setMaxTenant] = useState(initialData?.maxTenant === '-' ? '' : initialData?.maxTenant || '');
  const [billingCycle, setBillingCycle] = useState(initialData?.billing || 'Bulanan');
  const [currency, setCurrency] = useState('IDR - Rupiah (Rp)');

  const [status, setStatus] = useState<'Aktif' | 'Nonaktif'>(initialData?.status || 'Aktif');

  // Search feature query
  const [featureSearch, setFeatureSearch] = useState('');

  // Feature Checklist state
  const [features, setFeatures] = useState<FeatureItem[]>([
    {
      id: 'reservasi',
      title: 'Manajemen Reservasi',
      description: 'Kelola reservasi dan jadwal secara lengkap',
      icon: Calendar,
      iconBg: 'bg-amber-100/80',
      iconColor: 'text-amber-600',
      checked: true,
    },
    {
      id: 'layanan',
      title: 'Manajemen Layanan',
      description: 'Kelola layanan, kategori, dan harga',
      icon: Layers,
      iconBg: 'bg-blue-100/80',
      iconColor: 'text-blue-600',
      checked: true,
    },
    {
      id: 'crm',
      title: 'CRM & Pelanggan',
      description: 'Kelola pelanggan dan riwayat interaksi',
      icon: Users,
      iconBg: 'bg-emerald-100/80',
      iconColor: 'text-emerald-600',
      checked: true,
    },
    {
      id: 'website',
      title: 'Website Builder',
      description: 'Buat dan kelola website bisnis sendiri',
      icon: Globe,
      iconBg: 'bg-orange-100/80',
      iconColor: 'text-orange-600',
      checked: true,
    },
    {
      id: 'tim',
      title: 'Manajemen Tim',
      description: 'Kelola tim, role, dan hak akses',
      icon: UserCheck,
      iconBg: 'bg-purple-100/80',
      iconColor: 'text-purple-600',
      checked: true,
    },
    {
      id: 'inventaris',
      title: 'Inventaris',
      description: 'Kelola stok produk dan inventaris',
      icon: Package,
      iconBg: 'bg-indigo-100/80',
      iconColor: 'text-indigo-600',
      checked: true,
    },
    {
      id: 'keuangan',
      title: 'Keuangan',
      description: 'Laporan keuangan dan analitik bisnis',
      icon: DollarSign,
      iconBg: 'bg-teal-100/80',
      iconColor: 'text-teal-600',
      checked: true,
    },
    {
      id: 'promosi',
      title: 'Promosi & Diskon',
      description: 'Buat promo, diskon, dan voucher',
      icon: Tag,
      iconBg: 'bg-pink-100/80',
      iconColor: 'text-pink-600',
      checked: false,
    },
    {
      id: 'api',
      title: 'API Access',
      description: 'Akses API untuk integrasi sistem',
      icon: Code,
      iconBg: 'bg-slate-100',
      iconColor: 'text-slate-600',
      checked: false,
    },
    {
      id: 'domain',
      title: 'Custom Domain',
      description: 'Gunakan domain khusus untuk website',
      icon: Globe,
      iconBg: 'bg-sky-100/80',
      iconColor: 'text-sky-600',
      checked: false,
    },
    {
      id: 'whitelabel',
      title: 'White Label',
      description: 'Hilangkan branding MuaKita di platform',
      icon: Shield,
      iconBg: 'bg-violet-100/80',
      iconColor: 'text-violet-600',
      checked: false,
    }
  ]);

  const toggleFeature = (id: string) => {
    setFeatures(prev =>
      prev.map(f => (f.id === id ? { ...f, checked: !f.checked } : f))
    );
  };

  const selectAllFeatures = () => {
    const allChecked = features.every(f => f.checked);
    setFeatures(prev => prev.map(f => ({ ...f, checked: !allChecked })));
  };

  const selectedFeaturesCount = features.filter(f => f.checked).length;

  const filteredFeatures = features.filter(
    f =>
      f.title.toLowerCase().includes(featureSearch.toLowerCase()) ||
      f.description.toLowerCase().includes(featureSearch.toLowerCase())
  );

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    if (!packageName) {
      triggerToast('Mohon isi nama paket');
      return;
    }
    triggerToast(isEdit ? `Paket "${packageName}" berhasil diperbarui!` : `Paket "${packageName}" berhasil dibuat!`);
    onBack();
  };

  return (
    <div className="space-y-6 animate-in fade-in duration-200 text-slate-800 pb-16">
      
      {/* Back button & Header */}
      <div>
        <button
          onClick={onBack}
          className="inline-flex items-center gap-1.5 text-xs font-bold text-slate-500 hover:text-slate-900 transition-colors mb-3 cursor-pointer"
        >
          <ArrowLeft className="w-4 h-4" />
          <span>Kembali ke Daftar Paket</span>
        </button>

        <div className="flex items-center gap-3">
          <div className="w-10 h-10 rounded-2xl bg-pink-100 text-[#EC167F] flex items-center justify-center shrink-0 border border-pink-200 shadow-2xs">
            <Store className="w-5 h-5" />
          </div>
          <div>
            <h1 className="text-lg font-black text-slate-900 leading-tight">
              {isEdit ? 'Edit Paket' : 'Tambah Paket Baru'}
            </h1>
            <p className="text-xs text-slate-500">
              {isEdit
                ? 'Ubah informasi dan konfigurasi paket berlangganan.'
                : 'Buat paket berlangganan baru untuk tenant di platform MuaKita.'}
            </p>
          </div>
        </div>
      </div>

      {/* Main 2-Column Grid */}
      <form onSubmit={handleSubmit} className="grid grid-cols-1 lg:grid-cols-12 gap-5 items-start">
        
        {/* LEFT COLUMN (Informasi Paket, Harga, Status) - Spans 7 columns */}
        <div className="lg:col-span-7 space-y-5">
          
          {/* 1. INFORMASI PAKET */}
          <div className="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-2xs space-y-4">
            <h2 className="text-xs font-extrabold text-slate-900 tracking-wide uppercase">
              Informasi Paket
            </h2>

            <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
              {/* Nama Paket */}
              <div className="space-y-1">
                <div className="flex items-center justify-between">
                  <label className="text-xs font-extrabold text-slate-700">
                    Nama Paket <span className="text-pink-500">*</span>
                  </label>
                  <span className="text-[10px] text-slate-400">{packageName.length}/50</span>
                </div>
                <input
                  type="text"
                  maxLength={50}
                  placeholder="Contoh: Enterprise"
                  value={packageName}
                  onChange={(e) => setPackageName(e.target.value)}
                  className="w-full bg-white border border-slate-200 text-xs font-medium py-2.5 px-3 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 placeholder-slate-400"
                  required
                />
              </div>

              {/* Tipe Paket */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700">
                  Tipe Paket <span className="text-pink-500">*</span>
                </label>
                <div className="relative">
                  <select
                    value={packageType}
                    onChange={(e) => setPackageType(e.target.value)}
                    className="w-full appearance-none bg-white border border-slate-200 text-xs font-medium py-2.5 pl-3 pr-8 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 cursor-pointer"
                    required
                  >
                    <option value="">Pilih tipe paket</option>
                    <option value="Premium">Premium</option>
                    <option value="Pro">Pro</option>
                    <option value="Basic">Basic</option>
                    <option value="Custom">Custom</option>
                    <option value="Trial">Trial</option>
                  </select>
                  <ChevronDown className="w-4 h-4 text-slate-400 absolute right-3 top-2.5 pointer-events-none" />
                </div>
              </div>
            </div>

            {/* Deskripsi Paket */}
            <div className="space-y-1">
              <div className="flex items-center justify-between">
                <label className="text-xs font-extrabold text-slate-700">
                  Deskripsi Paket <span className="text-pink-500">*</span>
                </label>
                <span className="text-[10px] text-slate-400">{packageDescription.length}/300</span>
              </div>
              <textarea
                rows={3}
                maxLength={300}
                placeholder="Jelaskan paket ini secara singkat, manfaat, dan untuk siapa paket ini cocok..."
                value={packageDescription}
                onChange={(e) => setPackageDescription(e.target.value)}
                className="w-full bg-white border border-slate-200 text-xs font-medium p-3 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 placeholder-slate-400 resize-none"
                required
              />
            </div>

            {/* Warna, Ikon, Badge */}
            <div className="grid grid-cols-1 sm:grid-cols-3 gap-3 pt-1">
              
              {/* Warna & Ikon */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700 block">
                  Warna & Ikon
                </label>
                <div className="flex items-center gap-2 border border-slate-200 rounded-xl p-1.5 bg-white">
                  <div
                    className="w-6 h-6 rounded-lg shrink-0 border border-slate-200 shadow-2xs"
                    style={{ backgroundColor: colorHex }}
                  />
                  <input
                    type="text"
                    value={colorHex}
                    onChange={(e) => setColorHex(e.target.value)}
                    className="w-full text-xs font-bold text-slate-700 bg-transparent focus:outline-none"
                  />
                </div>
              </div>

              {/* Pilih Ikon */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700 block">
                  Pilih Ikon
                </label>
                <div className="relative">
                  <select
                    value={selectedIcon}
                    onChange={(e) => setSelectedIcon(e.target.value)}
                    className="w-full appearance-none bg-white border border-slate-200 text-xs font-medium py-2 Pl-3 pr-8 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 cursor-pointer"
                  >
                    <option value="Crown">👑 Crown</option>
                    <option value="Star">⭐ Star</option>
                    <option value="Zap">⚡ Zap</option>
                    <option value="Sprout">🌱 Sprout</option>
                    <option value="CalendarDays">📅 CalendarDays</option>
                  </select>
                  <ChevronDown className="w-4 h-4 text-slate-400 absolute right-3 top-2.5 pointer-events-none" />
                </div>
              </div>

              {/* Badge (Opsional) */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700 block">
                  Badge (Opsional)
                </label>
                <input
                  type="text"
                  placeholder="Contoh: Populer, Best Seller"
                  value={badgeText}
                  onChange={(e) => setBadgeText(e.target.value)}
                  className="w-full bg-white border border-slate-200 text-xs font-medium py-2 px-3 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 placeholder-slate-400"
                />
              </div>

            </div>

          </div>

          {/* 2. HARGA & BILLING */}
          <div className="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-2xs space-y-4">
            <h2 className="text-xs font-extrabold text-slate-900 tracking-wide uppercase">
              Harga & Billing
            </h2>

            <div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
              
              {/* Harga per bulan */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700">
                  Harga (per bulan) <span className="text-pink-500">*</span>
                </label>
                <div className="flex items-center border border-slate-200 rounded-xl overflow-hidden focus-within:border-pink-500 bg-white">
                  <span className="px-3 text-xs font-bold text-slate-400 bg-slate-50 border-r border-slate-200 py-2.5">
                    Rp
                  </span>
                  <input
                    type="number"
                    placeholder="0"
                    value={price}
                    onChange={(e) => setPrice(e.target.value)}
                    className="w-full text-xs font-bold text-slate-900 p-2.5 focus:outline-none"
                    required
                  />
                </div>
              </div>

              {/* Minimal Tenant */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700">
                  Minimal Tenant
                </label>
                <input
                  type="text"
                  placeholder="-"
                  value={minTenant}
                  onChange={(e) => setMinTenant(e.target.value)}
                  className="w-full bg-white border border-slate-200 text-xs font-medium py-2.5 px-3 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 placeholder-slate-400"
                />
                <span className="text-[10px] text-slate-400 block">Kosongkan jika tidak ada minimum</span>
              </div>

              {/* Maksimal Tenant */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700">
                  Maksimal Tenant
                </label>
                <input
                  type="text"
                  placeholder="-"
                  value={maxTenant}
                  onChange={(e) => setMaxTenant(e.target.value)}
                  className="w-full bg-white border border-slate-200 text-xs font-medium py-2.5 px-3 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 placeholder-slate-400"
                />
                <span className="text-[10px] text-slate-400 block">Kosongkan jika tidak ada batasan</span>
              </div>

            </div>

            <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
              
              {/* Siklus Billing */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700">
                  Siklus Billing <span className="text-pink-500">*</span>
                </label>
                <div className="relative">
                  <select
                    value={billingCycle}
                    onChange={(e) => setBillingCycle(e.target.value)}
                    className="w-full appearance-none bg-white border border-slate-200 text-xs font-medium py-2.5 pl-3 pr-8 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 cursor-pointer"
                  >
                    <option value="Bulanan">Bulanan</option>
                    <option value="Tahunan">Tahunan</option>
                    <option value="Kustom">Kustom</option>
                  </select>
                  <ChevronDown className="w-4 h-4 text-slate-400 absolute right-3 top-2.5 pointer-events-none" />
                </div>
              </div>

              {/* Mata Uang */}
              <div className="space-y-1">
                <label className="text-xs font-extrabold text-slate-700">
                  Mata Uang <span className="text-pink-500">*</span>
                </label>
                <div className="relative">
                  <select
                    value={currency}
                    onChange={(e) => setCurrency(e.target.value)}
                    className="w-full appearance-none bg-white border border-slate-200 text-xs font-medium py-2.5 pl-3 pr-8 rounded-xl focus:outline-none focus:border-pink-500 text-slate-900 cursor-pointer"
                  >
                    <option value="IDR - Rupiah (Rp)">IDR - Rupiah (Rp)</option>
                    <option value="USD - US Dollar ($)">USD - US Dollar ($)</option>
                  </select>
                  <ChevronDown className="w-4 h-4 text-slate-400 absolute right-3 top-2.5 pointer-events-none" />
                </div>
              </div>

            </div>

            {/* Tips Banner */}
            <div className="p-3.5 bg-pink-50/60 border border-pink-100 rounded-xl flex items-start gap-2.5">
              <Lightbulb className="w-4 h-4 text-pink-500 shrink-0 mt-0.5" />
              <div>
                <span className="text-xs font-bold text-pink-600 block">Tips</span>
                <p className="text-[11px] text-pink-800 leading-snug">
                  Harga yang Anda tetapkan akan menjadi dasar penagihan ke tenant setiap siklus.
                </p>
              </div>
            </div>

          </div>

          {/* 3. STATUS PAKET */}
          <div className="bg-white p-5 rounded-2xl border border-slate-200/80 shadow-2xs space-y-3">
            <div>
              <h2 className="text-xs font-extrabold text-slate-900 tracking-wide uppercase">
                Status Paket
              </h2>
              <p className="text-[11px] text-slate-400">Atur status paket setelah dibuat</p>
            </div>

            <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
              
              {/* Aktif Option Card */}
              <div
                onClick={() => setStatus('Aktif')}
                className={`p-3.5 rounded-xl border-2 transition-all cursor-pointer flex items-start gap-3 ${
                  status === 'Aktif'
                    ? 'border-pink-500 bg-pink-50/20 shadow-2xs'
                    : 'border-slate-200 hover:border-slate-300 bg-white'
                }`}
              >
                <span className="w-2.5 h-2.5 rounded-full bg-emerald-500 shrink-0 mt-1" />
                <div>
                  <span className="text-xs font-extrabold text-slate-900 block leading-tight">
                    Aktif
                  </span>
                  <span className="text-[11px] text-slate-500 leading-snug block mt-0.5">
                    Paket langsung tersedia untuk digunakan tenant
                  </span>
                </div>
              </div>

              {/* Nonaktif Option Card */}
              <div
                onClick={() => setStatus('Nonaktif')}
                className={`p-3.5 rounded-xl border-2 transition-all cursor-pointer flex items-start gap-3 ${
                  status === 'Nonaktif'
                    ? 'border-pink-500 bg-pink-50/20 shadow-2xs'
                    : 'border-slate-200 hover:border-slate-300 bg-white'
                }`}
              >
                <span className="w-2.5 h-2.5 rounded-full bg-slate-400 shrink-0 mt-1" />
                <div>
                  <span className="text-xs font-extrabold text-slate-900 block leading-tight">
                    Nonaktif
                  </span>
                  <span className="text-[11px] text-slate-500 leading-snug block mt-0.5">
                    Paket disimpan sebagai draft, tidak ditampilkan
                  </span>
                </div>
              </div>

            </div>

          </div>

        </div>

        {/* RIGHT COLUMN (Fitur Paket Checklist) - Spans 5 columns */}
        <div className="lg:col-span-5 bg-white p-5 rounded-2xl border border-slate-200/80 shadow-2xs space-y-4">
          
          {/* Header Title & Select All */}
          <div className="flex items-center justify-between">
            <div>
              <h2 className="text-xs font-extrabold text-slate-900 tracking-wide uppercase">
                Fitur Paket
              </h2>
              <p className="text-[11px] text-slate-400">Pilih fitur yang akan tersedia di paket ini.</p>
            </div>

            <button
              type="button"
              onClick={selectAllFeatures}
              className="text-xs font-extrabold text-pink-600 hover:text-pink-700 hover:underline cursor-pointer"
            >
              Pilih Semua
            </button>
          </div>

          {/* Search Features Input */}
          <div className="relative">
            <Search className="w-3.5 h-3.5 text-slate-400 absolute left-3 top-2.5" />
            <input
              type="text"
              placeholder="Cari fitur..."
              value={featureSearch}
              onChange={(e) => setFeatureSearch(e.target.value)}
              className="w-full bg-slate-50 border border-slate-200 text-xs font-medium py-2 pl-8 pr-3 rounded-xl focus:outline-none focus:border-pink-500 text-slate-800 placeholder-slate-400"
            />
          </div>

          {/* Features List */}
          <div className="space-y-2 max-h-[500px] overflow-y-auto pr-1">
            {filteredFeatures.map((feat) => {
              const IconComp = feat.icon;

              return (
                <div
                  key={feat.id}
                  onClick={() => toggleFeature(feat.id)}
                  className={`p-3 rounded-xl border transition-all cursor-pointer flex items-center justify-between gap-3 ${
                    feat.checked
                      ? 'border-pink-200 bg-pink-50/20'
                      : 'border-slate-100 hover:bg-slate-50/80'
                  }`}
                >
                  <div className="flex items-center gap-3 min-w-0">
                    <div className={`w-9 h-9 rounded-xl ${feat.iconBg} ${feat.iconColor} flex items-center justify-center shrink-0`}>
                      <IconComp className="w-4 h-4" />
                    </div>
                    <div className="min-w-0">
                      <span className="text-xs font-extrabold text-slate-900 block leading-tight">
                        {feat.title}
                      </span>
                      <span className="text-[11px] text-slate-400 block truncate">
                        {feat.description}
                      </span>
                    </div>
                  </div>

                  {/* Custom Styled Checkbox */}
                  <div
                    className={`w-5 h-5 rounded-md flex items-center justify-center shrink-0 transition-colors ${
                      feat.checked
                        ? 'bg-[#EC167F] text-white shadow-2xs'
                        : 'border-2 border-slate-300 bg-white'
                    }`}
                  >
                    {feat.checked && <Check className="w-3.5 h-3.5 stroke-[3]" />}
                  </div>
                </div>
              );
            })}
          </div>

          {/* Callout Notice */}
          <div className="p-3 bg-pink-50/50 border border-pink-100 rounded-xl flex items-center gap-2 text-pink-700 text-[11px]">
            <Lightbulb className="w-4 h-4 text-pink-500 shrink-0" />
            <span>Fitur dapat diubah kapan saja setelah paket dibuat.</span>
          </div>

          {/* Dynamic Footer Counter */}
          <div className="pt-2 border-t border-slate-100 flex items-center gap-2 text-xs font-bold text-slate-800">
            <span className="w-4 h-4 rounded-full bg-pink-100 text-[#EC167F] flex items-center justify-center text-[10px]">
              ✓
            </span>
            <span>{selectedFeaturesCount} fitur dipilih</span>
          </div>

        </div>

      </form>

      {/* BOTTOM FIXED / FLOATING ACTION BAR */}
      <div className="bg-white/95 backdrop-blur-md p-4 rounded-2xl border border-slate-200/80 shadow-lg flex items-center justify-end gap-3">
        <button
          type="button"
          onClick={onBack}
          className="px-6 py-2.5 bg-white hover:bg-slate-50 text-slate-700 font-extrabold text-xs rounded-xl border border-slate-200 transition-colors cursor-pointer shadow-2xs"
        >
          Batal
        </button>

        <button
          type="button"
          onClick={handleSubmit}
          className="px-6 py-2.5 bg-[#EC167F] hover:bg-pink-600 text-white font-extrabold text-xs rounded-xl shadow-md transition-all cursor-pointer active:scale-98"
        >
          Simpan Paket
        </button>
      </div>

    </div>
  );
};

Zerion Mini Shell 1.0