"use client";
import { useEffect, useMemo, useState } from "react";
import CategoryMultiSelect from "@/components/CategoryMultiSelect";
import DetailBanner from "@/components/DetailBanner";
import {
categoryLabel,
searchMeshkeeCategories,
type MeshkeeCategory,
} from "@/lib/meshkee-categories";
import { registerShop } from "@/lib/marketplace";
import styles from "./BusinessRegistration.module.css";
const steps = [
{ id: 1, label: "Business information" },
{ id: 2, label: "insert photo" },
{ id: 3, label: "Confirm information" },
] as const;
const businessTypes = [
{
id: "store",
title: "Store",
subtitle: "In publishing and graphic design",
icon: "/images/register/type-store.png",
iconClass: "typeIconStore",
},
{
id: "corporates",
title: "Corporates",
subtitle: "In publishing and graphic design",
icon: "/images/register/type-corporates.png",
iconClass: "typeIconCorporates",
},
{
id: "industrial",
title: "industrial",
subtitle: "In publishing and graphic design",
icon: "/images/register/type-industrial.png",
iconClass: "typeIconIndustrial",
},
] as const;
const sideImages = [
{
src: "/images/register/side-step1.png",
className: "sideImageLaptop",
},
{
src: "/images/register/side-step2.png",
className: "sideImagePainting",
},
{
src: "/images/register/side-step3.png",
className: "sideImageNotebook",
},
] as const;
type FormState = {
businessType: string;
categoryIds: string[];
storeName: string;
telephone: string;
since: string;
gmail: string;
description: string;
country: string;
province: string;
postalCode: string;
address: string;
logoName: string;
bannerName: string;
};
const initialForm: FormState = {
businessType: "corporates",
categoryIds: [],
storeName: "Sani Khani",
telephone: "025 - 3698 52 69",
since: "2018",
gmail: "@Gmail.com",
description: "In publishing and graphic design, Lorem ipsum is a placeholder.",
country: "Iran",
province: "Qom",
postalCode: "03785692",
address: "In publishing and graphic design, Lorem ipsum is a placeholder.",
logoName: "",
bannerName: "",
};
function Field({
label,
value,
onChange,
placeholder,
className,
type = "text",
}: {
label: string;
value: string;
onChange: (value: string) => void;
placeholder?: string;
className?: string;
type?: string;
}) {
return (
);
}
function SelectField({
label,
value,
onChange,
options,
className,
}: {
label: string;
value: string;
onChange: (value: string) => void;
options: string[];
className?: string;
}) {
return (
);
}
function SummaryItem({ label, value }: { label: string; value: string }) {
return (
{label}
{value}
);
}
export default function BusinessRegistration() {
const [step, setStep] = useState(1);
const [form, setForm] = useState(initialForm);
const [categories, setCategories] = useState([]);
const [categoriesLoading, setCategoriesLoading] = useState(true);
const [categoriesError, setCategoriesError] = useState("");
const [ownerPassword, setOwnerPassword] = useState("");
const [submitting, setSubmitting] = useState(false);
const [submitError, setSubmitError] = useState("");
const [submitOk, setSubmitOk] = useState("");
const update = (key: K, value: FormState[K]) => {
setForm((prev) => ({ ...prev, [key]: value }));
};
useEffect(() => {
const controller = new AbortController();
async function loadCategories() {
setCategoriesLoading(true);
setCategoriesError("");
try {
const items = await searchMeshkeeCategories("", controller.signal);
if (controller.signal.aborted) return;
setCategories(items);
} catch (err) {
if (controller.signal.aborted) return;
setCategories([]);
setCategoriesError(
err instanceof Error ? err.message : "Failed to load categories",
);
} finally {
if (!controller.signal.aborted) setCategoriesLoading(false);
}
}
void loadCategories();
return () => controller.abort();
}, []);
const goNext = () => setStep((prev) => Math.min(3, prev + 1));
const goBack = () => setStep((prev) => Math.max(1, prev - 1));
const businessTypeLabel =
businessTypes.find((item) => item.id === form.businessType)?.title ??
form.businessType;
const selectedCategoryLabels = useMemo(() => {
const byId = new Map(categories.map((item) => [item.id, item]));
return form.categoryIds
.map((id) => byId.get(id))
.filter((item): item is MeshkeeCategory => Boolean(item))
.map((item) => categoryLabel(item));
}, [categories, form.categoryIds]);
return (
{step === 1 ? (
Category
Do Select
{businessTypes.map((item) => (
))}
update("categoryIds", ids)}
loading={categoriesLoading}
error={categoriesError}
/>
update("storeName", value)}
/>
update("telephone", value)}
/>
update("since", value)}
/>
update("gmail", value)}
placeholder="@Gmail.com"
/>
update("country", value)}
options={["Iran", "UAE", "Turkey"]}
/>
update("province", value)}
options={["Qom", "Tehran", "Isfahan", "Shiraz"]}
/>
update("postalCode", value)}
/>
) : null}
{step === 2 ? (
) : null}
{step === 3 ? (
Discraption
{form.description}
Confirm your IranBay account password to create your Meshkee
shop (separate from the iranbay.com auth tenant).
{submitError ? (
{submitError}
) : null}
{submitOk ? (
{submitOk}
) : null}
) : null}
{step > 1 ? (
) : (
)}
{step < 3 ? (
) : (
)}
);
}