<?php
use App\Core\Csrf;
use function App\Core\e;

$communityMaxChars = (int) ($communityMaxChars ?? (($GLOBALS['zalorox_config']['COMMUNITY_POST_MAX_CHARS'] ?? 1000) ?: 1000));
?>
<section class="community-composer" data-community-composer>
    <div class="community-composer-head">
        <div>
            <p class="eyebrow">Topluluk Paylasimi</p>
            <h2>Yeni gonderi</h2>
        </div>
        <div class="community-type-tabs" role="tablist" aria-label="Gonderi turu">
            <button class="is-active" type="button" data-community-type="text">Yazi</button>
            <button type="button" data-community-type="image">Resim</button>
            <button type="button" data-community-type="poll">Anket</button>
        </div>
    </div>

    <form action="/api/community/create" method="post" enctype="multipart/form-data" data-community-form>
        <input type="hidden" name="_csrf" value="<?= e(Csrf::token()) ?>">
        <input type="hidden" name="post_type" value="text" data-community-post-type>

        <div class="community-composer-panel is-active" data-community-panel="text">
            <label>Metin
                <textarea name="content" rows="5" maxlength="<?= $communityMaxChars ?>" placeholder="Takipcilerinle bir guncelleme paylas..."></textarea>
            </label>
            <small><span data-community-char-count>0</span> / <?= $communityMaxChars ?></small>
        </div>

        <div class="community-composer-panel" data-community-panel="image" hidden>
            <label>Metin
                <textarea name="image_content" rows="4" maxlength="<?= $communityMaxChars ?>" placeholder="Gorsele kisa bir not ekle..."></textarea>
            </label>
            <label class="community-dropzone" data-community-dropzone>
                <span>+</span>
                <strong>Gorsel sec veya surukle</strong>
                <small>JPG, PNG, WEBP, GIF</small>
                <input type="file" name="image" accept="image/jpeg,image/png,image/webp,image/gif" data-community-image-input>
            </label>
            <div class="community-image-preview" data-community-image-preview hidden></div>
        </div>

        <div class="community-composer-panel" data-community-panel="poll" hidden>
            <label>Anket sorusu
                <input name="poll_question" maxlength="240" placeholder="Topluluga ne sormak istersin?">
            </label>
            <div class="community-poll-builder" data-community-poll-builder>
                <label>Secenek 1<input name="poll_options[]" maxlength="160" placeholder="Secenek"></label>
                <label>Secenek 2<input name="poll_options[]" maxlength="160" placeholder="Secenek"></label>
            </div>
            <button class="pill" type="button" data-community-add-option>Secenek ekle</button>
            <small>Anket suresi sonraki bolumde ayarlanabilir olacak.</small>
        </div>

        <div class="community-composer-actions">
            <span class="field-error" data-community-form-error></span>
            <button class="pill primary" type="submit">Yayinla</button>
        </div>
    </form>
</section>
