11<script >
22 import { Card , CardBody } from " @sveltestrap/sveltestrap" ;
3- import { onMount } from " svelte" ;
3+ import { getContext , onMount } from " svelte" ;
44
55 /** @type {boolean} */
66 export let disableOption = false ;
1111 /** @type {(args0: string, args1: string) => any} */
1212 export let onConfirm;
1313
14- /** @type {() => any} */
15- export let refresh = () => {};
16-
1714 /** @type {any[]} */
1815 let cards = [];
16+ /** @type {any[]} */
17+ let buttons = [];
18+
19+ const { autoScrollToBottom } = getContext (' chat-window-context' );
1920
2021 onMount (() => {
2122 reset ();
22- collectOptions (options);
23- refresh && refresh ();
23+ collectOptions (options)
24+ autoScrollToBottom ? . ();
2425 });
2526
2627 /** @param {any[]} options */
2728 function collectOptions (options ) {
28- cards = options? .map (op => {
29+ cards = options? .filter ( op => !! op . title || !! op . subtitle ) ? . map (op => {
2930 // @ts-ignore
30- const options = op .buttons ? .filter (op => !! op .title && !! op .payload )? .map (x => {
31+ const options = op .buttons ? .filter (x => !! x .title && !! x .payload )? .map (x => {
3132 return {
3233 title: x .title ,
33- payload: x .payload
34+ payload: x .payload ,
35+ is_primary: x .is_primary ,
36+ is_secondary: x .is_secondary ,
3437 };
3538 }) || [];
3639
4043 options: options
4144 };
4245 }) || [];
46+
47+ buttons = options? .filter (op => !!! op .title && !!! op .subtitle )? .flatMap (op => {
48+ // @ts-ignore
49+ return op .buttons ? .filter (x => !! x .title && !! x .payload )? .map (x => {
50+ return {
51+ title: x .title ,
52+ payload: x .payload ,
53+ is_primary: x .is_primary ,
54+ is_secondary: x .is_secondary ,
55+ };
56+ }) || [];;
57+ }) || [];
4358 }
4459
4560 /**
6681< / script>
6782
6883{#if cards .length > 0 }
69- < div class = " card-group -container" >
84+ < div class = " complex-option -container" >
7085 {#each cards as card, idx (idx)}
7186 < Card class = " card-element" >
72- < CardBody>
87+ < CardBody class = " card-element-body " >
7388 {#if !! card .title }
74- < div class = " card-element-title mb-3 " > {card .title }< / div>
89+ < div class = " card-element-title hide-text " > {card .title }< / div>
7590 {/ if }
7691 {#if !! card .subtitle }
77- < div class = " card-element-subtitle mb-3 " > {card .subtitle }< / div>
92+ < div class = " card-element-subtitle hide-text " > {card .subtitle }< / div>
7893 {/ if }
7994 {#if card .options ? .length > 0 }
8095 < div class = " card-option-group" >
8196 {#each card .options as option, i (i)}
8297 < button
83- class = " btn btn-outline-primary btn-sm m-1 "
98+ class = { ` btn btn-sm m-1 ${ option . is_secondary ? ' btn-outline-secondary ' : ' btn-outline-primary ' } ` }
8499 disabled= {disableOption}
85100 on: click= {(e ) => handleClickOption (e, option)}
86101 >
94109 {/ each}
95110 < / div>
96111{/ if }
112+
113+ {#if buttons .length > 0 }
114+ < div class = " plain-option-container" style= " margin-top: 5px;" >
115+ {#each buttons as option, index}
116+ < button
117+ class = {` btn btn-sm m-1 ${ option .is_secondary ? ' btn-outline-secondary' : ' btn-outline-primary' } ` }
118+ disabled= {disableOption}
119+ on: click= {(e ) => handleClickOption (e, option)}
120+ >
121+ {option .title }
122+ < / button>
123+ {/ each}
124+ < / div>
125+ {/ if }
0 commit comments