"""
EXAMPLE NOTES — written for the USER, not for the developer.

A port of `features/notes/data/mock.js`, which carries the rule and the reason:
the set it replaced was a stress fixture — an untitled note, a title that would
not fit on one line at any card size, a four-paragraph essay about data
modelling — good for finding a card with no height, wrong as the thing "Fill
with example data" hands a person on their first run.

The rule is **every note must be one somebody would be glad to have written.**
Short, readable, and about their own life rather than about the app's
internals.

It still teaches. Between them the notes use every block type at least once,
and the list is here so a row cannot be deleted without noticing what went
with it:

    several sheets in one note      the side project (Plan / Hours / Questions)
    a table                         the side project, the trip
    a goal diagram, drawn live      the side project
    a link to another page          the group project
    checkboxes inside a note        the side project, the group project
    a pinned note                   the side project
    a cover, and a note with none   the side project has one, the books list not
    a date in the past              the group project — a date is not a deadline
    a date still to come            the trip

Deliberately absent: untitled notes, titles long enough to clamp, and bodies
long enough to test the overflow. Those are still worth checking — paste one in.

TWO DIFFERENCES FROM THE CLIENT'S SET, and both are forced by the same rule
that emptied the Goals sample's `task_ids`.

- **The goal diagram and the page link carry a LABEL and no ids.** The client's
  set points at `g-4` on a page called `goals`, which are ids in its own
  fixture; here they would name rows that do not exist on this account. The
  blocks keep their `label`, which is exactly what `NoteLink` and the diagram
  block fall back to when their target has gone — so the note reads correctly
  and re-pointing it is one click rather than a repair.
- **No note carries a calendar link.** Same reason: a pointer at nothing is
  worse than no pointer.
"""

from datetime import date, timedelta

_counter = 0


def _bid(prefix='b'):
    """
    An id that is unique inside one response.

    Nothing is persisted here, so these only have to be distinct from each
    other — the client uses them as React keys and as the caret's address until
    the set is written back through `bulk`.
    """
    global _counter
    _counter += 1
    return f'{prefix}-{_counter}'


def _text(text):
    return {'id': _bid(), 'type': 'text', 'text': text}


def _head(text, level=2):
    return {'id': _bid(), 'type': 'heading', 'text': text, 'level': level}


def _bullet(text):
    return {'id': _bid(), 'type': 'bullet', 'text': text}


def _numbered(text):
    return {'id': _bid(), 'type': 'numbered', 'text': text}


def _todo(text, done=False):
    return {'id': _bid(), 'type': 'todo', 'text': text, 'done': done}


def _quote(text):
    return {'id': _bid(), 'type': 'quote', 'text': text}


def _divider():
    return {'id': _bid(), 'type': 'divider', 'text': ''}


def _table(rows):
    return {'id': _bid(), 'type': 'table', 'text': '', 'rows': rows}


def _link(target):
    return {'id': _bid(), 'type': 'link', 'text': '', 'target': target, 'kind': 'page'}


def _diagram(source):
    return {'id': _bid(), 'type': 'diagram', 'text': '', 'source': source}


def _sheet(name, blocks):
    return {'id': _bid('sh'), 'name': name, 'blocks': blocks}


def _sample(index, **fields):
    row = {
        'id': f'sample-{index}',
        'title': '',
        'icon': None,
        'cover': None,
        'cover_off': False,
        'tags': [],
        'date': None,
        'pinned': False,
        'sheets': [],
        'calendar_page_id': None,
        'calendar_event_id': None,
        'source': None,
        'is_sample': True,
    }
    row.update(fields)
    return row


