import { useState, cloneElement, isValidElement, type ReactNode } from "react";
import { View, Text, Image, Button } from "@tarojs/components";
import Taro from "@tarojs/taro";
import type { RuntimeWorkspace } from "@personal-brand/types";
import type { TemplateProps } from "../../../apps/taro/src/runtime/template";
import { navigate } from "../../../apps/taro/src/runtime/navigation";
import { object, rows, text, presentation, offering } from "../../../apps/taro/src/runtime/content";
import { inquiryPluginState } from "../../../apps/taro/src/runtime/plugins";
import "./style.css";
type Props = { workspace: RuntimeWorkspace };
function InquiryAction({ workspace, label }: Props & { label: string }) {
const state = inquiryPluginState(workspace);
return (
);
}
function Home({ workspace }: Props) {
const p = presentation(workspace, "home");
const config = object(workspace.brand.atelier);
const identity = object(config.identity);
const founderStatus = text(identity.status);
const founderExperience = text(identity.experience);
const b = workspace.brand;
return (
{text(b.avatarUrl) ? (
) : (
{(text(b.founder) || "·").slice(0, 1)}
)}
{text(b.founder) || "待补充主理人"}
{[text(b.title), founderExperience].filter(Boolean).join(" · ")}
{founderStatus && {founderStatus}}
{rows(identity.tags).map((item, index) => (
{item.title}
))}
{p.eyebrow}
{p.title}
{p.subtitle}
{rows(config.badges).map((item, index) => (
✓ {item.title}
))}
{p.featuresTitle}
{p.featuresEnglish}
{rows(config.features).map((item, index) => (
{String(index + 1).padStart(2, "0")}
{item.tag}
{item.title}
{item.description}
))}
{p.casesTitle}
{p.casesSubtitle}
{p.caseAction}
{workspace.offerings.length ? (
workspace.offerings.map((item) => (
navigate("detail", { id: item.id })}
>
{item.coverUrl ? (
) : (
↗
)}
{item.name}
{item.summary}
→
))
) : (
案例内容正在整理中
)}
{p.audienceTitle}
{p.audienceEnglish}
{rows(config.audiences).map((item, index) => (
{item.symbol}
{item.title}
{item.description}
))}
{p.ctaTitle}
{p.ctaSubtitle}
);
}
function Services({ workspace }: Props) {
const p = presentation(workspace, "offerings");
const config = object(workspace.brand.atelier);
return (
{p.eyebrow}
{p.title}
{p.subtitle}
{p.deliverablesTitle}
{p.deliverablesEnglish}
{rows(config.deliverables).map((item, index) => (
{String(index + 1).padStart(2, "0")}
{item.title}
{item.tag}
{item.description}
))}
{p.processTitle}
{p.processEnglish}
{rows(config.process).map((item, index) => (
{index + 1}
{item.title}
{item.description}
))}
{p.proofTitle}
{p.proofEnglish}
{rows(config.proofs).map((item, index) => (
◇
{item.title}
{item.description}
))}
{workspace.trustItems.map((item) => (
{item.title}
{item.summary}
{item.content}
))}
{p.ctaTitle}
{p.ctaSubtitle}
);
}
function Profile({ workspace }: Props) {
const [opened, setOpened] = useState(null);
const b = workspace.brand;
const p = presentation(workspace, "profile");
const config = object(b.atelier);
async function copyWechat() {
try {
await Taro.setClipboardData({ data: text(b.contactWechat) });
} catch {
void Taro.showToast({ title: "复制失败,请重试", icon: "none" });
}
}
return (
{p.eyebrow}
{p.title}
{p.subtitle}
{p.recordsTitle}
{p.recordsDescription}
{p.wechatLabel}
{text(b.contactWechat) || p.contactHint}
✓ {p.promise}
{p.faqTitle}
{p.faqSubtitle}
{rows(config.faqs).map((item, index) => (
{opened === index && (
{item.description}
)}
))}
{p.footerQuote}
{p.footerNote}
);
}
function Detail({ workspace, id }: Props & { id?: string }) {
const found = workspace.offerings.find((item) => item.id === id);
const p = presentation(workspace, "detail");
if (!found)
return (
未找到该案例
);
const item = offering(found);
return (
{item.image && (
)}
{item.name}
{item.desc}
{p.priceLabel}
{item.priceRange}
{p.spaceLabel}
{text(item.presentation.spaceType)}
{[item.category, item.area, item.series].filter(Boolean).map((value, index) => (
{value}
))}
{item.keywords.join(" · ")}
{p.backgroundTitle}
{item.details.background}
{p.conceptTitle}
{item.details.designConcept}
{p.craftsTitle}
{item.details.crafts.map((line, index) => (
{line}
))}
{p.materialsTitle}
{item.details.materialsList.map((row, index) => (
{row.name} {row.spec}
))}
{p.inquiryHint}
);
}
const formTargets: Record = {
inquiry: "atelier.inquiry.intro",
success: "atelier.success.copy",
records: "atelier.records.copy",
};
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
if (page === "home")
return (
);
if (page === "offerings" || page === "service")
return (
);
if (page === "profile")
return (
);
if (page === "detail")
return (
);
const p = presentation(workspace, "inquiry");
const privacy = (
{p.note}
{p.privacyTitle}
{p.privacyNote}
{p.followupHint}
);
const content =
page === "inquiry" &&
isValidElement<{ choiceStyle?: string; beforeSubmit?: ReactNode }>(children)
? cloneElement(children, { choiceStyle: "chips", beforeSubmit: privacy })
: children;
return (
{content}
);
}