48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import type { LeadSource } from "@montech/shared";
|
|||
|
|
|
||
|
|
const DEFAULT_CONSULT_TYPE = "طلا و جواهر";
|
||
|
|
|
||
|
|
/** Consultation modal state shared by the header, hero, solution cards, banners and the AI modal. */
|
||
|
|
export function useConsultModal() {
|
||
|
|
const isOpen = useState("consult-open", () => false);
|
||
|
|
const mounted = useState("consult-mounted", () => false);
|
||
|
|
const type = useState("consult-type", () => DEFAULT_CONSULT_TYPE);
|
||
|
|
const source = useState<LeadSource>("consult-source", () => "consult");
|
||
|
|
const aiQuery = useState<string>("consult-ai-query", () => "");
|
||
|
|
|
||
|
|
function open(opts: { type?: string; source?: LeadSource; aiQuery?: string } = {}) {
|
||
|
|
if (opts.type) type.value = opts.type;
|
||
|
|
source.value = opts.source ?? "consult";
|
||
|
|
aiQuery.value = opts.aiQuery ?? "";
|
||
|
|
mounted.value = true;
|
||
|
|
isOpen.value = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
function close() {
|
||
|
|
isOpen.value = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
function resetType() {
|
||
|
|
type.value = DEFAULT_CONSULT_TYPE;
|
||
|
|
}
|
||
|
|
|
||
|
|
return { isOpen, mounted, type, source, aiQuery, open, close, resetType };
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useAiModal() {
|
||
|
|
const isOpen = useState("ai-open", () => false);
|
||
|
|
const mounted = useState("ai-mounted", () => false);
|
||
|
|
const query = useState("ai-query", () => "");
|
||
|
|
|
||
|
|
function open() {
|
||
|
|
mounted.value = true;
|
||
|
|
isOpen.value = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
function close() {
|
||
|
|
isOpen.value = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return { isOpen, mounted, query, open, close };
|
||
|
|
}
|