def sample_notes(today=None):
    """
    The example set, dated relative to TODAY at request time.

    A fixture with absolute dates rots into a screen of stale rows. One date is
    deliberately in the past — a note's date is not a deadline, and nothing on
    this page goes red for it.
    """
    global _counter
    _counter = 0
    today = today or date.today()
    day = lambda offset: (today + timedelta(days=offset)).isoformat()  # noqa: E731

    return [
        _sample(
            1,
            # THE FULL NOTE — every block type in one document, three sheets,
            # pinned and covered. The one that shows what a note can be without
            # anybody having to read a help page.
            title='Side project — the plan',
            icon={'id': 'lucide:Rocket', 'color': 'violet'},
            cover={'type': 'gradient', 'id': 'moss'},
            tags=['ideas', 'work'],
            date=day(4),
            pinned=True,
            sheets=[
                _sheet(
                    'Plan',
                    [
                        _head('What it is'),
                        _text(
                            'A small app that does one thing well. The point is to '
                            'finish it and show it to people, not to make it perfect.'
                        ),
                        _head('Next steps'),
                        _bullet('Decide what it actually does, in one sentence'),
                        _bullet('Draw the three screens on paper first'),
                        _bullet('Show it to five people before adding anything else'),
                        _divider(),
                        _head('Order of work'),
                        _numbered('The screen you land on'),
                        _numbered('The thing the app is for'),
                        _numbered('Settings, last'),
                        _quote('Finished and small beats perfect and unfinished.'),
                        # A LABEL AND NO IDS — see the module docstring. The
                        # diagram block falls back to the label when it cannot
                        # resolve a goal, so the note reads and re-pointing it
                        # is one click.
                        _diagram({'label': 'Ship the first version of the side project'}),
                    ],
                ),
                _sheet(
                    'Hours',
                    [
                        _head('Time spent'),
                        _table(
                            [
                                ['Week', 'Hours', 'What came out of it'],
                                ['One', '4', 'Idea, and the first sketch'],
                                ['Two', '6', 'The three screens'],
                                ['Three', '5', 'Half of the first one built'],
                            ]
                        ),
                        _text('Kept honestly, including the weeks that were quiet.'),
                    ],
                ),
                _sheet(
                    'Questions',
                    [
                        _todo('Work out whether it needs an account at all', done=True),
                        _todo('Decide on a name'),
                        _todo('Ask two friends what confuses them about it'),
                        _text(
                            'None of these are urgent, and none of them get easier '
                            'by waiting.'
                        ),
                    ],
                ),
            ],
        ),
        _sample(
            2,
            # A SHORT NOTE. Most notes are this size, and the grid has to make
            # one look like a card worth clicking rather than a gap between two
            # others. No cover, so the page shows both.
            title='Books to read next',
            icon={'id': 'lucide:BookOpen', 'color': 'amber'},
            tags=['personal'],
            sheets=[
                _sheet(
                    'Sheet 1',
                    [
                        _bullet('Ursula K. Le Guin — anything'),
                        _bullet('Chiang, Exhalation'),
                        _bullet('Whatever Mina recommended at the weekend'),
                    ],
                )
            ],
        ),
        _sample(
            3,
            # DATED IN THE PAST, which is the case that shows a note's date is
            # not a deadline. Nothing here goes red.
            title='Group project — what we agreed',
            icon={'id': 'lucide:Users', 'color': 'blue'},
            tags=['meetings', 'work'],
            date=day(-3),
            sheets=[
                _sheet(
                    'Sheet 1',
                    [
                        _head('Agreed', 3),
                        _bullet('Three sections, one each'),
                        _bullet('Everything in the shared folder, not over messages'),
                        _bullet('Meet again on the Thursday before it is due'),
                        _head('Mine to do', 3),
                        _todo('Write the introduction', done=True),
                        _todo('Find two more sources'),
                        _link({'kind': 'page', 'label': 'Private / Calendar'}),
                    ],
                )
            ],
        ),
        _sample(
            4,
            # MOSTLY A TABLE, and dated in the FUTURE — so the date filter has
            # something in every window, and the wide editor has a reason to
            # exist.
            title='Trip — what to book, and when',
            icon={'id': 'lucide:Plane', 'color': 'sky'},
            cover={'type': 'gradient', 'id': 'tide'},
            tags=['personal'],
            date=day(26),
            sheets=[
                _sheet(
                    'Sheet 1',
                    [
                        _table(
                            [
                                ['What', 'By when', 'Booked'],
                                ['Train tickets', 'Six weeks out', 'Yes'],
                                ['Somewhere to stay', 'Four weeks out', 'No'],
                                ['Anything that needs a timed ticket', 'The week before', 'No'],
                            ]
                        ),
                        _text(
                            'The train tickets are the only ones that get more '
                            'expensive by waiting.'
                        ),
                        _divider(),
                        _text('Check the passport before booking anything else.'),
                    ],
                )
            ],
        ),
        _sample(
            5,
            # A NOTE THAT IS ONE IDEA. This is what most people's notes page
            # fills up with, and it is worth showing that a note does not have
            # to be a document.
            title='Study in the morning, not at night',
            icon={'id': 'lucide:Lightbulb', 'color': 'yellow'},
            tags=['ideas'],
            sheets=[
                _sheet(
                    'Sheet 1',
                    [
                        _text(
                            'Two hours before ten in the morning are worth about four '
                            'after nine at night. Worth rearranging the week around, '
                            'rather than trying harder in the evening.'
                        )
                    ],
                )
            ],
        ),
    ]
