#!/bin/bash

modal() {
# usage
    local LANG=C
    if [ "$1" = "help" ]; then
    echo '    start="start"             start modal'
    echo '    title="title"             Title'
    echo '    id="id"                   id'
    echo '    run="file.run"            File to be executed when clicking the button'
    echo '    footerStart="start"       start footer'
    echo '    footerEnd="end"           end footer'
    echo '    end="end"                 end modal'
    echo ''
    fi

#It is only necessary to declare the variables that need changes in the content, the file that calls this script already creates the variable that will be used in the script

# start
if [ -n "$start" ];then
read -d $'' ShowText <<EOF
<!-- Modal -->
<div class="modal fade" id="$id" tabindex="-1" aria-labelledby="${id}Label" aria-hidden="true">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="${id}Label">$title</h1>
        <button onclick="javascript:reload();" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
EOF
echo "$ShowText"
fi

# end
if [ -n "$end" ];then
read -d $'' ShowText <<EOF
      </div>
    </div>
  </div>
</div>
EOF
echo "$ShowText"
fi

# run
if [ -n "$run" ];then
	bash "$run"
fi

# footerStart
if [ -n "$footerStart" ];then
read -d $'' ShowText <<EOF
    <p></p>
	<div class="modal-footer">
EOF
echo "$ShowText"
fi

# footerEnd
if [ -n "$footerEnd" ];then
echo "</div>"
fi

}
