- @pagetitle = 'Image template'

.card
  .card-body
    %h3.mb-4 Choose a base template

    .mb-3
      - first_template = nil
      - @projects.each do |project|
        - remote = Project.remote_project?(project.name)
        .row
          .col-12.fw-bold
            = link_to_if(!remote, title_or_name(project), project_show_path(project))
          .col-12
            .row
              - project.packages.each_with_index do |template, index|
                .col-12.col-md-6.col-lg-4.my-4
                  .image-template-box{ class: "#{'active' if first_template.nil?}" }
                    .form-check
                      %input{ name: 'image', type: 'radio', class: 'image_template form-check-input', id: "#{project}-#{index}",
                              checked: check_first(first_template), data: { project: project, package: template } }
                      %label.form-check-label{ for: "#{project}-#{index}" }
                        - first_template ||= template
                        .d-flex
                          = image_template_icon(template)
                          .ps-3
                            = link_to_if(!remote, title_or_name(template), package_show_path(project: project, package: template))
                            %small.description.text-muted.d-block= template.description
          - if project.packages.empty?
            %p
              There are currently no base image templates available for project
              = succeed '.' do
                %strong= title_or_name(project)
    - if first_template
      %hr
      = form_tag(packages_branches_path, id: 'appliance_form') do
        .mb-3
          = hidden_field_tag 'linked_project', first_template.project
          = hidden_field_tag 'linked_package', first_template.name
          = hidden_field_tag 'add_repositories_rebuild', 'copy'
          = hidden_field_tag 'current_revision', true
          = label_tag(:target_package, 'Name your appliance')
          = render partial: 'webui/shared/required_label_mark'
          = text_field_tag(:target_package, first_template, class: 'form-control', required: true)
          %small.text-muted (Maximum of 200 characters, no blank, /, :, - or ; characters)
        = submit_tag('Create appliance', class: 'btn btn-sm btn-primary px-4', disabled: User.session ? nil : true,
                                         data: { disable_with: 'Creating appliance...' })
    - elsif @projects.empty?
      %p There are no templates yet, sorry.

- content_for :ready_function do
  setupImageTemplates();
