import React, { useEffect, useState } from 'react'; import PageHeader from '../components/ui/PageHeader'; import PriceInput from '../components/ui/PriceInput'; import SearchableSelect from '../components/ui/SearchableSelect'; import { usePermissions } from '../hooks/usePermissions'; import { useCancellationPolicy } from '../hooks/useCancellation'; const MODES = [ { value: 'none', label: 'بدون جریمه' }, { value: 'percent', label: 'درصدی' }, { value: 'fixed', label: 'مبلغ ثابت' }, ]; /** * سیاست لغو محیط. * * پیشفرض «بدون جریمه» است و همینجا هم گفته میشود: فعالکردن جریمه یک تصمیم * کسبوکاری است، نه چیزی که کسی تصادفی روشنش کند. */ export default function CancellationPolicyPage() { const { policy, loading, save } = useCancellationPolicy(); const { can } = usePermissions(); const canManage = can('appointment_settings', 'update'); const [freeWindow, setFreeWindow] = useState(24); const [mode, setMode] = useState<'none' | 'percent' | 'fixed'>('none'); const [value, setValue] = useState(0); const [depositRefundable, setDepositRefundable] = useState(false); const [creditRefundable, setCreditRefundable] = useState(true); const [threshold, setThreshold] = useState(3); useEffect(() => { if (!policy) return; setFreeWindow(policy.free_window_hours); setMode(policy.penalty_mode); setValue(policy.penalty_value); setDepositRefundable(policy.deposit_refundable); setCreditRefundable(policy.credit_refundable); setThreshold(policy.no_show_threshold); }, [policy]); const percentInvalid = mode === 'percent' && (value < 0 || value > 100); return (