import React, { useState, createContext, useContext } from 'react';
import { View, Text, Pressable, TextInput } from 'react-native';
import { ThemeProvider, useT, T, Screen, Scroll, Header, NavBar, Card, Group, Row, Button, Segmented, Chip, Pill, Checkbox, Stat, Ring, Bars, Progress, TabBar, Tabs, Stack, Sheet, Icon, Spacer, SectionTitle, alpha } from './ui/kit';
const ACCENT = '#6366F1';
const THEME = { dark: { bg: '#09090F', card: '#13131C', card2: '#1C1C28', line: '#21212E', text2: '#9A9AB3', text3: '#5E5E78' }, light: { bg: '#F2F2F9', card: '#FFFFFF', card2: '#E4E4F1' } };
const PRI = { high: '#FF5C5C', med: '#FFB020', low: '#5CCB6A' };
const LISTS = [{ id: 'work', name: 'Work', icon: 'Briefcase', c: '#6366F1' }, { id: 'home', name: 'Home', icon: 'House', c: '#F59E42' }, { id: 'health', name: 'Health', icon: 'HeartPulse', c: '#22C55E' }, { id: 'ideas', name: 'Ideas', icon: 'Lightbulb', c: '#FBBF24' }];
const INIT = [
{ id: 1, title: 'Ship the landing page', list: 'work', pri: 'high', due: 'Today', done: false, sub: 3, subDone: 2, notes: 'Final copy from Lena, then deploy to staging and run the Lighthouse check.' },
{ id: 2, title: 'Review pull requests', list: 'work', pri: 'med', due: 'Today', done: false, sub: 4, subDone: 1, notes: 'Four open: auth refactor, i18n, the sidebar fix, the flaky test.' },
{ id: 3, title: 'Reply to Dana', list: 'work', pri: 'low', due: 'Today', done: true, sub: 0, subDone: 0, notes: '' },
{ id: 4, title: 'Book dentist', list: 'health', pri: 'med', due: 'Tomorrow', done: false, sub: 0, subDone: 0, notes: 'Dr Alves, ask for a morning slot.' },
{ id: 5, title: 'Plan Q3 roadmap', list: 'work', pri: 'high', due: 'Thu', due2: 1, done: false, sub: 5, subDone: 0, notes: 'Themes first, then the three bets, then what we stop doing.' },
{ id: 6, title: 'Fix the kitchen tap', list: 'home', pri: 'low', due: 'Weekend', done: false, sub: 0, subDone: 0, notes: '' },
{ id: 7, title: 'Run 10k', list: 'health', pri: 'med', due: 'Sun', done: false, sub: 0, subDone: 0, notes: '' },
];
const Store = createContext(null);
function TaskRow({ x, onToggle, onOpen }) {
const t = useT();
const l = LISTS.find((z) => z.id === x.list);
return (
} title={x.title} titleStyle={x.done ? { color: t.text3, textDecorationLine: 'line-through' } : null} subtitle={l.name + (x.sub ? ' · ' + x.subDone + '/' + x.sub + ' subtasks' : '') + ' · ' + x.due} right={} onPress={onOpen} />
);
}
function TodayScreen({ nav }) {
const t = useT();
const { tasks, toggle, setAdd } = useContext(Store);
const today = tasks.filter((x) => x.due === 'Today');
const later = tasks.filter((x) => x.due !== 'Today');
const n = today.filter((x) => x.done).length;
return (
{n}/{today.length}} />
{today.map((x) => toggle(x.id)} onOpen={() => nav.push('task', { id: x.id })} />)}
{later.map((x) => toggle(x.id)} onOpen={() => nav.push('task', { id: x.id })} />)}
);
}
function ListsScreen({ nav }) {
const t = useT();
const { tasks } = useContext(Store);
const [active, setActive] = useState(null);
const list = active ? tasks.filter((x) => x.list === active) : [];
return (
} />
{LISTS.map((l) => {
const n = tasks.filter((x) => x.list === l.id && !x.done).length;
return (
setActive(active === l.id ? null : l.id)}>
{n}
{l.name}
{n === 1 ? '1 open task' : n + ' open tasks'}
);
})}
{active ? l.id === active).name} /> : null}
{active ? {list.map((x) => {}} onOpen={() => nav.push('task', { id: x.id })} />)} : null}
);
}
function ReviewScreen() {
const t = useT();
const { tasks } = useContext(Store);
const done = tasks.filter((x) => x.done).length;
return (
{LISTS.map((l) => {
const all = tasks.filter((x) => x.list === l.id).length || 1;
const d = tasks.filter((x) => x.list === l.id && x.done).length;
return (
{l.name}{d}/{all}
);
})}
);
}
function TaskDetail({ nav, params }) {
const t = useT();
const { tasks, toggle, setPri } = useContext(Store);
const x = tasks.find((z) => z.id === params.id) || tasks[0];
const l = LISTS.find((z) => z.id === x.list);
const [subs, setSubs] = useState([true, true, false].slice(0, Math.max(x.sub, 0)));
return (
} />
toggle(x.id)} />
{x.title}
{['high', 'med', 'low'].map((p) => setPri(x.id, p)} />)}
{}} />
{}} />
{}} />
{x.notes ? : null}
{x.notes ? {x.notes} : null}
{x.sub ? : null}
{x.sub ? (
{Array.from({ length: x.sub }).map((_, i) => setSubs((s) => { const c = s.slice(); c[i] = !c[i]; return c; })} />} title={['Write copy', 'Deploy to staging', 'Lighthouse check', 'Ask for review', 'Announce'][i]} titleStyle={subs[i] ? { color: t.text3, textDecorationLine: 'line-through' } : null} />)}
) : null}
);
}
function AddSheet() {
const t = useT();
const { add, addOpen, setAdd } = useContext(Store);
const [title, setTitle] = useState('');
const [list, setList] = useState('work');
const [pri, setPri] = useState('med');
return (
setAdd(false)} title="New task" height={400}>
LIST
{LISTS.map((l) => setList(l.id)} />)}
PRIORITY
);
}
function Root({ nav }) {
const [tab, setTab] = useState('today');
return (
, lists: , review: }} />
);
}
const SCREENS = { root: Root, task: TaskDetail };
export default function App() {
const [tasks, setTasks] = useState(INIT);
const [addOpen, setAdd] = useState(false);
const toggle = (id) => setTasks((xs) => xs.map((x) => (x.id === id ? Object.assign({}, x, { done: !x.done }) : x)));
const setPri = (id, pri) => setTasks((xs) => xs.map((x) => (x.id === id ? Object.assign({}, x, { pri }) : x)));
const add = (title, list, pri) => setTasks((xs) => [{ id: Date.now(), title, list, pri, due: 'Today', done: false, sub: 0, subDone: 0, notes: '' }, ...xs]);
return (
);
}