import { useCallback, useState } from 'react' import { __ } from '@wordpress/i18n' import { useSelect } from '@wordpress/data' import { store_name } from '../../../store/backend' import { ProFeatuerWrapper } from '../ProFeatuerWrapper/ProFeatuerWrapper' import { EmailNotificationsStepContent } from './EmailNotificationsStepContent' import { AdvancedBookingRulesStepContent } from './AdvancedBookingRulesStepContent' import { PaymentSettingsStepContent } from './PaymentSettingsStepContent' import { SetupChecklistLockedStepContent } from './SetupChecklistLockedStepContent' import { SkipStepButton } from './SkipStepButton' import type { SetupChecklistEmailTemplate, SetupChecklistStep } from './types' import checkIcon from '../../../../public/images/icon-check-nobg.svg' import clipboardIcon from '../../../../public/images/icon-clipboard.svg' import './SetupChecklist.scss' interface SetupChecklistStepItemProps { step: SetupChecklistStep shortcode: string emailTemplates: SetupChecklistEmailTemplate[] isExpanded: boolean isReviewMode?: boolean reviewActiveStepId?: string | null onReviewStepChange?: (stepId: string) => void onSkipStep: (stepId: string) => Promise } const hasRequiredPlan = ( requiredPlans: string[], planMap: Record ): boolean => { if (!requiredPlans.length) { return true } return requiredPlans.some((plan) => planMap[plan] === true) } export const SetupChecklistStepItem = ({ step, shortcode, emailTemplates, isExpanded, isReviewMode = false, reviewActiveStepId = null, onReviewStepChange, onSkipStep, }: SetupChecklistStepItemProps) => { const { plan_map } = useSelect( (select: any) => select(store_name).getPreset(), [] ) as { plan_map?: Record } const [copied, setCopied] = useState(false) const [isSkipping, setIsSkipping] = useState(false) const planMap = plan_map || {} const planAvailable = hasRequiredPlan(step.required_plans, planMap) const isActive = isReviewMode ? step.id === reviewActiveStepId : step.status === 'in_progress' const showDetails = isExpanded && isActive const handleReviewStepSelect = useCallback( (event: React.MouseEvent) => { if (!isReviewMode || !onReviewStepChange) { return } const target = event.target as HTMLElement if (target.closest('a, button')) { return } onReviewStepChange(step.id) }, [isReviewMode, onReviewStepChange, step.id] ) const handleCopy = useCallback(() => { navigator.clipboard.writeText(shortcode).then(() => { setCopied(true) setTimeout(() => setCopied(false), 2000) }) }, [shortcode]) const handleSkip = useCallback(async () => { setIsSkipping(true) try { await onSkipStep(step.id) } finally { setIsSkipping(false) } }, [onSkipStep, step.id]) const statusLabel = step.skipped ? __('Skipped', 'webba-booking-lite') : step.status === 'completed' ? isReviewMode && isActive ? __('Reviewing', 'webba-booking-lite') : __('Completed', 'webba-booking-lite') : step.status === 'in_progress' ? __('In Progress', 'webba-booking-lite') : __('Pending', 'webba-booking-lite') const statusBadgeClass = step.skipped ? 'wbk_setupChecklist__statusBadge--skipped' : `wbk_setupChecklist__statusBadge--${step.status}` return (
{ if (event.key === 'Enter' || event.key === ' ') { event.preventDefault() onReviewStepChange?.(step.id) } } : undefined } role={isReviewMode ? 'button' : undefined} tabIndex={isReviewMode ? 0 : undefined} aria-expanded={isReviewMode ? isActive : undefined} >
{step.status === 'completed' ? ( ) : ( )}

{step.action_url ? ( {step.title} ) : ( step.title )}

{!planAvailable && step.required_plans.length > 0 && ( )} {isExpanded && ( {statusLabel} )}
{isExpanded && (

{step.description}

)} {showDetails && step.id === 'embed_form' && (
{shortcode}
)} {showDetails && step.id === 'email_notifications' && ( )} {showDetails && !planAvailable && step.required_plans.length > 0 && ( )} {showDetails && step.id === 'payment_settings' && planAvailable && ( )} {showDetails && step.id === 'advanced_booking_rules' && ( )} {showDetails && planAvailable && step.id !== 'embed_form' && step.id !== 'email_notifications' && step.id !== 'payment_settings' && step.id !== 'advanced_booking_rules' && ( )}
) }