<?php require_once(THEME_ROOT . '/blocks/user_head.php'); ?>
<?php require_once(THEME_ROOT . '/blocks/user_top.php'); ?>

<div id="page-content-wrapper">
    <div class="row">
        <div class="col-lg-8 col-md-9">
            <div class="history_blocks">
                <?php echo flash_show('send_answer_ticker'); ?>

                <?php $list = support_get_appeal_list($login);
                if ($list) {
                    foreach ($list as $item) { ?>
                        <div class="modal fade" id="<?php echo (int)($item['id']); ?>" tabindex="-1" role="dialog"
                             aria-labelledby="myModalLabel">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                <span aria-hidden="true">
                                                    <img src="/theme/demo108/assets/common/Assets/cabinet/x.svg">
                                                </span>
                                        </button>
                                        <h4 class="modal-title"
                                            id="myModalLabel"><?php echo escape($item['subject']); ?></h4>
                                    </div>
                                    <div class="modal-footer" style="text-align: left;">
                                        <?php foreach (support_get_messages_list($item['id']) as $row) { ?>
                                            <div class="chat_block <?php if ($login === $row['login']) {
                                                echo 'from_right';
                                            } else {
                                                echo 'from_left';
                                            } ?>">
                                                <p>
                                                    <?php echo escape($row['text']); ?>
                                                </p>
                                                <span class="date"><?php echo date('M j, Y H:i', $row['date']); ?></span>
                                            </div>
                                        <?php } ?>
                                        <div class="block">
                                            <div class="block-body">
                                                <form method="POST" action="/handlers/user/send_answer_ticker.php">
                                                    <?php echo form_init(); ?>
                                                    <textarea
                                                            name="text"
                                                            class="form-control"
                                                            rows="5"
                                                            style="margin-bottom: 10px;"
                                                            placeholder="<?php echo T('Сообщение ...'); ?>"
                                                            required></textarea>
                                                    <div class="text-right" style="margin-top: 0px;">
                                                        <button type="submit" name="support_add_message"
                                                                class="btn btn-success btn-lg">
                                                            <?php echo T('Отправить'); ?>
                                                        </button>
                                                        <input type="hidden" value="<?php echo (int)$item['id']; ?>"
                                                               name="id">
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php $processed = in_array($item['status'], ['open', 'read', 'processed']); ?>

                        <div class="panel panel-default shadow support_block  wow fadeInUp" style="cursor: pointer">
                            <div class="panel-heading">
                                <h4 class="panel-title <?php if ($processed) {
                                    echo 'wait';
                                } else {
                                    echo 'closed';
                                } ?>">
                                    <a data-toggle="modal" data-target="#<?php echo (int)$item['id']; ?>">
                                        <div class="row">
                                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                     viewbox="0 0 24 24" fill="none" stroke="#000" stroke-width="2"
                                                     stroke-linecap="round" stroke-linejoin="round">
                                                    <circle cx="12" cy="12" r="10"></circle>
                                                    <polyline points="12 6 12 12 15 15"></polyline>
                                                </svg>
                                            </div>
                                            <div class="col-lg-7 col-md-6 col-sm-10 col-xs-10">
                                                <?php echo escape($item['subject']) . ', ' . date('M j, Y H:i', $item['date']); ?>
                                            </div>
                                            <div class="col-lg-3 col-md-4 col-sm-3 text-right hidden-sm hidden-xs">
                                                <div class="amount">
                                                    <?php if ($processed) {
                                                        echo T('Ожидает');
                                                    } else {
                                                        echo T('Отвечен');
                                                    } ?>
                                                </div>
                                            </div>
                                        </div>
                                    </a>
                                </h4>
                            </div>
                        </div>
                    <?php }
                } else { ?>
                    <h4 class="wow fadeIn" data-wow-delay="0.1s"><?php echo T('Записей не обнаружено'); ?></h4>
                <?php } ?>
            </div>
        </div>
        <div class="col-lg-4 col-md-3">
            <div class="cab_block shadow left_ticket wow fadeIn" data-wow-delay="0.1s">
                <h2><?php echo T('Новый тикет'); ?></h2>

                <form method="post" action="/handlers/user/new_ticket.php">
                    <?php echo flash_show('new_ticket'); ?>
                    <?php echo form_init(); ?>
                    <input name="subject" style="margin-bottom: 10px;" type="text"
                           placeholder="<?php echo T('Тема вашего обращения'); ?>" class="form-control" required>
                    <textarea name="text" style="margin-bottom: 10px;" class="form-control" rows="7" cols="5"
                              required></textarea>
                    <button name="support_add_appeal" type="submit" class="btn btn-success btn-lg">
                        <?php echo T('Отправить'); ?>
                    </button>
                </form>

            </div>
        </div>
    </div>
</div>


</div>
<script src="//cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
<script src="/theme/demo108/assets/common/Assets/js/sidebar_menu.js" type="text/javascript"></script>
<script src="/theme/demo108/assets/common/Assets/sound/ion.sound.min.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<script>

    ion.sound({
        sounds: [
            {
                name: "bip-2"
            },
            {
                name: "wuf-3"
            },
            {
                name: "wuf-1"
            },
            {
                name: "wuf-4"
            },
            {
                name: "bip-1"
            },
            {
                name: "welcome_ru"
            },
            {
                name: "withdrawal_ru"
            },
        ],
        path: "/theme/demo108/assets/common/Assets/sound/sounds/",
        preload: true,
        volume: 1.0,
        multiplay: true
    });

    $(document).ready(function () {
        $(".left_ticket").css("width", $(".left_ticket").outerWidth());
        $(".left_ticket").css("position", "fixed");

    });


    $(".sidebar-nav li, .btn").on("mouseenter", function () {
        ion.sound.play("bip-2");
    });

    $(".sidebar-nav li, .btn").on("click", function () {
        ion.sound.play("bip-1");
    });

    $(".form-control").on("click", function () {
        ion.sound.play("wuf-1");
    });
    if ($(".wow").is(':visible')) {
        ion.sound.play("wuf-1");
    }
</script>
</body>
</html>
