173 lines
5.2 KiB
TypeScript
173 lines
5.2 KiB
TypeScript
'use client';
|
|
|
|
import React, { type ReactNode } from 'react';
|
|
import { ArrowUpRight, ArrowDownRight, ChevronDown } from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
export const CARD =
|
|
'bg-card crm-radius-section border border-border shadow-[0_1px_3px_rgba(16,24,40,0.06)] min-w-0';
|
|
|
|
export const PIPELINE = [
|
|
{ key: 'pending', label: 'Pending', color: '#5BA4C7' },
|
|
{ key: 'processing', label: 'Processing', color: '#3B82F6' },
|
|
{ key: 'shipped', label: 'Shipped', color: '#7C3AED' },
|
|
{ key: 'delivered', label: 'Delivered', color: '#01B574' },
|
|
] as const;
|
|
|
|
export const OVERVIEW = [
|
|
{ key: 'delivered', label: 'Successful orders', color: '#01B574' },
|
|
{ key: 'pending', label: 'Pending orders', color: '#5BA4C7' },
|
|
{ key: 'cancelled', label: 'Cancelled', color: '#7C3AED' },
|
|
{ key: 'shipped', label: 'In transit', color: '#3B82F6' },
|
|
] as const;
|
|
|
|
export const DONUT_COLORS: Record<string, string> = {
|
|
delivered: '#01B574',
|
|
shipped: '#3B82F6',
|
|
processing: '#5BA4C7',
|
|
pending: '#7C3AED',
|
|
};
|
|
|
|
export const PAYMENT_TAG: Record<string, string> = {
|
|
paid: 'border-[#01B574] text-[#01B574] bg-[#01B574]/8',
|
|
unpaid: 'border-[#5BA4C7] text-[#5BA4C7] bg-[#5BA4C7]/10',
|
|
refunded: 'border-primary text-primary bg-primary/8',
|
|
};
|
|
|
|
export const PRODUCT_TONES = ['#5BA4C7', '#3B82F6', '#01B574', '#1B2559', '#7C3AED'];
|
|
|
|
export function formatCompact(val: number) {
|
|
if (val >= 1_000_000) return `₹${(val / 1_000_000).toFixed(2)}M`;
|
|
if (val >= 1_000) return `₹${(val / 1_000).toFixed(val >= 10_000 ? 0 : 1)}K`;
|
|
return `₹${val.toFixed(0)}`;
|
|
}
|
|
|
|
export function formatInr(val: number) {
|
|
return new Intl.NumberFormat('en-IN', {
|
|
style: 'currency',
|
|
currency: 'INR',
|
|
maximumFractionDigits: 0,
|
|
}).format(val);
|
|
}
|
|
|
|
export function initials(name: string) {
|
|
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
return ((parts[0]?.[0] ?? '') + (parts[1]?.[0] ?? '')).toUpperCase() || '•';
|
|
}
|
|
|
|
export function samplePoints<T>(items: T[], count: number) {
|
|
if (items.length <= count) return items;
|
|
const step = (items.length - 1) / (count - 1);
|
|
return Array.from({ length: count }, (_, i) => items[Math.round(i * step)]);
|
|
}
|
|
|
|
export function deltaFromWeek(week: number, month: number) {
|
|
if (!month) return 2.5;
|
|
const actual = week / month;
|
|
const expected = 7 / 30;
|
|
return ((actual - expected) / expected) * 100;
|
|
}
|
|
|
|
export function CardTitle({ children }: { children: ReactNode }) {
|
|
return (
|
|
<h3 className="flex items-center gap-2 text-[15px] font-bold text-foreground min-w-0">
|
|
<span className="w-[3px] h-4 rounded-full bg-warning shrink-0" />
|
|
<span className="truncate">{children}</span>
|
|
</h3>
|
|
);
|
|
}
|
|
|
|
export function PeriodPills({
|
|
value,
|
|
onChange,
|
|
}: {
|
|
value: 'weekly' | 'monthly' | 'yearly';
|
|
onChange: (next: 'weekly' | 'monthly' | 'yearly') => void;
|
|
}) {
|
|
return (
|
|
<div className="inline-flex items-center gap-1 shrink-0">
|
|
{(['weekly', 'monthly', 'yearly'] as const).map((mode) => (
|
|
<button
|
|
key={mode}
|
|
type="button"
|
|
onClick={() => onChange(mode)}
|
|
className={cn(
|
|
'h-7 px-3 crm-radius-control text-[12px] font-medium capitalize cursor-pointer transition-colors',
|
|
value === mode
|
|
? 'bg-primary text-white'
|
|
: 'bg-card text-muted-foreground hover:bg-muted'
|
|
)}
|
|
>
|
|
{mode}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function GhostSelect({ label }: { label: string }) {
|
|
return (
|
|
<span className="inline-flex items-center gap-1 h-7 px-2.5 crm-radius-control border border-border text-[12px] text-muted-foreground shrink-0">
|
|
{label}
|
|
<ChevronDown className="w-3.5 h-3.5" />
|
|
</span>
|
|
);
|
|
}
|
|
|
|
export function DeltaPill({ value }: { value: number }) {
|
|
const up = value >= 0;
|
|
return (
|
|
<span
|
|
className={cn(
|
|
'inline-flex items-center gap-0.5 h-[22px] px-1.5 crm-radius-badge text-[11px] font-semibold',
|
|
up ? 'bg-success/10 text-success' : 'bg-primary/10 text-primary'
|
|
)}
|
|
>
|
|
{up ? <ArrowUpRight className="w-3 h-3" /> : <ArrowDownRight className="w-3 h-3" />}
|
|
{up ? '+' : ''}
|
|
{Math.abs(value).toFixed(1)}%
|
|
</span>
|
|
);
|
|
}
|
|
|
|
export function StatusDonut({
|
|
slices,
|
|
}: {
|
|
slices: Array<{ label: string; value: number; color: string }>;
|
|
}) {
|
|
const total = slices.reduce((sum, slice) => sum + slice.value, 0) || 1;
|
|
const cx = 90;
|
|
const cy = 90;
|
|
const r = 58;
|
|
const stroke = 26;
|
|
const circ = 2 * Math.PI * r;
|
|
let offset = 0;
|
|
|
|
return (
|
|
<svg viewBox="0 0 180 180" className="w-[168px] h-[168px]">
|
|
<circle cx={cx} cy={cy} r={r} fill="none" stroke="var(--muted)" strokeWidth={stroke} />
|
|
{slices.map((slice) => {
|
|
const pct = slice.value / total;
|
|
const dash = Math.max(pct * circ, 0);
|
|
const gap = Math.max(circ - dash, 0);
|
|
const currentOffset = offset;
|
|
offset += dash;
|
|
return (
|
|
<circle
|
|
key={slice.label}
|
|
cx={cx}
|
|
cy={cy}
|
|
r={r}
|
|
fill="none"
|
|
stroke={slice.color}
|
|
strokeWidth={stroke}
|
|
strokeDasharray={`${dash} ${gap}`}
|
|
strokeDashoffset={-currentOffset}
|
|
transform={`rotate(-90 ${cx} ${cy})`}
|
|
strokeLinecap="butt"
|
|
/>
|
|
);
|
|
})}
|
|
</svg>
|
|
);
|
|
}
|