|
| 1 | +import { CompanyLogo } from '../../../components/CompanyLogo'; |
1 | 2 | import React from 'react'; |
2 | 3 | import { RussiaInfoBox } from '../results-list/RussiaInfoBox'; |
3 | | -import { Product, IManufacturer } from 'search'; |
| 4 | +import { Product} from 'search'; |
4 | 5 | import styled from 'styled-components'; |
5 | 6 | import { ScoreBar } from '@Components/ScoreBar'; |
6 | 7 | import { ScoreGauge } from '@Components/ScoreGauge'; |
@@ -98,6 +99,45 @@ const ManufacturerDesc = styled.p` |
98 | 99 | color: ${color.text}; |
99 | 100 | `; |
100 | 101 |
|
| 102 | +// ---- STYLE DLA LOGO MAREK ---- |
| 103 | +const BrandsGrid = styled.div` |
| 104 | + display: grid; |
| 105 | + grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); |
| 106 | + gap: 20px; |
| 107 | + margin-top: 16px; |
| 108 | +`; |
| 109 | + |
| 110 | + |
| 111 | +const BrandTile = styled.div` |
| 112 | + background: #fafafa; |
| 113 | + border-radius: 12px; |
| 114 | + padding: 10px; |
| 115 | + box-shadow: 0 2px 6px rgba(0,0,0,0.07); |
| 116 | + display: flex; |
| 117 | + justify-content: center; |
| 118 | + align-items: center; |
| 119 | + transition: transform .2s ease, box-shadow .2s ease; |
| 120 | +
|
| 121 | + &:hover { |
| 122 | + transform: translateY(-3px); |
| 123 | + box-shadow: 0 4px 10px rgba(0,0,0,0.1); |
| 124 | + } |
| 125 | +`; |
| 126 | + |
| 127 | +const BrandLogo = styled.img` |
| 128 | + max-height: 45px; |
| 129 | + max-width: 100%; |
| 130 | + object-fit: contain; |
| 131 | +`; |
| 132 | + |
| 133 | +// ---- POMOCNICZA FUNKCJA ---- |
| 134 | +const isRealUrl = (url?: string | null) => { |
| 135 | + if (!url) return false; |
| 136 | + const u = url.toLowerCase(); |
| 137 | + return !u.includes("example.pl") && !u.includes("example.com"); |
| 138 | +}; |
| 139 | + |
| 140 | + |
101 | 141 | // ---- KOMPONENTY ---- |
102 | 142 |
|
103 | 143 | const CriterionItem: React.FC<{ condition: boolean; label: string }> = ({ condition, label }) => ( |
@@ -148,95 +188,150 @@ interface IProductDetails { |
148 | 188 |
|
149 | 189 | export const ProductDetails: React.FC<IProductDetails> = ({ product }) => { |
150 | 190 | const manufacturer = product.manufacturer; |
| 191 | + const brandsWithLogo = manufacturer.brands?.filter(b => b.logotype_url) || []; |
151 | 192 | const workersProperty = getPropertiesFromManufacturer(manufacturer, PolishPropertyName.WORKERS); |
152 | 193 | const researchProperty = getPropertiesFromManufacturer(manufacturer, PolishPropertyName.RnD); |
153 | 194 | const registeredProperty = getPropertiesFromManufacturer(manufacturer, PolishPropertyName.REGISTERED); |
154 | 195 | const notGlobalProperty = getPropertiesFromManufacturer(manufacturer, PolishPropertyName.NOT_GLOBAL); |
155 | 196 | const capitalProperty = getPropertiesFromManufacturer(manufacturer, PolishPropertyName.CAPITAL); |
156 | 197 |
|
157 | | - return ( |
158 | | - <DetailsContainer> |
159 | | - <Header> |
160 | | - <h3> |
161 | | - {product.name} |
162 | | - </h3> |
163 | | - </Header> |
164 | | - <RussiaInfoBox product={product} /> |
165 | | - |
166 | | - {/* Ocena + progress bar */} |
167 | | - <ScoreRow> |
168 | | - {product.manufacturer.plScore === 100 && ( |
169 | | - <div style={{ |
170 | | - background: '#ffe5e5', |
171 | | - color: '#c10028', |
172 | | - padding: '10px 0', |
173 | | - textAlign: 'center', |
174 | | - fontWeight: '600', |
175 | | - borderRadius: '8px', |
176 | | - display: 'flex', |
177 | | - justifyContent: 'space-between', |
178 | | - alignItems: 'center', |
179 | | - paddingLeft: '20px', |
180 | | - paddingRight: '20px' |
181 | | - }}> |
182 | | - <span>❤️</span> |
183 | | - <span>Ta firma jest Przyjacielem Poli</span> |
184 | | - <span>❤️</span> |
185 | | - </div> |
186 | | - )} |
187 | | - <ScoreLabel> |
188 | | - <img src={InfoIcon} alt="Info" style={{ width: '14px', marginRight: '4px' }} /> |
189 | | - Nasza ocena: <b>{product.manufacturer.plScore ?? "-"}</b> pkt |
190 | | - </ScoreLabel> |
191 | | - <ScoreBarWrapper> |
192 | | - <ScoreBar |
193 | | - value={product.manufacturer.plScore} |
194 | | - unit="pkt" |
195 | | - missingValuePlaceholder="brak punktacji w rankingu Poli" |
196 | | - animation={{ duration: 1, delay: 0.2 }} |
197 | | - /> |
198 | | - </ScoreBarWrapper> |
199 | | - </ScoreRow> |
200 | | - |
201 | | - {/* Kryteria oceniania */} |
202 | | - <Heading><h2>Kryteria oceniania:</h2></Heading> |
203 | | - <CriteriaRow> |
204 | | - <ScoreGauge |
205 | | - value={capitalProperty.value} |
206 | | - unit="%" |
207 | | - animation={{ duration: 1 }} |
208 | | - missingValuePlaceholder="—" |
209 | | - /> |
210 | | - |
211 | | - <CriteriaList> |
212 | | - <CriterionItem |
213 | | - condition={workersProperty.value === 100} |
214 | | - label="Produkuje w Polsce" |
215 | | - /> |
216 | | - <CriterionItem |
217 | | - condition={researchProperty.value === 100} |
218 | | - label="Prowadzi badania w Polsce" |
219 | | - /> |
220 | | - <CriterionItem |
221 | | - condition={registeredProperty.value === 100} |
222 | | - label="Zarejestrowana w Polsce" |
223 | | - /> |
224 | | - <CriterionItem |
225 | | - condition={notGlobalProperty.value === 100} |
226 | | - label="Nie jest częścią zagranicznego koncernu" |
| 198 | + return ( |
| 199 | + <DetailsContainer> |
| 200 | + <Header> |
| 201 | + <h3> |
| 202 | + {product.name} |
| 203 | + </h3> |
| 204 | + </Header> |
| 205 | + <RussiaInfoBox product={product} /> |
| 206 | + |
| 207 | + {/* Ocena + progress bar */} |
| 208 | + <ScoreRow> |
| 209 | + {product.manufacturer.plScore === 100 && ( |
| 210 | + <div style={{ |
| 211 | + background: '#ffe5e5', |
| 212 | + color: '#c10028', |
| 213 | + padding: '10px 0', |
| 214 | + textAlign: 'center', |
| 215 | + fontWeight: '600', |
| 216 | + borderRadius: '8px', |
| 217 | + display: 'flex', |
| 218 | + justifyContent: 'space-between', |
| 219 | + alignItems: 'center', |
| 220 | + paddingLeft: '20px', |
| 221 | + paddingRight: '20px' |
| 222 | + }}> |
| 223 | + <span>❤️</span> |
| 224 | + <span>Ta firma jest Przyjacielem Poli</span> |
| 225 | + <span>❤️</span> |
| 226 | + </div> |
| 227 | + )} |
| 228 | + <ScoreLabel> |
| 229 | + <img src={InfoIcon} alt="Info" style={{ width: '14px', marginRight: '4px' }} /> |
| 230 | + Nasza ocena: <b>{product.manufacturer.plScore ?? "-"}</b> pkt |
| 231 | + </ScoreLabel> |
| 232 | + <ScoreBarWrapper> |
| 233 | + <ScoreBar |
| 234 | + value={product.manufacturer.plScore} |
| 235 | + unit="pkt" |
| 236 | + missingValuePlaceholder="brak punktacji w rankingu Poli" |
| 237 | + animation={{ duration: 1, delay: 0.2 }} |
| 238 | + /> |
| 239 | + </ScoreBarWrapper> |
| 240 | + </ScoreRow> |
| 241 | + |
| 242 | + {/* Kryteria oceniania */} |
| 243 | + <Heading><h2>Kryteria oceniania:</h2></Heading> |
| 244 | + <CriteriaRow> |
| 245 | + <ScoreGauge |
| 246 | + value={capitalProperty.value} |
| 247 | + unit="%" |
| 248 | + animation={{ duration: 1 }} |
| 249 | + missingValuePlaceholder="—" |
227 | 250 | /> |
228 | | - <br /> |
229 | | - </CriteriaList> |
230 | | - </CriteriaRow> |
| 251 | + |
| 252 | + <CriteriaList> |
| 253 | + <CriterionItem |
| 254 | + condition={workersProperty.value === 100} |
| 255 | + label="Produkuje w Polsce" |
| 256 | + /> |
| 257 | + <CriterionItem |
| 258 | + condition={researchProperty.value === 100} |
| 259 | + label="Prowadzi badania w Polsce" |
| 260 | + /> |
| 261 | + <CriterionItem |
| 262 | + condition={registeredProperty.value === 100} |
| 263 | + label="Zarejestrowana w Polsce" |
| 264 | + /> |
| 265 | + <CriterionItem |
| 266 | + condition={notGlobalProperty.value === 100} |
| 267 | + label="Nie jest częścią zagranicznego koncernu" |
| 268 | + /> |
| 269 | + <br /> |
| 270 | + </CriteriaList> |
| 271 | + </CriteriaRow> |
231 | 272 |
|
232 | | - {/* Notatki o kapitale, producent */} |
233 | | - {AppSettings.SHOW_POLISH_VALUE_NOTES && capitalProperty.notes && ( |
234 | | - <Notes>{capitalProperty.notes}</Notes> |
235 | | - )} |
| 273 | + {/* Notatki o kapitale, producent */} |
| 274 | + {AppSettings.SHOW_POLISH_VALUE_NOTES && capitalProperty.notes && ( |
| 275 | + <Notes>{capitalProperty.notes}</Notes> |
| 276 | + )} |
236 | 277 |
|
237 | | - {product.manufacturer.description && ( |
238 | | - <ManufacturerDesc><ReadMoreArea text={product.manufacturer.description} maxLength={184} /></ManufacturerDesc> |
239 | | - )} |
240 | | - </DetailsContainer> |
241 | | -); |
| 278 | + {product.manufacturer.description && ( |
| 279 | + <ManufacturerDesc><ReadMoreArea text={product.manufacturer.description} maxLength={184} /></ManufacturerDesc> |
| 280 | + )} |
| 281 | + |
| 282 | + {/* Logo producenta */} |
| 283 | + {manufacturer.logotype_url && ( |
| 284 | + isRealUrl(manufacturer.official_url) ? ( |
| 285 | + <a |
| 286 | + href={manufacturer.official_url} |
| 287 | + target="_blank" |
| 288 | + rel="noopener noreferrer" |
| 289 | + style={{ marginTop: "-15px", display: "block" }} |
| 290 | + > |
| 291 | + <CompanyLogo |
| 292 | + logoUrl={manufacturer.logotype_url} |
| 293 | + companyName={manufacturer.name} |
| 294 | + /> |
| 295 | + </a> |
| 296 | + ) : ( |
| 297 | + <div style={{ marginTop: "10px" }}> |
| 298 | + <CompanyLogo |
| 299 | + logoUrl={manufacturer.logotype_url} |
| 300 | + companyName={manufacturer.name} |
| 301 | + /> |
| 302 | + </div> |
| 303 | + ) |
| 304 | + )} |
| 305 | + |
| 306 | + |
| 307 | + {/* Logo marek */} |
| 308 | + {brandsWithLogo.length > 0 && ( |
| 309 | + <div style={{ marginTop: "20px" }}> |
| 310 | + <h4 style={{ marginBottom: "10px", fontWeight: "700", color: "#212121" }}> |
| 311 | + Marki producenta: |
| 312 | + </h4> |
| 313 | + |
| 314 | + <BrandsGrid> |
| 315 | + {brandsWithLogo.map((brand, i) => ( |
| 316 | + <BrandTile key={i}> |
| 317 | + {isRealUrl(brand.website_url) ? ( |
| 318 | + <a |
| 319 | + href={brand.website_url} |
| 320 | + target="_blank" |
| 321 | + rel="noopener noreferrer" |
| 322 | + style={{ display: "flex", justifyContent: "center" }} |
| 323 | + > |
| 324 | + <BrandLogo src={brand.logotype_url} alt={brand.name} /> |
| 325 | + </a> |
| 326 | + ) : ( |
| 327 | + <BrandLogo src={brand.logotype_url} alt={brand.name} /> |
| 328 | + )} |
| 329 | + </BrandTile> |
| 330 | + ))} |
| 331 | + </BrandsGrid> |
| 332 | + </div> |
| 333 | + )} |
| 334 | + |
| 335 | + </DetailsContainer> |
| 336 | + ); |
242 | 337 | }; |
0 commit comments