'use client'; import * as React from 'react'; import { Plus, AlertTriangle, Wand2, Minus } from 'lucide-react'; import * as Alert from '@/components/ui/alert'; import * as Avatar from '@/components/ui/avatar'; import * as Badge from '@/components/ui/badge'; import * as Button from '@/components/ui/button'; import * as CompactButton from '@/components/ui/compact-button'; import * as Input from '@/components/ui/input'; import * as Label from '@/components/ui/label'; import * as Select from '@/components/ui/select'; import * as Slider from '@/components/ui/slider'; export function ResponsiveSlider() { const [storageUnits, setStorageUnits] = React.useState(1); const [sliderValue, setSliderValue] = React.useState(0); const [billingPeriod, setBillingPeriod] = React.useState('annually'); const [email, setEmail] = React.useState('james@alignui.com'); const [companyName, setCompanyName] = React.useState('APEX INC'); const prices = { enterprisePlan: 479.88, storageUnit: 287.9, monthlyRate: 39.99, annualUserPrice: 59.0, monthlyUserPrice: 69.0, }; const storageSteps = [ { value: 0, label: '0TB' }, { value: 16, label: '1TB' }, { value: 30, label: '5TB' }, { value: 46, label: '10TB' }, { value: 63, label: '25TB' }, { value: 80, label: '50TB' }, { value: 100, label: '100TB' }, ]; const snapToClosestStep = (val: number) => { let closest = storageSteps[0]?.value ?? 0; let minDiff = Math.abs(val - closest); for (let i = 1; i < storageSteps.length; i++) { const diff = Math.abs(val - (storageSteps[i]?.value ?? 0)); if (diff < minDiff) { minDiff = diff; closest = storageSteps[i]?.value ?? 0; } } return closest; }; const getActiveStep = (currentValue: number) => { const idx = storageSteps.findIndex((step) => step.value === currentValue); return idx >= 0 && idx < storageSteps.length ? idx : 0; }; const calculateStoragePrice = (sliderValue: number) => { const tbIndex = getActiveStep(sliderValue); const tbValue = storageSteps[tbIndex]?.label ?? '0TB'; const tbAmount = parseInt(tbValue.replace('TB', '')) || 0; return tbAmount * prices.monthlyRate; }; const calculateTotalPrice = () => { const storagePrice = calculateStoragePrice(sliderValue); const unitsPrice = prices.storageUnit * storageUnits; const baseUserPrice = billingPeriod === 'annually' ? prices.annualUserPrice : prices.monthlyUserPrice; const basePrice = baseUserPrice * 12; const subtotal = basePrice + unitsPrice + storagePrice; const discount = billingPeriod === 'annually' ? 0.85 : 1; const discountedSubtotal = subtotal * discount; return { subtotal: discountedSubtotal, total: discountedSubtotal * 1.18, storagePrice, unitsPrice, basePrice: basePrice * discount, }; }; const priceDetails = calculateTotalPrice(); return (
Select storage units for your organization
500GB included + 5TB /month