<commit_before><?php
declare(strict_types=1);

namespace block;

use app;
use arr;
use attr;
use DomainException;
use entity;
use html;
use layout;
use response;
use session;
use str;

function block(array $block): string
{
    return layout\render(layout\block(['type' => 'view'] + $block));
}

function breadcrumb(array $block): string
{
    $url = app\data('request', 'url');

    if ($url === '/' || !($cur = entity\one('menu', crit: [['url', $url]], select: ['path']))) {
        return '';
    }

    $home = entity\one('page', crit: [['url', '/']], select: ['name', 'url']);
    $html = html\element('a', ['href' => $home['url']], $home['name']);
    $all = entity\all('menu', crit: [['id', $cur['path']]], select: ['name', 'url'], order: ['level' => 'asc']);

    foreach ($all as $item) {
        $a = match (true) {
            !$item['url'] => [],
            $item['url'] === $url => ['href' => $item['url'], 'aria-current' => 'page'],
            default => ['href' => $item['url']],
        };
        $html .= ' ' . html\element('a', $a, $item['name']);
    }

    return html\element('nav', ['id' => $block['id'], 'aria-label' => 'breadcrumb'], $html);
}

function container(array $block): string
{
    if (($html = layout\render_children($block['id'])) && $block['tag']) {
        return html\element($block['tag'], $block['cfg']['id'] ? ['id' => $block['id']] : [], $html);
    }

    return $html;
}

function edit(array $block): string
{
    $app = app\data('app');
    $entity = $app['entity'];

    if (!$entity || !$app['action'] || !($attrs = arr\extract($entity['attr'], $block['cfg']['attr_id']))) {
        return '';
    }

    if ($data = app\data('request', 'post')) {
        if ($app['id']) {
            $data = ['id' => $app['id']] + $data;
        }

        if (entity\save($entity['id'], $data)) {
            response\redirect(app\actionurl($entity['id'], $app['action'], $data['id']));
        }
    }

    $args = $app['item'] ? [$app['item'], $data] : [$data];
    $data = arr\replace(entity\item($entity['id']), ...$args);

    return app\tpl(
        $block['tpl'],
        ['attr' => $attrs, 'data' => $data, 'multipart' => !!arr\filter($attrs, 'uploadable', true)]
    );
}

function filter(array $block): string
{
    if (!$block['cfg']['attr'] && !$block['cfg']['searchable']) {
        return '';
    }

    return app\tpl($block['tpl'], [
        'attr' => $block['cfg']['attr'],
        'data' => $block['cfg']['data'],
        'q' => $block['cfg']['q'],
        'searchable' => $block['cfg']['searchable'],
    ]);
}

function html(): string
{
    $app = app\data('app');
    $a = [
        'lang' => APP['lang'],
        'data-area' => $app['area'],
        'data-parent' => $app['parent_id'],
        'data-entity' => $app['entity_id'],
        'data-action' => $app['action'],
        'data-url' => app\data('request', 'url'),
    ];

    return "<!doctype html>\n" . html\element('html', $a, layout\render_id('head') . layout\render_id('body'));
}

function index(array $block): string
{
    $app = app\data('app');
    $entity = $block['cfg']['entity_id'] ? app\cfg('entity', $block['cfg']['entity_id']) : $app['entity'];

    if (!$entity || !($attrs = arr\extract($entity['attr'], $block['cfg']['attr_id']))) {
        return '';
    }

    $crit = $block['cfg']['crit'];<commit_msg>Add data-id to html element if set<commit_after><?php
declare(strict_types=1);

namespace block;

use app;
use arr;
use attr;
use DomainException;
use entity;
use html;
use layout;
use response;
use session;
use str;

function block(array $block): string
{
    return layout\render(layout\block(['type' => 'view'] + $block));
}

function breadcrumb(array $block): string
{
    $url = app\data('request', 'url');

    if ($url === '/' || !($cur = entity\one('menu', crit: [['url', $url]], select: ['path']))) {
        return '';
    }

    $home = entity\one('page', crit: [['url', '/']], select: ['name', 'url']);
    $html = html\element('a', ['href' => $home['url']], $home['name']);
    $all = entity\all('menu', crit: [['id', $cur['path']]], select: ['name', 'url'], order: ['level' => 'asc']);

    foreach ($all as $item) {
        $a = match (true) {
            !$item['url'] => [],
            $item['url'] === $url => ['href' => $item['url'], 'aria-current' => 'page'],
            default => ['href' => $item['url']],
        };
        $html .= ' ' . html\element('a', $a, $item['name']);
    }

    return html\element('nav', ['id' => $block['id'], 'aria-label' => 'breadcrumb'], $html);
}

function container(array $block): string
{
    if (($html = layout\render_children($block['id'])) && $block['tag']) {
        return html\element($block['tag'], $block['cfg']['id'] ? ['id' => $block['id']] : [], $html);
    }

    return $html;
}

function edit(array $block): string
{
    $app = app\data('app');
    $entity = $app['entity'];

    if (!$entity || !$app['action'] || !($attrs = arr\extract($entity['attr'], $block['cfg']['attr_id']))) {
        return '';
    }

    if ($data = app\data('request', 'post')) {
        if ($app['id']) {
            $data = ['id' => $app['id']] + $data;
        }

        if (entity\save($entity['id'], $data)) {
            response\redirect(app\actionurl($entity['id'], $app['action'], $data['id']));
        }
    }

    $args = $app['item'] ? [$app['item'], $data] : [$data];
    $data = arr\replace(entity\item($entity['id']), ...$args);

    return app\tpl(
        $block['tpl'],
        ['attr' => $attrs, 'data' => $data, 'multipart' => !!arr\filter($attrs, 'uploadable', true)]
    );
}

function filter(array $block): string
{
    if (!$block['cfg']['attr'] && !$block['cfg']['searchable']) {
        return '';
    }

    return app\tpl($block['tpl'], [
        'attr' => $block['cfg']['attr'],
        'data' => $block['cfg']['data'],
        'q' => $block['cfg']['q'],
        'searchable' => $block['cfg']['searchable'],
    ]);
}

function html(): string
{
    $app = app\data('app');
    $a = [
        'lang' => APP['lang'],
        'data-area' => $app['area'],
        'data-parent' => $app['parent_id'],
        'data-entity' => $app['entity_id'],
        'data-action' => $app['action'],
        ...($app['id'] ? ['data-id' => $app['id']] : []),
        'data-url' => app\data('request', 'url'),
    ];

    return "<!doctype html>\n" . html\element('html', $a, layout\render_id('head') . layout\render_id('body'));
}

function index(array $block): string
{
    $app = app\data('app');
    $entity = $block['cfg']['entity_id'] ? app\cfg('entity', $block['cfg']['entity_id']) : $app['entity'];

    if (!$entity || !($attrs = arr\extract($entity['attr'], $block['cfg']['attr_id']))) {
        return '';
    }

    $crit = $block['cfg']['crit'];
{'fraction_non_alphanumeric': 0.27333234728590444, 'fraction_numerical': 0.00029581422866439876, 'mean_word_length': 3.115642118076689, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '53320', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2284, 'n_words': 466}