-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathestimator.ts
More file actions
143 lines (121 loc) · 3.47 KB
/
Copy pathestimator.ts
File metadata and controls
143 lines (121 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { getAdjustedBasePrice } from "@/lib/estimator-deliverables";
export type ProjectType =
| "company_profile"
| "ecommerce"
| "webapp"
| "mobile_app";
export type PlatformType = "android" | "ios" | "both";
export type ProjectScope = "small" | "medium" | "large";
export type ProjectComplexity = "basic" | "standard" | "premium";
export type ProjectTimeline = "relaxed" | "standard" | "rush";
export type DesignApproach = "custom" | "template";
export type TemplateEligibleType = Extract<
ProjectType,
"company_profile" | "ecommerce"
>;
export type CurrencyCode =
| "USD"
| "IDR"
| "MYR"
| "SGD"
| "BND"
| "PHP"
| "THB";
export interface EstimatorState {
type: ProjectType | null;
designApproach: DesignApproach | null;
platform: PlatformType | null;
scope: ProjectScope | null;
complexity: ProjectComplexity | null;
timeline: ProjectTimeline | null;
excludedDeliverableIds: string[];
}
/** USD base anchors — custom design, boutique international positioning */
export const BASE_PRICES: Record<ProjectType, number> = {
company_profile: 1200,
ecommerce: 2800,
webapp: 4800,
mobile_app: 5800,
};
/** Reduced base when using a pre-built template (company profile & e-commerce only) */
export const TEMPLATE_BASE_PRICES: Record<TemplateEligibleType, number> = {
company_profile: 650,
ecommerce: 1600,
};
export const PLATFORM_MULTIPLIERS: Record<PlatformType, number> = {
android: 1.0,
ios: 1.0,
both: 1.6,
};
export const SCOPE_MULTIPLIERS: Record<ProjectScope, number> = {
small: 1.0,
medium: 1.5,
large: 2.2,
};
export const COMPLEXITY_MULTIPLIERS: Record<ProjectComplexity, number> = {
basic: 1.0,
standard: 1.3,
premium: 1.8,
};
export const TIMELINE_MULTIPLIERS: Record<ProjectTimeline, number> = {
relaxed: 0.9,
standard: 1.0,
rush: 1.4,
};
export function supportsTemplateDesign(
type: ProjectType | null,
): type is TemplateEligibleType {
return type === "company_profile" || type === "ecommerce";
}
export function resolveBasePrice(state: EstimatorState): number {
if (!state.type) return 0;
if (
state.designApproach === "template" &&
supportsTemplateDesign(state.type)
) {
return TEMPLATE_BASE_PRICES[state.type];
}
return BASE_PRICES[state.type];
}
export function getLowestBasePrice(type: ProjectType): number {
if (supportsTemplateDesign(type)) {
return TEMPLATE_BASE_PRICES[type];
}
return BASE_PRICES[type];
}
export function formatDesignApproach(
approach: DesignApproach | null | undefined,
): string {
if (!approach) return "—";
return approach === "template" ? "Template Design" : "Custom Design";
}
export function calculateEstimateUsd(state: EstimatorState): number {
if (!state.type || !state.scope || !state.complexity || !state.timeline) {
return 0;
}
if (supportsTemplateDesign(state.type) && !state.designApproach) {
return 0;
}
if (state.type === "mobile_app" && !state.platform) {
return 0;
}
const adjustedBase = getAdjustedBasePrice(state);
const platformMult =
state.type === "mobile_app" && state.platform
? PLATFORM_MULTIPLIERS[state.platform]
: 1.0;
return (
adjustedBase *
platformMult *
SCOPE_MULTIPLIERS[state.scope] *
COMPLEXITY_MULTIPLIERS[state.complexity] *
TIMELINE_MULTIPLIERS[state.timeline]
);
}
export function formatUsdBasePrice(amount: number): string {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0,
}).format(amount);
}