import { Field, Input, Select } from "./Ui"; import { isMoneyField, unitHint } from "../lib/fieldUnits"; type Kind = "text" | "decimal" | "integer" | "date" | "bool"; type Definition = [string, string, Kind?, string?, string?, boolean?]; const digital: Definition[] = [ ["digitalCompetence", "شایستگی دیجیتال"], ["solutionOriginality", "اصالت راهکار دیجیتال"], ["digitalMaturityElement", "المان بلوغ دیجیتال"], ["digitalCapability", "قابلیت دیجیتال"], ["preProjectOperationalCost", "هزینه عملیاتی قبل پروژه", "decimal"], ["energyUnitBefore", "واحد انرژی قبل"], ["energyConsumptionBefore", "مصرف انرژی قبل", "integer"], ["energyUnitAfter", "واحد انرژی بعد"], ["energyConsumptionAfter", "مصرف انرژی بعد", "integer"], ["operationalPlan", "برنامه عملیاتی"], ["desiredStrategy", "استراتژی موردنظر"], ["totalResourcesConsumed", "کل منابع مصرف‌شده", "decimal", undefined, undefined, false], ["resourcesRecovered", "منابع بازیافت یا بازیابی‌شده", "decimal", undefined, undefined, false], ]; const process: Definition[] = [ ["preventedProductionStop", "جلوگیری از توقف تولید", "bool"], [ "productionStopBefore", "توقف/ظرفیت قبل", "integer", "preventedProductionStop", "true", ], [ "productionStopAfter", "توقف/ظرفیت بعد", "integer", "preventedProductionStop", "true", ], ["addedCapacity", "ظرفیت افزوده", "decimal"], ["removedBottleneck", "رفع گلوگاه", "bool"], [ "bottleneckCountBefore", "گلوگاه قبل", "integer", "removedBottleneck", "true", ], ["bottleneckCountAfter", "گلوگاه بعد", "integer"], ["implementationTimeBefore", "زمان اجرای فرایند قبل", "integer"], ["implementationTimeAfter", "زمان اجرای فرایند بعد", "integer"], ["reducedFailure", "کاهش خرابی", "bool"], ["breakdownCountBefore", "خرابی قبل", "integer", "reducedFailure", "true"], ["breakdownCountAfter", "خرابی بعد", "integer", "reducedFailure", "true"], [ "foreignCurrencyCostBefore", "هزینه ارزی قبل", "integer", "removedBottleneck", "true", ], [ "foreignCurrencyCostAfter", "هزینه ارزی بعد", "integer", "removedBottleneck", "true", ], ["annualValueBefore", "ارزش سالانه قبل", "decimal"], ["operatingCostBefore", "هزینه عملیاتی قبل نوآوری", "decimal"], ["operatingCostAfter", "هزینه عملیاتی بعد نوآوری", "decimal"], ]; const product: Definition[] = [ ["productTitle", "عنوان محصول"], ["productExported", "محصول صادر شده", "bool"], ["currentStatus", "وضعیت فعلی"], ["obtainedStandardTitle", "عنوان استاندارد اخذ‌شده"], ["developedTechnologyType", "نوع دانش فنی توسعه"], ["progressStage", "مرحله پیشرفت"], ["productInnovationType", "نوع نوآوری محصول"], ["productReleaseDate", "تاریخ عرضه", "date"], ["exportDate", "تاریخ صادرات", "date", "productExported", "true"], ["knowledgeBasedCertificateObtained", "گواهی دانش‌بنیان اخذ شده", "bool"], [ "certificateNumber", "شماره گواهی", "text", "knowledgeBasedCertificateObtained", "true", ], [ "certificateDate", "تاریخ اخذ گواهی", "date", "knowledgeBasedCertificateObtained", "true", ], [ "issuingAuthority", "مرجع صادرکننده", "text", "knowledgeBasedCertificateObtained", "true", ], ]; const domestic: Definition[] = [ ["technologyConstructionCost", "هزینه ساخت فناوری", "decimal"], ["bottleneckResolved", "رفع گلوگاه", "bool"], [ "bottleneckResolutionCount", "تعداد گلوگاه رفع‌شده", "integer", "bottleneckResolved", "true", ], ["investmentAmount", "مبلغ سرمایه‌گذاری", "decimal"], ["domesticProductUnitPrice", "قیمت واحد محصول داخلی", "decimal"], ["importedProductUnitPrice", "قیمت واحد محصول وارداتی", "decimal"], ["potentialImportBefore", "واردات بالقوه قبل", "decimal"], ["complexityLevel", "سطح پیچیدگی"], ["isHighLevelProductOrTechnology", "محصول/فناوری سطح بالا", "bool"], ["domesticProductionAfter", "تولید داخلی بعد", "decimal"], ["technologyMaturityLevel", "سطح بلوغ فناوری"], ["collaborationModel", "مدل همکاری"], ["projectParticipationCount", "تعداد مشارکت پروژه", "integer"], ["developerTeamRole", "نقش تیم توسعه"], ["companyStaffRole", "نقش کارکنان شرکت"], ["employeesInvolved", "کارکنان درگیر", "integer"], ["participantsFullName", "نام مشارکت‌کنندگان"], ["organizationalPosition", "پست سازمانی"], ["foreignTechnologySampleExists", "وجود نمونه خارجی", "bool"], ["foreignCurrencyCostBefore", "هزینه ارزی قبل", "decimal"], ["foreignCurrencyCostAfter", "هزینه ارزی بعد", "decimal"], ]; const definitions: Record = { 1: digital, 2: process, 3: product, 5: domestic, }; const payloadNames: Record = { 1: "digitalDetails", 2: "processDetails", 3: "productDetails", 5: "domesticDetails", }; export function InnovationDetailsFields({ type, values, setValues, }: { type: number; values: Record; setValues: (x: Record) => void; }) { const fields = definitions[type] ?? []; if (!fields.length) return null; return (
{fields .filter( ([, , , dependency, expected]) => !dependency || values[dependency] === expected, ) .map(([key, label, kind = "text", , , required = true]) => ( {kind === "bool" ? ( ) : ( setValues({ ...values, [key]: e.target.value }) } /> )} ))}
); } export function buildInnovationPayload( type: number, values: Record, ) { const fields = definitions[type]; if (!fields) return {}; const data: Record = {}; for (const [key, , kind = "text", dependency, expected] of fields) { if (dependency && values[dependency] !== expected) { data[key] = null; continue; } const value = values[key] ?? ""; data[key] = kind === "bool" ? value === "true" : kind === "integer" ? Number(value) : value; } return { [payloadNames[type]]: data }; }