|
| 1 | +import type { FC } from "hono/jsx"; |
| 2 | +import { twMerge } from "tailwind-merge"; |
| 3 | +import type { TranslationStatus } from "../../../utils/translationStatus"; |
| 4 | +import { LanguageIcon } from "../../icons"; |
| 5 | + |
| 6 | +type StatusConfig = { |
| 7 | + bgColor: string; |
| 8 | + borderColor: string; |
| 9 | + textColor: string; |
| 10 | + iconColor: string; |
| 11 | + label: string; |
| 12 | + message: string; |
| 13 | +}; |
| 14 | + |
| 15 | +const getStatusConfig = (status: TranslationStatus): StatusConfig => { |
| 16 | + switch (status) { |
| 17 | + case "translated": |
| 18 | + return { |
| 19 | + bgColor: "bg-green-50", |
| 20 | + borderColor: "border-green-200", |
| 21 | + textColor: "text-green-800", |
| 22 | + iconColor: "text-green-600", |
| 23 | + label: "翻訳済み", |
| 24 | + message: "このページは日本語に翻訳済みです。", |
| 25 | + }; |
| 26 | + case "partially_translated": |
| 27 | + return { |
| 28 | + bgColor: "bg-yellow-50", |
| 29 | + borderColor: "border-yellow-200", |
| 30 | + textColor: "text-yellow-800", |
| 31 | + iconColor: "text-yellow-600", |
| 32 | + label: "部分的に翻訳済み", |
| 33 | + message: |
| 34 | + "このページは部分的に翻訳されています。一部原文の内容が含まれています。", |
| 35 | + }; |
| 36 | + case "untranslated": |
| 37 | + return { |
| 38 | + bgColor: "bg-red-50", |
| 39 | + borderColor: "border-red-200", |
| 40 | + textColor: "text-red-800", |
| 41 | + iconColor: "text-red-600", |
| 42 | + label: "未翻訳", |
| 43 | + message: |
| 44 | + "このページはまだ翻訳されていません。原文の内容が表示されています。", |
| 45 | + }; |
| 46 | + } |
| 47 | +}; |
| 48 | + |
| 49 | +export type TranslationStatusAlertProps = { |
| 50 | + status: TranslationStatus; |
| 51 | +}; |
| 52 | + |
| 53 | +export const TranslationStatusAlert: FC<TranslationStatusAlertProps> = ({ |
| 54 | + status, |
| 55 | +}) => { |
| 56 | + const config = getStatusConfig(status); |
| 57 | + return ( |
| 58 | + <div |
| 59 | + class={twMerge( |
| 60 | + "border rounded-md p-4 mb-6", |
| 61 | + config.bgColor, |
| 62 | + config.borderColor, |
| 63 | + config.textColor, |
| 64 | + )} |
| 65 | + > |
| 66 | + <div class="flex items-start"> |
| 67 | + <div class={twMerge("w-5 h-5 mr-3 flex-shrink-0", config.iconColor)}> |
| 68 | + <LanguageIcon /> |
| 69 | + </div> |
| 70 | + <div class="flex-1"> |
| 71 | + <div class="text-sm font-bold mb-1">{config.label}</div> |
| 72 | + <p class="text-sm">{config.message}</p> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + ); |
| 77 | +}; |
0 commit comments