import { useState } from 'react'; import styled, {css} from 'styled-components'; import { declension } from '../../utils/declension'; import type { User } from '../../types/user'; import { PersonModal } from './PersonModal'; interface FamilySectionProps { users: User[]; availableTags: string[]; onChange: (users: User[]) => void; } export function FamilySection({ users, availableTags, onChange, }: FamilySectionProps) { const [editingIndex, setEditingIndex] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); function handleDelete(index: number) { onChange(users.filter((_, userIndex) => userIndex !== index)); } function handleSave(user: User) { if (editingIndex === null) { onChange([...users, user]); } else { onChange(users.map((item, index) => index === editingIndex ? user : item)); } setIsModalOpen(false); setEditingIndex(null); } return ( <> {users.map((user, index) => ( { setEditingIndex(index); setIsModalOpen(true); }} > {user.name} {user.age} {declension(user.age, ['год', 'года', 'лет'])} {user.gender === 'm' ? 'Мужской' : 'Женский'} { event.stopPropagation(); handleDelete(index); }} > ))} { setEditingIndex(null); setIsModalOpen(true); }} > Добавить человека + { setIsModalOpen(false); setEditingIndex(null); }} onSave={handleSave} /> ); } function getAvatarSrc(user: User): string { if (user.age < 16) { return user.gender === 'f' ? '/images/broc-girl.png' : '/images/broc-boy.png'; } return user.gender === 'f' ? '/images/broc-woman.png' : '/images/broc-man.png'; } const FamilyList = styled.div` display: flex; flex-direction: column; gap: 12px; `; const FamilyMember = styled.div` width: 100%; display: flex; align-items: stretch; padding: 12px 20px; border: 1px solid ${({ theme }) => theme.colors.border}; border-radius: 12px; background: #fff; transition: 0.2s; cursor: pointer; text-align: left; height: 100%; &:hover { border-color: #c0c0c0; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02); } &:nth-child(n+1) ${() => Avatar} { background-color: #CEE0FF; } &:nth-child(2n+2) ${() => Avatar} { background-color: #E6F696; } &:nth-child(3n+3) ${() => Avatar} { background-color: #fff488; } &:nth-child(4n+4) ${() => Avatar} { background-color: #ffd623; } `; const Avatar = styled.div` width: 46px; height: 46px; border-radius: 50%; background: #f8f9fa; display: flex; align-items: center; justify-content: center; margin-right: 14px; overflow: hidden; img { max-width: 100%; } `; const Info = styled.div` flex: 1; display: flex; flex-direction: column; justify-content: space-between; `; const Name = styled.div` font-size: 16px; font-weight: 600; color: ${({ theme }) => theme.colors.darkGreen}; ${props => props.theme.media.mobile(css` padding-top: 1.5px; font-size: 14px; `)} `; const Age = styled.div` font-size: 16px; font-weight: 350; color: ${({ theme }) => theme.colors.gray}; * { color: inherit; } ${props => props.theme.media.mobile(css` font-size: 14px; padding-bottom: 4.5px; `)} `; const DeleteButton = styled.button` color: #d1d5db; cursor: pointer; font-size: 18px; transition: 0.2s; background: transparent; border: 0; width: 20px; height: 20px; align-self: center; &:hover { color: #e53935; } `; const AddWrapper = styled.div` width: 100%; display: flex; align-items: center; justify-content: center; `; const AddButton = styled.button` padding: 18px 23px; border-radius: 12px; height: 52px; display: flex; align-items: center; justify-content: center; margin-top: 14px; color: ${({ theme }) => theme.colors.green}; font-size: 14px; font-weight: 500; cursor: pointer; transition: 0.2s; background-color: transparent; border: 0; span { color:inherit; font-weight: inherit; } &:hover { background-color: #F7FBF6; } &:active, &:focus { background-color: #EEF8EB; outline: none; } span { font-size: 20px; margin-left: 8px; font-weight: 300; } `;